Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into idle-state-handler
Browse files Browse the repository at this point in the history
beiwei30 authored Jan 25, 2019
2 parents 49047b5 + e3aac2d commit f62a870
Showing 24 changed files with 157 additions and 144 deletions.
Original file line number Diff line number Diff line change
@@ -98,6 +98,7 @@ static Optional<List<Configurator>> toConfigurators(List<URL> urls) {
* 1. the url with a specific host ip should have higher priority than 0.0.0.0
* 2. if two url has the same host, compare by priority value;
*/
@Override
default int compareTo(Configurator o) {
if (o == null) {
return -1;
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ public void setForce(boolean force) {
this.force = force;
}

@Override
public int getPriority() {
return priority;
}
Original file line number Diff line number Diff line change
@@ -109,18 +109,18 @@ public void destroy() {
* @param invokers invoker candidates
* @param selected exclude selected invokers or not
* @return the invoker which will final to do invoke.
* @throws RpcException
* @throws RpcException exception
*/
protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation,
List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {

if (CollectionUtils.isEmpty(invokers)) {
return null;
}
String methodName = invocation == null ? StringUtils.EMPTY : invocation.getMethodName();

boolean sticky = invokers.get(0).getUrl()
.getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY);
.getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY);

//ignore overloaded method
if (stickyInvoker != null && !invokers.contains(stickyInvoker)) {
@@ -142,7 +142,7 @@ protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation,
}

private Invoker<T> doSelect(LoadBalance loadbalance, Invocation invocation,
List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {

if (CollectionUtils.isEmpty(invokers)) {
return null;
@@ -180,19 +180,20 @@ private Invoker<T> doSelect(LoadBalance loadbalance, Invocation invocation,
* Reselect, use invokers not in `selected` first, if all invokers are in `selected`,
* just pick an available one using loadbalance policy.
*
* @param loadbalance
* @param invocation
* @param invokers
* @param selected
* @return
* @throws RpcException
* @param loadbalance load balance policy
* @param invocation invocation
* @param invokers invoker candidates
* @param selected exclude selected invokers or not
* @param availablecheck check invoker available if true
* @return the reselect result to do invoke
* @throws RpcException exception
*/
private Invoker<T> reselect(LoadBalance loadbalance, Invocation invocation,
List<Invoker<T>> invokers, List<Invoker<T>> selected, boolean availablecheck) throws RpcException {
List<Invoker<T>> invokers, List<Invoker<T>> selected, boolean availablecheck) throws RpcException {

//Allocating one in advance, this list is certain to be used.
List<Invoker<T>> reselectInvokers = new ArrayList<>(
invokers.size() > 1 ? (invokers.size() - 1) : invokers.size());
invokers.size() > 1 ? (invokers.size() - 1) : invokers.size());

// First, try picking a invoker not in `selected`.
for (Invoker<T> invoker : invokers) {
@@ -242,7 +243,6 @@ public Result invoke(final Invocation invocation) throws RpcException {
}

protected void checkWhetherDestroyed() {

if (destroyed.get()) {
throw new RpcException("Rpc cluster invoker for " + getInterface() + " on consumer " + NetUtils.getLocalHost()
+ " use dubbo version " + Version.getVersion()
Original file line number Diff line number Diff line change
@@ -39,12 +39,7 @@
*/

public abstract class Proxy {
public static final InvocationHandler RETURN_NULL_INVOKER = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) {
return null;
}
};
public static final InvocationHandler RETURN_NULL_INVOKER = (proxy, method, args) -> null;
public static final InvocationHandler THROW_UNSUPPORTED_INVOKER = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) {
@@ -108,11 +103,7 @@ public static Proxy getProxy(ClassLoader cl, Class<?>... ics) {
// get cache by class loader.
Map<String, Object> cache;
synchronized (ProxyCacheMap) {
cache = ProxyCacheMap.get(cl);
if (cache == null) {
cache = new HashMap<String, Object>();
ProxyCacheMap.put(cl, cache);
}
cache = ProxyCacheMap.computeIfAbsent(cl, k -> new HashMap<>());
}

Proxy proxy = null;
@@ -145,8 +136,8 @@ public static Proxy getProxy(ClassLoader cl, Class<?>... ics) {
try {
ccp = ClassGenerator.newInstance(cl);

Set<String> worked = new HashSet<String>();
List<Method> methods = new ArrayList<Method>();
Set<String> worked = new HashSet<>();
List<Method> methods = new ArrayList<>();

for (int i = 0; i < ics.length; i++) {
if (!Modifier.isPublic(ics[i].getModifiers())) {
@@ -176,7 +167,7 @@ public static Proxy getProxy(ClassLoader cl, Class<?>... ics) {
for (int j = 0; j < pts.length; j++) {
code.append(" args[").append(j).append("] = ($w)$").append(j + 1).append(";");
}
code.append(" Object ret = handler.invoke(this, methods[" + ix + "], args);");
code.append(" Object ret = handler.invoke(this, methods[").append(ix).append("], args);");
if (!Void.TYPE.equals(rt)) {
code.append(" return ").append(asArgument(rt, "ret")).append(";");
}
Original file line number Diff line number Diff line change
@@ -22,14 +22,16 @@
@Deprecated
public interface Protocol extends org.apache.dubbo.rpc.Protocol {

<T> Exporter<T> export(Invoker <T> invoker) throws RpcException;
<T> Exporter<T> export(Invoker<T> invoker) throws RpcException;

<T> Invoker<T> refer(Class<T> aClass, URL url) throws RpcException;

@Override
default <T> org.apache.dubbo.rpc.Exporter<T> export(org.apache.dubbo.rpc.Invoker<T> invoker) throws RpcException {
return this.export(new Invoker.CompatibleInvoker<>(invoker));
}

@Override
default <T> org.apache.dubbo.rpc.Invoker<T> refer(Class<T> aClass, org.apache.dubbo.common.URL url) throws RpcException {
return this.refer(aClass, new URL(url));
}
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
package org.apache.dubbo.config.spring.beans.factory.annotation;

import com.alibaba.dubbo.config.annotation.Reference;

import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.config.ConsumerConfig;
import org.apache.dubbo.config.spring.ReferenceBean;
@@ -104,7 +103,7 @@ protected void preConfigureBean(Reference reference, ReferenceBean referenceBean
dataBinder.registerCustomEditor(String.class, "filter", new StringTrimmerEditor(true));
dataBinder.registerCustomEditor(String.class, "listener", new StringTrimmerEditor(true));
dataBinder.registerCustomEditor(Map.class, "parameters", new PropertyEditorSupport() {

@Override
public void setAsText(String text) throws java.lang.IllegalArgumentException {
// Trim all whitespace
String content = StringUtils.trimAllWhitespace(text);
@@ -161,7 +160,7 @@ protected void postConfigureBean(Reference annotation, ReferenceBean bean) throw
}

public static CompatibleReferenceBeanBuilder create(Reference annotation, ClassLoader classLoader,
ApplicationContext applicationContext) {
ApplicationContext applicationContext) {
return new CompatibleReferenceBeanBuilder(annotation, classLoader, applicationContext);
}

Original file line number Diff line number Diff line change
@@ -498,10 +498,6 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> r
map.put(Constants.TOKEN_KEY, token);
}
}
if (Constants.LOCAL_PROTOCOL.equals(protocolConfig.getName())) {
protocolConfig.setRegister(false);
map.put("notify", "false");
}
// export service
String contextPath = protocolConfig.getContextpath();
if (StringUtils.isEmpty(contextPath) && provider != null) {
Original file line number Diff line number Diff line change
@@ -113,6 +113,7 @@ public final Class<A> getAnnotationType() {
return annotationType;
}

@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory,
"AnnotationInjectedBeanPostProcessor requires a ConfigurableListableBeanFactory");
@@ -293,6 +294,7 @@ public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}

@Override
public void setEnvironment(Environment environment) {
this.environment = environment;
}
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ protected void preConfigureBean(Reference reference, ReferenceBean referenceBean
dataBinder.registerCustomEditor(String.class, "filter", new StringTrimmerEditor(true));
dataBinder.registerCustomEditor(String.class, "listener", new StringTrimmerEditor(true));
dataBinder.registerCustomEditor(Map.class, "parameters", new PropertyEditorSupport() {

@Override
public void setAsText(String text) throws java.lang.IllegalArgumentException {
// Trim all whitespace
String content = StringUtils.trimAllWhitespace(text);
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ public class MetadataReportService {

protected final Logger logger = LoggerFactory.getLogger(getClass());

private static MetadataReportService metadataReportService;
private static volatile MetadataReportService metadataReportService;
private static Object lock = new Object();

private MetadataReportFactory metadataReportFactory = ExtensionLoader.getExtensionLoader(MetadataReportFactory.class).getAdaptiveExtension();
Original file line number Diff line number Diff line change
@@ -357,7 +357,7 @@ class MetadataReportRetry {
protected final Logger logger = LoggerFactory.getLogger(getClass());

final ScheduledExecutorService retryExecutor = Executors.newScheduledThreadPool(0, new NamedThreadFactory("DubboRegistryFailedRetryTimer", true));
ScheduledFuture retryScheduledFuture;
volatile ScheduledFuture retryScheduledFuture;
AtomicInteger retryCounter = new AtomicInteger(0);
// retry task schedule period
long retryPeriod;
Original file line number Diff line number Diff line change
@@ -103,22 +103,23 @@ public void testCount() throws Exception {
.addParameter(MonitorService.CONCURRENT, 1)
.addParameter(MonitorService.MAX_CONCURRENT, 1);
monitor.collect(statistics);
monitor.send();
while (lastStatistics == null) {
Thread.sleep(10);
}
Assertions.assertEquals(lastStatistics.getParameter(MonitorService.APPLICATION), "morgan");
Assertions.assertEquals(lastStatistics.getProtocol(), "dubbo");
Assertions.assertEquals(lastStatistics.getHost(), "10.20.153.10");
Assertions.assertEquals(lastStatistics.getParameter(MonitorService.APPLICATION), "morgan");
Assertions.assertEquals(lastStatistics.getParameter(MonitorService.INTERFACE), "MemberService");
Assertions.assertEquals(lastStatistics.getParameter(MonitorService.METHOD), "findPerson");
Assertions.assertEquals(lastStatistics.getParameter(MonitorService.CONSUMER), "10.20.153.11");
Assertions.assertEquals(lastStatistics.getParameter(MonitorService.SUCCESS), "1");
Assertions.assertEquals(lastStatistics.getParameter(MonitorService.FAILURE), "0");
Assertions.assertEquals(lastStatistics.getParameter(MonitorService.ELAPSED), "3");
Assertions.assertEquals(lastStatistics.getParameter(MonitorService.MAX_ELAPSED), "3");
Assertions.assertEquals(lastStatistics.getParameter(MonitorService.CONCURRENT), "1");
Assertions.assertEquals(lastStatistics.getParameter(MonitorService.MAX_CONCURRENT), "1");
Assertions.assertEquals("morgan", lastStatistics.getParameter(MonitorService.APPLICATION));
Assertions.assertEquals("dubbo", lastStatistics.getProtocol());
Assertions.assertEquals("10.20.153.10", lastStatistics.getHost());
Assertions.assertEquals("morgan", lastStatistics.getParameter(MonitorService.APPLICATION));
Assertions.assertEquals("MemberService", lastStatistics.getParameter(MonitorService.INTERFACE));
Assertions.assertEquals("findPerson", lastStatistics.getParameter(MonitorService.METHOD));
Assertions.assertEquals("10.20.153.11", lastStatistics.getParameter(MonitorService.CONSUMER));
Assertions.assertEquals("1", lastStatistics.getParameter(MonitorService.SUCCESS));
Assertions.assertEquals("0", lastStatistics.getParameter(MonitorService.FAILURE));
Assertions.assertEquals("3", lastStatistics.getParameter(MonitorService.ELAPSED));
Assertions.assertEquals("3", lastStatistics.getParameter(MonitorService.MAX_ELAPSED));
Assertions.assertEquals("1", lastStatistics.getParameter(MonitorService.CONCURRENT));
Assertions.assertEquals("1", lastStatistics.getParameter(MonitorService.MAX_CONCURRENT));
monitor.destroy();
}

Loading
Oops, something went wrong.

0 comments on commit f62a870

Please sign in to comment.