diff --git a/README.md b/README.md index 9285dd01f5..e34ee20894 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The following code snippet comes from [Dubbo Samples](https://github.com/apache/ ```bash git clone https://github.com/apache/dubbo-samples.git -cd dubbo-samples/dubbo-samples-api +cd dubbo-samples/1-basic/dubbo-samples-api ``` There's a [README](https://github.com/apache/dubbo-samples/blob/389cd612f1ea57ee6e575005b32f195c442c35a2/1-basic/dubbo-samples-api/README.md) file under `dubbo-samples-api` directory. We recommend referencing the samples in that directory by following the below-mentioned instructions: diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java index a1ea668291..c4561dfe4f 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java @@ -476,15 +476,21 @@ public abstract class AbstractDirectory implements Directory { } private boolean addValidInvoker(Invoker invoker) { + boolean result; synchronized (this.validInvokers) { - return this.validInvokers.add(invoker); + result = this.validInvokers.add(invoker); } + MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary())); + return result; } private boolean removeValidInvoker(Invoker invoker) { + boolean result; synchronized (this.validInvokers) { - return this.validInvokers.remove(invoker); + result = this.validInvokers.remove(invoker); } + MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary())); + return result; } protected abstract List> doList(SingleRouterChain singleRouterChain, diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java index 8a17dc0fc0..36e3d3eb59 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java @@ -36,6 +36,7 @@ import static org.apache.dubbo.common.constants.LoggerCodeConstants.CLUSTER_FAIL */ public class StaticDirectory extends AbstractDirectory { private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(StaticDirectory.class); + private final Class interfaceClass; public StaticDirectory(List> invokers) { this(null, invokers, null); @@ -55,11 +56,12 @@ public class StaticDirectory extends AbstractDirectory { throw new IllegalArgumentException("invokers == null"); } this.setInvokers(new BitList<>(invokers)); + this.interfaceClass = invokers.get(0).getInterface(); } @Override public Class getInterface() { - return getInvokers().get(0).getInterface(); + return interfaceClass; } @Override diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java index 4efa2ba9fe..582578b5e9 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java @@ -110,7 +110,7 @@ public class ConsumerContextFilter implements ClusterFilter, ClusterFilter.Liste if (timeoutCountDown.isExpired()) { return AsyncRpcResult.newDefaultAsyncResult(new RpcException(RpcException.TIMEOUT_TERMINATE, "No time left for making the following call: " + invocation.getServiceName() + "." - + invocation.getMethodName() + ", terminate directly."), invocation); + + RpcUtils.getMethodName(invocation) + ", terminate directly."), invocation); } } } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/governance/DefaultGovernanceRuleRepositoryImpl.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/governance/DefaultGovernanceRuleRepositoryImpl.java index 6d6770876b..1d8d7183c3 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/governance/DefaultGovernanceRuleRepositoryImpl.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/governance/DefaultGovernanceRuleRepositoryImpl.java @@ -54,7 +54,7 @@ public class DefaultGovernanceRuleRepositoryImpl implements GovernanceRuleReposi } private DynamicConfiguration getDynamicConfiguration() { - return moduleModel.getModelEnvironment().getDynamicConfiguration().orElse(null); + return moduleModel.modelEnvironment().getDynamicConfiguration().orElse(null); } } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java index a4866e888b..59ecd9a305 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java @@ -22,6 +22,7 @@ import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.cluster.ClusterInvoker; import org.apache.dubbo.rpc.cluster.LoadBalance; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.List; @@ -83,7 +84,7 @@ public abstract class AbstractLoadBalance implements LoadBalance { if (REGISTRY_SERVICE_REFERENCE_PATH.equals(url.getServiceInterface())) { weight = url.getParameter(WEIGHT_KEY, DEFAULT_WEIGHT); } else { - weight = url.getMethodParameter(invocation.getMethodName(), WEIGHT_KEY, DEFAULT_WEIGHT); + weight = url.getMethodParameter(RpcUtils.getMethodName(invocation), WEIGHT_KEY, DEFAULT_WEIGHT); if (weight > 0) { long timestamp = invoker.getUrl().getParameter(TIMESTAMP_KEY, 0L); if (timestamp > 0L) { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java index 8604def436..37386ab186 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java @@ -28,7 +28,6 @@ import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; /** @@ -97,10 +96,7 @@ public class ConsistentHashLoadBalance extends AbstractLoadBalance { } public Invoker select(Invocation invocation) { - boolean isGeneric = invocation.getMethodName().equals($INVOKE); - String key = toKey(invocation.getArguments(),isGeneric); - - byte[] digest = Bytes.getMD5(key); + byte[] digest = Bytes.getMD5(RpcUtils.getMethodName(invocation)); return selectForKey(hash(digest, 0)); } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java index 41c1bab569..9eb41f6fe9 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcStatus; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.List; import java.util.concurrent.ThreadLocalRandom; @@ -60,7 +61,7 @@ public class LeastActiveLoadBalance extends AbstractLoadBalance { for (int i = 0; i < length; i++) { Invoker invoker = invokers.get(i); // Get the active number of the invoker - int active = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()).getActive(); + int active = RpcStatus.getStatus(invoker.getUrl(), RpcUtils.getMethodName(invocation)).getActive(); // Get the weight of the invoker's configuration. The default value is 100. int afterWarmup = getWeight(invoker, invocation); // save for later use @@ -97,7 +98,7 @@ public class LeastActiveLoadBalance extends AbstractLoadBalance { return invokers.get(leastIndexes[0]); } if (!sameWeight && totalWeight > 0) { - // If (not every invoker has the same weight & at least one invoker's weight>0), select randomly based on + // If (not every invoker has the same weight & at least one invoker's weight>0), select randomly based on // totalWeight. int offsetWeight = ThreadLocalRandom.current().nextInt(totalWeight); // Return a invoker based on the random value. diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java index ce5bdaa16c..1b0b9fce7e 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java @@ -21,6 +21,7 @@ import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.cluster.ClusterInvoker; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.Arrays; import java.util.List; @@ -115,7 +116,7 @@ public class RandomLoadBalance extends AbstractLoadBalance { String weight = invokerUrl.getParameter(WEIGHT_KEY); return StringUtils.isNotEmpty(weight); } else { - String weight = invokerUrl.getMethodParameter(invocation.getMethodName(), WEIGHT_KEY); + String weight = invokerUrl.getMethodParameter(RpcUtils.getMethodName(invocation), WEIGHT_KEY); if (StringUtils.isNotEmpty(weight)) { return true; } else { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RoundRobinLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RoundRobinLoadBalance.java index 8a24a4af4a..0ee6a82c5d 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RoundRobinLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RoundRobinLoadBalance.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.ConcurrentHashMapUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.Collection; import java.util.List; @@ -79,7 +80,7 @@ public class RoundRobinLoadBalance extends AbstractLoadBalance { * @return */ protected Collection getInvokerAddrList(List> invokers, Invocation invocation) { - String key = invokers.get(0).getUrl().getServiceKey() + "." + invocation.getMethodName(); + String key = invokers.get(0).getUrl().getServiceKey() + "." + RpcUtils.getMethodName(invocation); Map map = methodWeightMap.get(key); if (map != null) { return map.keySet(); @@ -89,7 +90,7 @@ public class RoundRobinLoadBalance extends AbstractLoadBalance { @Override protected Invoker doSelect(List> invokers, URL url, Invocation invocation) { - String key = invokers.get(0).getUrl().getServiceKey() + "." + invocation.getMethodName(); + String key = invokers.get(0).getUrl().getServiceKey() + "." + RpcUtils.getMethodName(invocation); ConcurrentMap map = ConcurrentHashMapUtils.computeIfAbsent(methodWeightMap, key, k -> new ConcurrentHashMap<>()); int totalWeight = 0; long maxCurrent = Long.MIN_VALUE; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ShortestResponseLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ShortestResponseLoadBalance.java index 9b9eae5005..1244e76147 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ShortestResponseLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ShortestResponseLoadBalance.java @@ -25,6 +25,7 @@ import org.apache.dubbo.rpc.RpcStatus; import org.apache.dubbo.rpc.cluster.Constants; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ScopeModelAware; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -58,7 +59,7 @@ public class ShortestResponseLoadBalance extends AbstractLoadBalance implements @Override public void setApplicationModel(ApplicationModel applicationModel) { - slidePeriod = applicationModel.getModelEnvironment().getConfiguration().getInt(Constants.SHORTEST_RESPONSE_SLIDE_PERIOD, 30_000); + slidePeriod = applicationModel.modelEnvironment().getConfiguration().getInt(Constants.SHORTEST_RESPONSE_SLIDE_PERIOD, 30_000); executorService = applicationModel.getFrameworkModel().getBeanFactory() .getBean(FrameworkExecutorRepository.class).getSharedExecutor(); } @@ -116,7 +117,7 @@ public class ShortestResponseLoadBalance extends AbstractLoadBalance implements // Filter out all the shortest response invokers for (int i = 0; i < length; i++) { Invoker invoker = invokers.get(i); - RpcStatus rpcStatus = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); + RpcStatus rpcStatus = RpcStatus.getStatus(invoker.getUrl(), RpcUtils.getMethodName(invocation)); SlideWindowData slideWindowData = ConcurrentHashMapUtils.computeIfAbsent(methodMap, rpcStatus, SlideWindowData::new); // Calculate the estimated response time from the product of active connections and succeeded average elapsed time. diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/matcher/AbstractConditionMatcher.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/matcher/AbstractConditionMatcher.java index 1dc8310700..db5cd94b95 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/matcher/AbstractConditionMatcher.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/matcher/AbstractConditionMatcher.java @@ -22,6 +22,7 @@ import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.cluster.router.condition.matcher.pattern.ValuePattern; import org.apache.dubbo.rpc.model.ModuleModel; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.HashSet; import java.util.List; @@ -55,7 +56,7 @@ public abstract class AbstractConditionMatcher implements ConditionMatcher { String sampleValue; //get real invoked method name from invocation if (invocation != null && (METHOD_KEY.equals(conditionKey) || METHODS_KEY.equals(conditionKey))) { - sampleValue = invocation.getMethodName(); + sampleValue = RpcUtils.getMethodName(invocation); } else { sampleValue = sample.get(conditionKey); } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboMethodMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboMethodMatch.java index 32644cf526..f252410478 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboMethodMatch.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboMethodMatch.java @@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.cluster.router.mesh.rule.virtualservice.match; import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.List; import java.util.Map; @@ -83,7 +84,7 @@ public class DubboMethodMatch { public boolean isMatch(Invocation invocation) { StringMatch nameMatch = getName_match(); - if (nameMatch != null && !nameMatch.isMatch(invocation.getMethodName())) { + if (nameMatch != null && !nameMatch.isMatch(RpcUtils.getMethodName(invocation))) { return false; } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptStateRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptStateRouter.java index ac01380be1..d0f918094a 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptStateRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptStateRouter.java @@ -29,6 +29,7 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.router.RouterSnapshotNode; import org.apache.dubbo.rpc.cluster.router.state.AbstractStateRouter; import org.apache.dubbo.rpc.cluster.router.state.BitList; +import org.apache.dubbo.rpc.support.RpcUtils; import javax.script.Bindings; import javax.script.Compilable; @@ -139,7 +140,7 @@ public class ScriptStateRouter extends AbstractStateRouter { return function.eval(bindings); } catch (ScriptException e) { logger.error(CLUSTER_SCRIPT_EXCEPTION, "Scriptrouter exec script error", "", "Script route error, rule has been ignored. rule: " + rule + ", method:" + - invocation.getMethodName() + ", url: " + RpcContext.getContext().getUrl(), e); + RpcUtils.getMethodName(invocation) + ", url: " + RpcContext.getContext().getUrl(), e); return invokers; } }, accessControlContext)); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java index 89c58a6dc9..f6325df43b 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java @@ -158,7 +158,7 @@ public abstract class AbstractClusterInvoker implements ClusterInvoker { if (CollectionUtils.isEmpty(invokers)) { return null; } - String methodName = invocation == null ? StringUtils.EMPTY_STRING : invocation.getMethodName(); + String methodName = invocation == null ? StringUtils.EMPTY_STRING : RpcUtils.getMethodName(invocation); boolean sticky = invokers.get(0).getUrl() .getMethodParameter(methodName, CLUSTER_STICKY_KEY, DEFAULT_CLUSTER_STICKY); @@ -363,7 +363,7 @@ public abstract class AbstractClusterInvoker implements ClusterInvoker { protected void checkInvokers(List> invokers, Invocation invocation) { if (CollectionUtils.isEmpty(invokers)) { throw new RpcException(RpcException.NO_INVOKER_AVAILABLE_AFTER_FILTER, "Failed to invoke the method " - + invocation.getMethodName() + " in the service " + getInterface().getName() + + RpcUtils.getMethodName(invocation) + " in the service " + getInterface().getName() + ". No provider available for the service " + getDirectory().getConsumerUrl().getServiceKey() + " from registry " + getDirectory().getUrl().getAddress() + " on the consumer " + NetUtils.getLocalHost() diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailbackClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailbackClusterInvoker.java index 368244a1df..1a20839768 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailbackClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailbackClusterInvoker.java @@ -32,6 +32,7 @@ import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.Directory; import org.apache.dubbo.rpc.cluster.LoadBalance; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.Collections; import java.util.List; @@ -109,7 +110,9 @@ public class FailbackClusterInvoker extends AbstractClusterInvoker { // Then the serviceContext will be cleared after the call is completed. return invokeWithContextAsync(invoker, invocation, consumerUrl); } catch (Throwable e) { - logger.error(CLUSTER_FAILED_INVOKE_SERVICE,"Failback to invoke method and start to retries","","Failback to invoke method " + invocation.getMethodName() + ", wait for retry in background. Ignored exception: " + logger.error(CLUSTER_FAILED_INVOKE_SERVICE,"Failback to invoke method and start to retries", + "","Failback to invoke method " + RpcUtils.getMethodName(invocation) + + ", wait for retry in background. Ignored exception: " + e.getMessage() + ", ",e); if (retries > 0) { addFailed(loadbalance, invocation, invokers, invoker, consumerUrl); @@ -161,13 +164,13 @@ public class FailbackClusterInvoker extends AbstractClusterInvoker { @Override public void run(Timeout timeout) { try { - logger.info("Attempt to retry to invoke method " + invocation.getMethodName() + + logger.info("Attempt to retry to invoke method " + RpcUtils.getMethodName(invocation) + ". The total will retry " + retries + " times, the current is the " + retriedTimes + " retry"); Invoker retryInvoker = select(loadbalance, invocation, invokers, Collections.singletonList(lastInvoker)); lastInvoker = retryInvoker; invokeWithContextAsync(retryInvoker, invocation, consumerUrl); } catch (Throwable e) { - logger.error(CLUSTER_FAILED_INVOKE_SERVICE,"Failed retry to invoke method","","Failed retry to invoke method " + invocation.getMethodName() + ", waiting again.",e); + logger.error(CLUSTER_FAILED_INVOKE_SERVICE,"Failed retry to invoke method","","Failed retry to invoke method " + RpcUtils.getMethodName(invocation) + ", waiting again.",e); if ((++retriedTimes) >= retries) { logger.error(CLUSTER_FAILED_INVOKE_SERVICE,"Failed retry to invoke method and retry times exceed threshold","","Failed retry times exceed threshold (" + retries + "), We have to abandon, invocation->" + invocation,e); } else { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailfastClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailfastClusterInvoker.java index 22c708f824..87b3b45c5a 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailfastClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailfastClusterInvoker.java @@ -24,6 +24,7 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.Directory; import org.apache.dubbo.rpc.cluster.LoadBalance; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.List; @@ -51,7 +52,7 @@ public class FailfastClusterInvoker extends AbstractClusterInvoker { throw new RpcException(e instanceof RpcException ? ((RpcException) e).getCode() : 0, "Failfast invoke providers " + invoker.getUrl() + " " + loadbalance.getClass().getSimpleName() + " for service " + getInterface().getName() - + " method " + invocation.getMethodName() + " on consumer " + NetUtils.getLocalHost() + + " method " + RpcUtils.getMethodName(invocation) + " on consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", but no luck to perform the invocation. Last error is: " + e.getMessage(), e.getCause() != null ? e.getCause() : e); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java index a935fd95ea..348c6e032d 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java @@ -97,13 +97,13 @@ public class MockClusterInvoker implements ClusterInvoker { public Result invoke(Invocation invocation) throws RpcException { Result result; - String value = getUrl().getMethodParameter(invocation.getMethodName(), MOCK_KEY, Boolean.FALSE.toString()).trim(); + String value = getUrl().getMethodParameter(RpcUtils.getMethodName(invocation), MOCK_KEY, Boolean.FALSE.toString()).trim(); if (ConfigUtils.isEmpty(value)) { //no mock result = this.invoker.invoke(invocation); } else if (value.startsWith(FORCE_KEY)) { if (logger.isWarnEnabled()) { - logger.warn(CLUSTER_FAILED_MOCK_REQUEST,"force mock","","force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + getUrl()); + logger.warn(CLUSTER_FAILED_MOCK_REQUEST,"force mock","","force-mock: " + RpcUtils.getMethodName(invocation) + " force-mock enabled , url : " + getUrl()); } //force:direct mock result = doMockInvoke(invocation, null); @@ -128,7 +128,7 @@ public class MockClusterInvoker implements ClusterInvoker { } if (logger.isWarnEnabled()) { - logger.warn(CLUSTER_FAILED_MOCK_REQUEST,"failed to mock invoke","","fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + getUrl(),e); + logger.warn(CLUSTER_FAILED_MOCK_REQUEST,"failed to mock invoke","","fail-mock: " + RpcUtils.getMethodName(invocation) + " fail-mock enabled , url : " + getUrl(),e); } result = doMockInvoke(invocation, e); } @@ -198,7 +198,7 @@ public class MockClusterInvoker implements ClusterInvoker { } catch (RpcException e) { if (logger.isInfoEnabled()) { logger.info("Exception when try to invoke mock. Get mock invokers error for service:" - + getUrl().getServiceInterface() + ", method:" + invocation.getMethodName() + + getUrl().getServiceInterface() + ", method:" + RpcUtils.getMethodName(invocation) + ", will construct a new mock with 'new MockInvoker()'.", e); } } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java index 71b7ddf95d..98fd33bfef 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java @@ -20,6 +20,7 @@ package org.apache.dubbo.rpc.cluster.support.wrapper; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.url.component.DubboServiceAddressURL; import org.apache.dubbo.common.url.component.ServiceConfigURL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.rpc.Exporter; @@ -35,6 +36,7 @@ import org.apache.dubbo.rpc.cluster.Directory; import org.apache.dubbo.rpc.cluster.directory.StaticDirectory; import org.apache.dubbo.rpc.listener.ExporterChangeListener; import org.apache.dubbo.rpc.listener.InjvmExporterListener; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.ArrayList; import java.util.List; @@ -142,26 +144,26 @@ public class ScopeClusterInvoker implements ClusterInvoker, ExporterChange // When broadcasting, it should be called remotely. if (isBroadcast()) { if (logger.isDebugEnabled()) { - logger.debug("Performing broadcast call for method: " + invocation.getMethodName() + " of service: " + getUrl().getServiceKey()); + logger.debug("Performing broadcast call for method: " + RpcUtils.getMethodName(invocation) + " of service: " + getUrl().getServiceKey()); } return invoker.invoke(invocation); } if (peerFlag) { if (logger.isDebugEnabled()) { - logger.debug("Performing point-to-point call for method: " + invocation.getMethodName() + " of service: " + getUrl().getServiceKey()); + logger.debug("Performing point-to-point call for method: " + RpcUtils.getMethodName(invocation) + " of service: " + getUrl().getServiceKey()); } // If it's a point-to-point direct connection, invoke the original Invoker return invoker.invoke(invocation); } if (isInjvmExported()) { if (logger.isDebugEnabled()) { - logger.debug("Performing local JVM call for method: " + invocation.getMethodName() + " of service: " + getUrl().getServiceKey()); + logger.debug("Performing local JVM call for method: " + RpcUtils.getMethodName(invocation) + " of service: " + getUrl().getServiceKey()); } // If it's exported to the local JVM, invoke the corresponding Invoker return injvmInvoker.invoke(invocation); } if (logger.isDebugEnabled()) { - logger.debug("Performing remote call for method: " + invocation.getMethodName() + " of service: " + getUrl().getServiceKey()); + logger.debug("Performing remote call for method: " + RpcUtils.getMethodName(invocation) + " of service: " + getUrl().getServiceKey()); } // Otherwise, delegate the invocation to the original Invoker return invoker.invoke(invocation); @@ -178,7 +180,7 @@ public class ScopeClusterInvoker implements ClusterInvoker, ExporterChange } if (getUrl().getServiceKey().equals(exporter.getInvoker().getUrl().getServiceKey()) && exporter.getInvoker().getUrl().getProtocol().equalsIgnoreCase(LOCAL_PROTOCOL)) { - createInjvmInvoker(); + createInjvmInvoker(exporter); isExported.compareAndSet(false, true); } } @@ -274,14 +276,19 @@ public class ScopeClusterInvoker implements ClusterInvoker, ExporterChange /** * Creates a new Invoker for the current ScopeClusterInvoker and exports it to the local JVM. */ - private void createInjvmInvoker() { + private void createInjvmInvoker(Exporter exporter) { if (injvmInvoker == null) { synchronized (createLock) { if (injvmInvoker == null) { - URL url = new ServiceConfigURL(LOCAL_PROTOCOL, NetUtils.getLocalHost(), getUrl().getPort(), getInterface().getName(), getUrl().getParameters()); + URL url = new ServiceConfigURL(LOCAL_PROTOCOL, NetUtils.getLocalHost(), getUrl().getPort(), + getInterface().getName(), getUrl().getParameters()); url = url.setScopeModel(getUrl().getScopeModel()); url = url.setServiceModel(getUrl().getServiceModel()); - Invoker invoker = protocolSPI.refer(getInterface(), url); + + DubboServiceAddressURL consumerUrl = new DubboServiceAddressURL(url.getUrlAddress(), url.getUrlParam(), + exporter.getInvoker().getUrl(), null); + + Invoker invoker = protocolSPI.refer(getInterface(), consumerUrl); List> invokers = new ArrayList<>(); invokers.add(invoker); injvmInvoker = Cluster.getCluster(url.getScopeModel(), Cluster.DEFAULT, false).join(new StaticDirectory(url, invokers), true); diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.java index 2f293484b4..567e9cab3b 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.filter; -import io.micrometer.tracing.test.SampleTestRunner; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.TracingConfig; import org.apache.dubbo.rpc.AppResponse; @@ -24,6 +23,8 @@ import org.apache.dubbo.rpc.BaseFilter; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.model.ApplicationModel; + +import io.micrometer.tracing.test.SampleTestRunner; import org.junit.jupiter.api.AfterEach; import static org.mockito.BDDMockito.given; diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/ObservationSenderFilterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/ObservationSenderFilterTest.java index 8166203400..1315686740 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/ObservationSenderFilterTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/ObservationSenderFilterTest.java @@ -17,14 +17,15 @@ package org.apache.dubbo.rpc.cluster.filter; -import io.micrometer.common.KeyValues; -import io.micrometer.core.tck.MeterRegistryAssert; -import io.micrometer.tracing.test.SampleTestRunner; -import io.micrometer.tracing.test.simple.SpansAssert; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.cluster.filter.support.ObservationSenderFilter; import org.apache.dubbo.rpc.model.ApplicationModel; + +import io.micrometer.common.KeyValues; +import io.micrometer.core.tck.MeterRegistryAssert; +import io.micrometer.tracing.test.SampleTestRunner; +import io.micrometer.tracing.test.simple.SpansAssert; import org.assertj.core.api.BDDAssertions; class ObservationSenderFilterTest extends AbstractObservationFilterTest { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java index eaca5a8dbb..dae8a0ca03 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java @@ -44,7 +44,6 @@ import java.util.Set; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT; import static org.apache.dubbo.common.constants.CommonConstants.SHUTDOWN_WAIT_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SHUTDOWN_WAIT_SECONDS_KEY; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION; /** * Utilities for manipulating configurations from different sources @@ -77,7 +76,7 @@ public final class ConfigurationUtils { * @return */ public static Configuration getSystemConfiguration(ScopeModel scopeModel) { - return getScopeModelOrDefaultApplicationModel(scopeModel).getModelEnvironment().getSystemConfiguration(); + return getScopeModelOrDefaultApplicationModel(scopeModel).modelEnvironment().getSystemConfiguration(); } /** @@ -86,7 +85,7 @@ public final class ConfigurationUtils { * @return */ public static Configuration getEnvConfiguration(ScopeModel scopeModel) { - return getScopeModelOrDefaultApplicationModel(scopeModel).getModelEnvironment().getEnvironmentConfiguration(); + return getScopeModelOrDefaultApplicationModel(scopeModel).modelEnvironment().getEnvironmentConfiguration(); } /** @@ -98,11 +97,11 @@ public final class ConfigurationUtils { */ public static Configuration getGlobalConfiguration(ScopeModel scopeModel) { - return getScopeModelOrDefaultApplicationModel(scopeModel).getModelEnvironment().getConfiguration(); + return getScopeModelOrDefaultApplicationModel(scopeModel).modelEnvironment().getConfiguration(); } public static Configuration getDynamicGlobalConfiguration(ScopeModel scopeModel) { - return scopeModel.getModelEnvironment().getDynamicGlobalConfiguration(); + return scopeModel.modelEnvironment().getDynamicGlobalConfiguration(); } // FIXME @@ -174,7 +173,7 @@ public final class ConfigurationUtils { public static Map parseProperties(String content) throws IOException { Map map = new HashMap<>(); if (StringUtils.isEmpty(content)) { - logger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "Config center was specified, but no config item found."); + logger.info("Config center was specified, but no config item found."); } else { Properties properties = new Properties(); properties.load(new StringReader(content)); @@ -365,7 +364,7 @@ public final class ConfigurationUtils { */ @Deprecated public static Configuration getSystemConfiguration() { - return ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration(); + return ApplicationModel.defaultModel().modelEnvironment().getSystemConfiguration(); } /** @@ -375,7 +374,7 @@ public final class ConfigurationUtils { */ @Deprecated public static Configuration getEnvConfiguration() { - return ApplicationModel.defaultModel().getModelEnvironment().getEnvironmentConfiguration(); + return ApplicationModel.defaultModel().modelEnvironment().getEnvironmentConfiguration(); } /** @@ -385,7 +384,7 @@ public final class ConfigurationUtils { */ @Deprecated public static Configuration getGlobalConfiguration() { - return ApplicationModel.defaultModel().getModelEnvironment().getConfiguration(); + return ApplicationModel.defaultModel().modelEnvironment().getConfiguration(); } /** @@ -395,7 +394,7 @@ public final class ConfigurationUtils { */ @Deprecated public static Configuration getDynamicGlobalConfiguration() { - return ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().getDynamicGlobalConfiguration(); + return ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().getDynamicGlobalConfiguration(); } /** diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ModuleEnvironment.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ModuleEnvironment.java index 673815afb1..cf51624262 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ModuleEnvironment.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ModuleEnvironment.java @@ -54,7 +54,7 @@ public class ModuleEnvironment extends Environment implements ModuleExt { public ModuleEnvironment(ModuleModel moduleModel) { super(moduleModel); this.moduleModel = moduleModel; - this.applicationDelegate = moduleModel.getApplicationModel().getModelEnvironment(); + this.applicationDelegate = moduleModel.getApplicationModel().modelEnvironment(); } @Override diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java index 02af9b73db..5bc262708e 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java @@ -73,6 +73,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Pattern; +import java.util.stream.Collectors; import static java.util.Arrays.asList; import static java.util.ServiceLoader.load; @@ -346,7 +347,9 @@ public class ExtensionLoader { checkDestroyed(); // solve the bug of using @SPI's wrapper method to report a null pointer exception. Map, T> activateExtensionsMap = new TreeMap<>(activateComparator); - List names = values == null ? new ArrayList<>(0) : asList(values); + List names = values == null ? + new ArrayList<>(0) : + Arrays.stream(values).map(StringUtils::trim).collect(Collectors.toList()); Set namesSet = new HashSet<>(names); if (!namesSet.contains(REMOVE_VALUE_PREFIX + DEFAULT_KEY)) { if (cachedActivateGroups.size() == 0) { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadlessExecutor.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadlessExecutor.java index 23ef3cf235..5ff664bc0b 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadlessExecutor.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadlessExecutor.java @@ -26,6 +26,7 @@ import java.util.concurrent.AbstractExecutorService; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.LockSupport; /** @@ -46,7 +47,7 @@ public class ThreadlessExecutor extends AbstractExecutorService { /** * Wait thread. It must be visible to other threads and does not need to be thread-safe */ - private volatile Object waiter; + private final AtomicReference waiter = new AtomicReference<>(); /** * Waits until there is a task, executes the task and all queued tasks (if there're any). The task is either a normal @@ -56,22 +57,25 @@ public class ThreadlessExecutor extends AbstractExecutorService { throwIfInterrupted(); Runnable runnable = queue.poll(); if (runnable == null) { - waiter = Thread.currentThread(); - try { - while ((runnable = queue.poll()) == null) { - long restTime = deadline - System.nanoTime(); - if (restTime <= 0) { - return; + if (waiter.compareAndSet(null, Thread.currentThread())) { + try { + while ((runnable = queue.poll()) == null && waiter.get() == Thread.currentThread()) { + long restTime = deadline - System.nanoTime(); + if (restTime <= 0) { + return; + } + LockSupport.parkNanos(this, restTime); + throwIfInterrupted(); } - LockSupport.parkNanos(this, restTime); - throwIfInterrupted(); + } finally { + waiter.compareAndSet(Thread.currentThread(), null); } - } finally { - waiter = null; } } do { - runnable.run(); + if (runnable != null) { + runnable.run(); + } } while ((runnable = queue.poll()) != null); } @@ -91,8 +95,8 @@ public class ThreadlessExecutor extends AbstractExecutorService { public void execute(Runnable runnable) { RunnableWrapper run = new RunnableWrapper(runnable); queue.add(run); - if (waiter != SHUTDOWN) { - LockSupport.unpark((Thread) waiter); + if (waiter.get() != SHUTDOWN) { + LockSupport.unpark((Thread) waiter.get()); } else if (queue.remove(run)) { throw new RejectedExecutionException(); } @@ -109,7 +113,10 @@ public class ThreadlessExecutor extends AbstractExecutorService { @Override public List shutdownNow() { - waiter = SHUTDOWN; + if (waiter.get() != SHUTDOWN) { + LockSupport.unpark((Thread) waiter.get()); + } + waiter.set(SHUTDOWN); Runnable runnable; while ((runnable = queue.poll()) != null) { runnable.run(); @@ -119,7 +126,7 @@ public class ThreadlessExecutor extends AbstractExecutorService { @Override public boolean isShutdown() { - return waiter == SHUTDOWN; + return waiter.get() == SHUTDOWN; } @Override diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ToStringUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ToStringUtils.java index d405703098..507146736a 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ToStringUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ToStringUtils.java @@ -16,7 +16,11 @@ */ package org.apache.dubbo.common.utils; +import org.apache.dubbo.config.AbstractConfig; + import java.util.Arrays; +import java.util.List; +import java.util.Map; public class ToStringUtils { @@ -36,4 +40,63 @@ public class ToStringUtils { return obj.toString(); } } + + public static String toString(Object obj) { + if (obj == null) { + return "null"; + } + if (ClassUtils.isSimpleType(obj.getClass())) { + return obj.toString(); + } + if (obj.getClass().isPrimitive()) { + return obj.toString(); + } + if (obj instanceof Object[]) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("["); + Object[] objects = (Object[]) obj; + for (int i = 0; i < objects.length; i++) { + stringBuilder.append(toString(objects[i])); + if (i != objects.length - 1) { + stringBuilder.append(", "); + } + } + stringBuilder.append("]"); + return stringBuilder.toString(); + } + if (obj instanceof List) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("["); + List list = (List) obj; + for (int i = 0; i < list.size(); i++) { + stringBuilder.append(toString(list.get(i))); + if (i != list.size() - 1) { + stringBuilder.append(", "); + } + } + stringBuilder.append("]"); + return stringBuilder.toString(); + } + if (obj instanceof Map) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{"); + Map map = (Map) obj; + int i = 0; + for (Object key : map.keySet()) { + stringBuilder.append(toString(key)); + stringBuilder.append("="); + stringBuilder.append(toString(map.get(key))); + if (i != map.size() - 1) { + stringBuilder.append(", "); + } + i++; + } + stringBuilder.append("}"); + return stringBuilder.toString(); + } + if (obj instanceof AbstractConfig) { + return obj.toString(); + } + return obj.getClass() + "@" + Integer.toHexString(System.identityHashCode(obj)); + } } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java index 6247a02bd4..eee83f501c 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java @@ -31,6 +31,7 @@ import org.apache.dubbo.common.utils.FieldUtils; import org.apache.dubbo.common.utils.MethodUtils; import org.apache.dubbo.common.utils.ReflectUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.ToStringUtils; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.context.ConfigMode; import org.apache.dubbo.config.support.Nested; @@ -695,7 +696,7 @@ public abstract class AbstractConfig implements Serializable { } protected void refreshWithPrefixes(List prefixes, ConfigMode configMode) { - Environment environment = getScopeModel().getModelEnvironment(); + Environment environment = getScopeModel().modelEnvironment(); List> configurationMaps = environment.getConfigurationMaps(); // Search props starts with PREFIX in order @@ -967,7 +968,7 @@ public abstract class AbstractConfig implements Serializable { buf.append(' '); buf.append(key); buf.append("=\""); - buf.append(key.equals("password") ? "******" : value); + buf.append(key.equals("password") ? "******" : ToStringUtils.toString(value)); buf.append('\"'); } } catch (Exception e) { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java index dec489ac9a..3d48ae2a96 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java @@ -303,7 +303,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig { } protected Environment getEnvironment() { - return getScopeModel().getModelEnvironment(); + return getScopeModel().modelEnvironment(); } @Override diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java index e659b10b6f..058f1d1622 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java @@ -21,6 +21,8 @@ import org.apache.dubbo.config.support.Parameter; import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.support.ProtocolUtils; +import java.beans.Transient; + import static org.apache.dubbo.common.constants.CommonConstants.INVOKER_LISTENER_KEY; import static org.apache.dubbo.common.constants.CommonConstants.REFERENCE_FILTER_KEY; import static org.apache.dubbo.common.constants.CommonConstants.REFER_ASYNC_KEY; @@ -184,6 +186,7 @@ public abstract class AbstractReferenceConfig extends AbstractInterfaceConfig { } @Override + @Transient protected boolean isNeedCheckMethod() { return StringUtils.isEmpty(getGeneric()); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/MethodConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/MethodConfig.java index d8696fadc4..914002e1a4 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/MethodConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/MethodConfig.java @@ -236,7 +236,7 @@ public class MethodConfig extends AbstractMethodConfig { private void refreshArgument(ArgumentConfig argument, InmemoryConfiguration subPropsConfiguration) { if (argument.getIndex() != null && argument.getIndex() >= 0) { String prefix = argument.getIndex() + "."; - Environment environment = getScopeModel().getModelEnvironment(); + Environment environment = getScopeModel().modelEnvironment(); List methods = MethodUtils.getMethods(argument.getClass(), method -> method.getDeclaringClass() != Object.class); for (java.lang.reflect.Method method : methods) { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ModuleConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ModuleConfig.java index 511c6bbfb7..ef6eaf870d 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ModuleConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ModuleConfig.java @@ -22,6 +22,7 @@ import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ScopeModel; +import java.beans.Transient; import java.util.ArrayList; import java.util.List; @@ -135,11 +136,13 @@ public class ModuleConfig extends AbstractConfig { } @Override + @Transient public ModuleModel getScopeModel() { return (ModuleModel) super.getScopeModel(); } @Override + @Transient protected ScopeModel getDefaultModel() { return ApplicationModel.defaultModel().getDefaultModule(); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java index bfeacacba5..4b41ea2786 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java @@ -150,6 +150,7 @@ public abstract class ReferenceConfigBase extends AbstractReferenceConfig { } @Override + @Transient public Map getMetaData() { return getMetaData(null); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java index 0db03d0208..60c5c641ec 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java @@ -180,6 +180,7 @@ public abstract class ServiceConfigBase extends AbstractServiceConfig { } @Override + @Transient public Map getMetaData() { return getMetaData(null); } @@ -425,7 +426,25 @@ public abstract class ServiceConfigBase extends AbstractServiceConfig { public abstract boolean isUnexported(); + /** + * Export service to network + * + * @param register Whether register service to registry. If false, can be registered manually + * through the {@link ServiceConfigBase#register(boolean)} API. + */ public abstract void export(boolean register); - public abstract void register(); + /** + * Register delay published service to registry. + */ + public final void register() { + register(false); + } + + /** + * Register delay published service to registry. + * + * @param onlyDefault only register those services that export with configured register false + */ + public abstract void register(boolean onlyDefault); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java b/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java index 8a5dfdd79b..0f8a0e23d4 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java @@ -105,7 +105,7 @@ public abstract class AbstractConfigManager extends LifecycleAdapter { this.scopeModel = scopeModel; this.applicationModel = ScopeModelUtil.getApplicationModel(scopeModel); this.supportedConfigTypes = supportedConfigTypes; - environment = scopeModel.getModelEnvironment(); + environment = scopeModel.modelEnvironment(); } @Override @@ -113,7 +113,7 @@ public abstract class AbstractConfigManager extends LifecycleAdapter { if (!initialized.compareAndSet(false, true)) { return; } - CompositeConfiguration configuration = scopeModel.getModelEnvironment().getConfiguration(); + CompositeConfiguration configuration = scopeModel.modelEnvironment().getConfiguration(); // dubbo.config.mode String configModeStr = (String) configuration.getProperty(ConfigKeys.DUBBO_CONFIG_MODE); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ExporterConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ExporterConfig.java index 3b621572d0..58de4dcd80 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ExporterConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ExporterConfig.java @@ -17,13 +17,13 @@ package org.apache.dubbo.config.nested; +import org.apache.dubbo.config.support.Nested; + import java.io.Serializable; import java.time.Duration; import java.util.HashMap; import java.util.Map; -import org.apache.dubbo.config.support.Nested; - public class ExporterConfig implements Serializable { @Nested diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java index 0978143257..0544df59ed 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java @@ -201,7 +201,7 @@ public class ApplicationModel extends ScopeModel { } @Override - public Environment getModelEnvironment() { + public Environment modelEnvironment() { if (environment == null) { environment = (Environment) this.getExtensionLoader(ApplicationExt.class) .getExtension(Environment.NAME); @@ -390,11 +390,11 @@ public class ApplicationModel extends ScopeModel { } /** - * @deprecated Replace to {@link ScopeModel#getModelEnvironment()} + * @deprecated Replace to {@link ScopeModel#modelEnvironment()} */ @Deprecated public static Environment getEnvironment() { - return defaultModel().getModelEnvironment(); + return defaultModel().modelEnvironment(); } /** diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/FrameworkModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/FrameworkModel.java index 2bdfa9f577..09a001f3bb 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/FrameworkModel.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/FrameworkModel.java @@ -367,7 +367,7 @@ public class FrameworkModel extends ScopeModel { } @Override - public Environment getModelEnvironment() { + public Environment modelEnvironment() { throw new UnsupportedOperationException("Environment is inaccessible for FrameworkModel"); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java index 5422c6169a..358868af69 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java @@ -150,7 +150,7 @@ public class ModuleModel extends ScopeModel { } @Override - public ModuleEnvironment getModelEnvironment() { + public ModuleEnvironment modelEnvironment() { if (moduleEnvironment == null) { moduleEnvironment = (ModuleEnvironment) this.getExtensionLoader(ModuleExt.class) .getExtension(ModuleEnvironment.NAME); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModel.java index bbf1bcc987..a96df0eb43 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModel.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModel.java @@ -243,7 +243,28 @@ public abstract class ScopeModel implements ExtensionAccessor { return Collections.unmodifiableSet(classLoaders); } - public abstract Environment getModelEnvironment(); + /** + * Get current model's environment. + *
+ * Note: This method should not start with `get` or it would be invoked due to Spring boot refresh. + * @see Configuration refresh issue + */ + public abstract Environment modelEnvironment(); + + /** + * Get current model's environment. + * + * @see Configuration refresh issue + * @deprecated use modelEnvironment() instead + */ + @Deprecated + public final Environment getModelEnvironment() { + try { + return modelEnvironment(); + } catch (Exception ex) { + return null; + } + } public String getInternalId() { return this.internalId; diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/config/ConfigurationUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/config/ConfigurationUtilsTest.java index de3bd2df71..16853eb32e 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/config/ConfigurationUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/config/ConfigurationUtilsTest.java @@ -37,7 +37,7 @@ class ConfigurationUtilsTest { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); - Environment originApplicationEnvironment = applicationModel.getModelEnvironment(); + Environment originApplicationEnvironment = applicationModel.modelEnvironment(); Environment applicationEnvironment = Mockito.spy(originApplicationEnvironment); applicationModel.setEnvironment(applicationEnvironment); @@ -52,7 +52,7 @@ class ConfigurationUtilsTest { Assertions.assertEquals("a", ConfigurationUtils.getCachedDynamicProperty(applicationModel, "TestKey", "xxx")); ModuleModel moduleModel = applicationModel.newModule(); - ModuleEnvironment originModuleEnvironment = moduleModel.getModelEnvironment(); + ModuleEnvironment originModuleEnvironment = moduleModel.modelEnvironment(); ModuleEnvironment moduleEnvironment = Mockito.spy(originModuleEnvironment); moduleModel.setModuleEnvironment(moduleEnvironment); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/config/EnvironmentTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/config/EnvironmentTest.java index 5d502fffaa..e0a1204193 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/config/EnvironmentTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/config/EnvironmentTest.java @@ -39,7 +39,7 @@ class EnvironmentTest { @Test void testResolvePlaceholders() { - Environment environment = ApplicationModel.defaultModel().getModelEnvironment(); + Environment environment = ApplicationModel.defaultModel().modelEnvironment(); Map externalMap = new LinkedHashMap<>(); externalMap.put("zookeeper.address", "127.0.0.1"); @@ -65,7 +65,7 @@ class EnvironmentTest { void test() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); - Environment environment = applicationModel.getModelEnvironment(); + Environment environment = applicationModel.modelEnvironment(); // test getPrefixedConfiguration RegistryConfig registryConfig = new RegistryConfig(); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java index 4f8f1474f1..2e2b2a0884 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java @@ -221,7 +221,7 @@ class ExtensionLoaderTest { } @Test - void test_getActivateExtension_WithWrapper() { + void test_getActivateExtension_WithWrapper1() { URL url = URL.valueOf("test://localhost/test"); List list = getExtensionLoader(ActivateExt1.class) .getActivateExtension(url, new String[]{}, "order"); @@ -596,7 +596,7 @@ class ExtensionLoaderTest { } @Test - void testLoadDefaultActivateExtension() { + void testLoadDefaultActivateExtension1() { // test default URL url = URL.valueOf("test://localhost/test?ext=order1,default"); List list = getExtensionLoader(ActivateExt1.class) @@ -620,6 +620,31 @@ class ExtensionLoaderTest { assertSame(list.get(1).getClass(), OrderActivateExtImpl1.class); } + @Test + void testLoadDefaultActivateExtension2() { + // test default + URL url = URL.valueOf("test://localhost/test?ext=order1 , default"); + List list = getExtensionLoader(ActivateExt1.class) + .getActivateExtension(url, "ext", "default_group"); + Assertions.assertEquals(2, list.size()); + assertSame(list.get(0).getClass(), OrderActivateExtImpl1.class); + assertSame(list.get(1).getClass(), ActivateExt1Impl1.class); + + url = URL.valueOf("test://localhost/test?ext=default, order1"); + list = getExtensionLoader(ActivateExt1.class) + .getActivateExtension(url, "ext", "default_group"); + Assertions.assertEquals(2, list.size()); + assertSame(list.get(0).getClass(), ActivateExt1Impl1.class); + assertSame(list.get(1).getClass(), OrderActivateExtImpl1.class); + + url = URL.valueOf("test://localhost/test?ext=order1"); + list = getExtensionLoader(ActivateExt1.class) + .getActivateExtension(url, "ext", "default_group"); + Assertions.assertEquals(2, list.size()); + assertSame(list.get(0).getClass(), ActivateExt1Impl1.class); + assertSame(list.get(1).getClass(), OrderActivateExtImpl1.class); + } + @Test void testInjectExtension() { // register bean for test ScopeBeanExtensionInjector diff --git a/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ModuleModelTest.java b/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ModuleModelTest.java index 2f76c09edb..4bf1b6f748 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ModuleModelTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ModuleModelTest.java @@ -61,7 +61,7 @@ class ModuleModelTest { ApplicationModel applicationModel = frameworkModel.newApplication(); ModuleModel moduleModel = applicationModel.newModule(); - ModuleEnvironment modelEnvironment = moduleModel.getModelEnvironment(); + ModuleEnvironment modelEnvironment = moduleModel.modelEnvironment(); Assertions.assertNotNull(modelEnvironment); frameworkModel.destroy(); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelUtilTest.java b/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelUtilTest.java index dcf0cfba79..2e90314da1 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelUtilTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelUtilTest.java @@ -108,7 +108,7 @@ class ScopeModelUtilTest { } @Override - public Environment getModelEnvironment() { + public Environment modelEnvironment() { return null; } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/Constants.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/Constants.java index f62a9bd177..4ed46e5e23 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/Constants.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/Constants.java @@ -23,21 +23,532 @@ import org.apache.dubbo.common.constants.QosConstants; import org.apache.dubbo.common.constants.RegistryConstants; import org.apache.dubbo.common.constants.RemotingConstants; +import java.util.concurrent.ExecutorService; +import java.util.regex.Pattern; + @Deprecated public class Constants implements CommonConstants, - QosConstants, - FilterConstants, - RegistryConstants, - RemotingConstants, - org.apache.dubbo.config.Constants, - org.apache.dubbo.remoting.Constants, - org.apache.dubbo.rpc.cluster.Constants, - org.apache.dubbo.monitor.Constants, - org.apache.dubbo.rpc.Constants, - org.apache.dubbo.rpc.protocol.dubbo.Constants, - org.apache.dubbo.common.serialize.Constants, - org.apache.dubbo.common.config.configcenter.Constants, - org.apache.dubbo.metadata.report.support.Constants , - org.apache.dubbo.rpc.protocol.rest.Constants, - org.apache.dubbo.registry.Constants { + QosConstants, + FilterConstants, + RegistryConstants, + RemotingConstants, + org.apache.dubbo.config.Constants, + org.apache.dubbo.remoting.Constants, + org.apache.dubbo.rpc.cluster.Constants, + org.apache.dubbo.monitor.Constants, + org.apache.dubbo.rpc.Constants, + org.apache.dubbo.rpc.protocol.dubbo.Constants, + org.apache.dubbo.common.serialize.Constants, + org.apache.dubbo.common.config.configcenter.Constants, + org.apache.dubbo.metadata.report.support.Constants, + org.apache.dubbo.rpc.protocol.rest.Constants, + org.apache.dubbo.registry.Constants { + public static final String PROVIDER = "provider"; + + public static final String CONSUMER = "consumer"; + + public static final String REGISTER = "register"; + + public static final String UNREGISTER = "unregister"; + + public static final String SUBSCRIBE = "subscribe"; + + public static final String UNSUBSCRIBE = "unsubscribe"; + + public static final String CATEGORY_KEY = "category"; + + public static final String PROVIDERS_CATEGORY = "providers"; + + public static final String CONSUMERS_CATEGORY = "consumers"; + + public static final String ROUTERS_CATEGORY = "routers"; + + public static final String CONFIGURATORS_CATEGORY = "configurators"; + + public static final String DEFAULT_CATEGORY = PROVIDERS_CATEGORY; + + public static final String ENABLED_KEY = "enabled"; + + public static final String DISABLED_KEY = "disabled"; + + public static final String VALIDATION_KEY = "validation"; + + public static final String CACHE_KEY = "cache"; + + public static final String DYNAMIC_KEY = "dynamic"; + + public static final String DUBBO_PROPERTIES_KEY = "dubbo.properties.file"; + + public static final String DEFAULT_DUBBO_PROPERTIES = "dubbo.properties"; + + public static final String SENT_KEY = "sent"; + + public static final boolean DEFAULT_SENT = false; + + public static final String REGISTRY_PROTOCOL = "registry"; + + public static final String $INVOKE = "$invoke"; + + public static final String $ECHO = "$echo"; + + public static final int DEFAULT_IO_THREADS = Runtime.getRuntime() + .availableProcessors() + 1; + + public static final String DEFAULT_PROXY = "javassist"; + + public static final int DEFAULT_PAYLOAD = 8 * 1024 * 1024; + + public static final String DEFAULT_CLUSTER = "failover"; + + public static final String DEFAULT_DIRECTORY = "dubbo"; + + public static final String DEFAULT_LOADBALANCE = "random"; + + public static final String DEFAULT_PROTOCOL = "dubbo"; + + public static final String DEFAULT_EXCHANGER = "header"; + + public static final String DEFAULT_TRANSPORTER = "netty"; + + public static final String DEFAULT_REMOTING_SERVER = "netty"; + + public static final String DEFAULT_REMOTING_CLIENT = "netty"; + + public static final String DEFAULT_REMOTING_CODEC = "dubbo"; + + public static final String DEFAULT_REMOTING_SERIALIZATION = "hessian2"; + + public static final String DEFAULT_HTTP_SERVER = "servlet"; + + public static final String DEFAULT_HTTP_CLIENT = "jdk"; + + public static final String DEFAULT_HTTP_SERIALIZATION = "json"; + + public static final String DEFAULT_CHARSET = "UTF-8"; + + public static final int DEFAULT_WEIGHT = 100; + + public static final int DEFAULT_FORKS = 2; + + public static final String DEFAULT_THREAD_NAME = "Dubbo"; + + public static final int DEFAULT_CORE_THREADS = 0; + + public static final int DEFAULT_THREADS = 200; + + public static final int DEFAULT_QUEUES = 0; + + public static final int DEFAULT_ALIVE = 60 * 1000; + + public static final int DEFAULT_CONNECTIONS = 0; + + public static final int DEFAULT_ACCEPTS = 0; + + public static final int DEFAULT_IDLE_TIMEOUT = 600 * 1000; + + public static final int DEFAULT_HEARTBEAT = 60 * 1000; + + public static final int DEFAULT_TIMEOUT = 1000; + + public static final int DEFAULT_CONNECT_TIMEOUT = 3000; + + public static final int DEFAULT_RETRIES = 2; + + public static final int DEFAULT_BUFFER_SIZE = 8 * 1024; + + public static final int MAX_BUFFER_SIZE = 16 * 1024; + + public static final int MIN_BUFFER_SIZE = 1 * 1024; + + public static final String REMOVE_VALUE_PREFIX = "-"; + + public static final String HIDE_KEY_PREFIX = "."; + + public static final String DEFAULT_KEY_PREFIX = "default."; + + public static final String DEFAULT_KEY = "default"; + + public static final String LOADBALANCE_KEY = "loadbalance"; + + public static final String ROUTER_KEY = "router"; + + public static final String CLUSTER_KEY = "cluster"; + + public static final String REGISTRY_KEY = "registry"; + + public static final String MONITOR_KEY = "monitor"; + + public static final String SIDE_KEY = "side"; + + public static final String PROVIDER_SIDE = "provider"; + + public static final String CONSUMER_SIDE = "consumer"; + + public static final String DEFAULT_REGISTRY = "dubbo"; + + public static final String BACKUP_KEY = "backup"; + + public static final String DIRECTORY_KEY = "directory"; + + public static final String DEPRECATED_KEY = "deprecated"; + + public static final String ANYHOST_KEY = "anyhost"; + + public static final String ANYHOST_VALUE = "0.0.0.0"; + + public static final String LOCALHOST_KEY = "localhost"; + + public static final String LOCALHOST_VALUE = "127.0.0.1"; + + public static final String APPLICATION_KEY = "application"; + + public static final String LOCAL_KEY = "local"; + + public static final String STUB_KEY = "stub"; + + public static final String MOCK_KEY = "mock"; + + public static final String PROTOCOL_KEY = "protocol"; + + public static final String PROXY_KEY = "proxy"; + + public static final String WEIGHT_KEY = "weight"; + + public static final String FORKS_KEY = "forks"; + + public static final String DEFAULT_THREADPOOL = "limited"; + + public static final String DEFAULT_CLIENT_THREADPOOL = "cached"; + + public static final String THREADPOOL_KEY = "threadpool"; + + public static final String THREAD_NAME_KEY = "threadname"; + + public static final String IO_THREADS_KEY = "iothreads"; + + public static final String CORE_THREADS_KEY = "corethreads"; + + public static final String THREADS_KEY = "threads"; + + public static final String QUEUES_KEY = "queues"; + + public static final String ALIVE_KEY = "alive"; + + public static final String EXECUTES_KEY = "executes"; + + public static final String BUFFER_KEY = "buffer"; + + public static final String PAYLOAD_KEY = "payload"; + + public static final String REFERENCE_FILTER_KEY = "reference.filter"; + + public static final String INVOKER_LISTENER_KEY = "invoker.listener"; + + public static final String SERVICE_FILTER_KEY = "service.filter"; + + public static final String EXPORTER_LISTENER_KEY = "exporter.listener"; + + public static final String ACCESS_LOG_KEY = "accesslog"; + + public static final String ACTIVES_KEY = "actives"; + + public static final String CONNECTIONS_KEY = "connections"; + + public static final String ACCEPTS_KEY = "accepts"; + + public static final String IDLE_TIMEOUT_KEY = "idle.timeout"; + + public static final String HEARTBEAT_KEY = "heartbeat"; + + public static final String HEARTBEAT_TIMEOUT_KEY = "heartbeat.timeout"; + + public static final String CONNECT_TIMEOUT_KEY = "connect.timeout"; + + public static final String TIMEOUT_KEY = "timeout"; + + public static final String RETRIES_KEY = "retries"; + + public static final String PROMPT_KEY = "prompt"; + + public static final String DEFAULT_PROMPT = "dubbo>"; + + public static final String CODEC_KEY = "codec"; + + public static final String SERIALIZATION_KEY = "serialization"; + + public static final String EXCHANGER_KEY = "exchanger"; + + public static final String TRANSPORTER_KEY = "transporter"; + + public static final String SERVER_KEY = "server"; + + public static final String CLIENT_KEY = "client"; + + public static final String ID_KEY = "id"; + + public static final String ASYNC_KEY = "async"; + + public static final String RETURN_KEY = "return"; + + public static final String TOKEN_KEY = "token"; + + public static final String METHOD_KEY = "method"; + + public static final String METHODS_KEY = "methods"; + + public static final String CHARSET_KEY = "charset"; + + public static final String RECONNECT_KEY = "reconnect"; + + public static final String SEND_RECONNECT_KEY = "send.reconnect"; + + public static final int DEFAULT_RECONNECT_PERIOD = 2000; + + public static final String SHUTDOWN_TIMEOUT_KEY = "shutdown.timeout"; + + public static final int DEFAULT_SHUTDOWN_TIMEOUT = 1000 * 60 * 15; + + public static final String PID_KEY = "pid"; + + public static final String TIMESTAMP_KEY = "timestamp"; + + public static final String WARMUP_KEY = "warmup"; + + public static final int DEFAULT_WARMUP = 10 * 60 * 1000; + + public static final String CHECK_KEY = "check"; + + public static final String REGISTER_KEY = "register"; + + public static final String SUBSCRIBE_KEY = "subscribe"; + + public static final String GROUP_KEY = "group"; + + public static final String PATH_KEY = "path"; + + public static final String INTERFACE_KEY = "interface"; + + public static final String GENERIC_KEY = "generic"; + + public static final String FILE_KEY = "file"; + + public static final String WAIT_KEY = "wait"; + + public static final String CLASSIFIER_KEY = "classifier"; + + public static final String VERSION_KEY = "version"; + + public static final String REVISION_KEY = "revision"; + + public static final String DUBBO_VERSION_KEY = "dubbo"; + + public static final String HESSIAN_VERSION_KEY = "hessian.version"; + + public static final String DISPATCHER_KEY = "dispatcher"; + + public static final String CHANNEL_HANDLER_KEY = "channel.handler"; + + public static final String DEFAULT_CHANNEL_HANDLER = "default"; + + public static final String ANY_VALUE = "*"; + + public static final String COMMA_SEPARATOR = ","; + + public static final Pattern COMMA_SPLIT_PATTERN = Pattern + .compile("\\s*[,]+\\s*"); + + public final static String PATH_SEPARATOR = "/"; + + public static final String REGISTRY_SEPARATOR = "|"; + + public static final Pattern REGISTRY_SPLIT_PATTERN = Pattern + .compile("\\s*[|;]+\\s*"); + + public static final String SEMICOLON_SEPARATOR = ";"; + + public static final Pattern SEMICOLON_SPLIT_PATTERN = Pattern + .compile("\\s*[;]+\\s*"); + + public static final String CONNECT_QUEUE_CAPACITY = "connect.queue.capacity"; + + public static final String CONNECT_QUEUE_WARNING_SIZE = "connect.queue.warning.size"; + + public static final int DEFAULT_CONNECT_QUEUE_WARNING_SIZE = 1000; + + public static final String CHANNEL_ATTRIBUTE_READONLY_KEY = "channel.readonly"; + + public static final String CHANNEL_READONLYEVENT_SENT_KEY = "channel.readonly.sent"; + + public static final String CHANNEL_SEND_READONLYEVENT_KEY = "channel.readonly.send"; + + public static final String COUNT_PROTOCOL = "count"; + + public static final String TRACE_PROTOCOL = "trace"; + + public static final String EMPTY_PROTOCOL = "empty"; + + public static final String ADMIN_PROTOCOL = "admin"; + + public static final String PROVIDER_PROTOCOL = "provider"; + + public static final String CONSUMER_PROTOCOL = "consumer"; + + public static final String ROUTE_PROTOCOL = "route"; + + public static final String SCRIPT_PROTOCOL = "script"; + + public static final String CONDITION_PROTOCOL = "condition"; + + public static final String MOCK_PROTOCOL = "mock"; + + public static final String RETURN_PREFIX = "return "; + + public static final String THROW_PREFIX = "throw"; + + public static final String FAIL_PREFIX = "fail:"; + + public static final String FORCE_PREFIX = "force:"; + + public static final String FORCE_KEY = "force"; + + public static final String MERGER_KEY = "merger"; + + public static final String CLUSTER_AVAILABLE_CHECK_KEY = "cluster.availablecheck"; + + public static final boolean DEFAULT_CLUSTER_AVAILABLE_CHECK = true; + + public static final String CLUSTER_STICKY_KEY = "sticky"; + + public static final boolean DEFAULT_CLUSTER_STICKY = false; + + public static final String LAZY_CONNECT_KEY = "lazy"; + + public static final String LAZY_CONNECT_INITIAL_STATE_KEY = "connect.lazy.initial.state"; + + public static final boolean DEFAULT_LAZY_CONNECT_INITIAL_STATE = true; + + public static final String REGISTRY_FILESAVE_SYNC_KEY = "save.file"; + + public static final String REGISTRY_RETRY_PERIOD_KEY = "retry.period"; + + public static final int DEFAULT_REGISTRY_RETRY_PERIOD = 5 * 1000; + + public static final String REGISTRY_RECONNECT_PERIOD_KEY = "reconnect.period"; + + public static final int DEFAULT_REGISTRY_RECONNECT_PERIOD = 3 * 1000; + + public static final String SESSION_TIMEOUT_KEY = "session"; + + public static final int DEFAULT_SESSION_TIMEOUT = 60 * 1000; + + public static final String EXPORT_KEY = "export"; + + public static final String REFER_KEY = "refer"; + + public static final String CALLBACK_SERVICE_KEY = "callback.service.instid"; + + public static final String CALLBACK_INSTANCES_LIMIT_KEY = "callbacks"; + + public static final int DEFAULT_CALLBACK_INSTANCES = 1; + + public static final String CALLBACK_SERVICE_PROXY_KEY = "callback.service.proxy"; + + public static final String IS_CALLBACK_SERVICE = "is_callback_service"; + + public static final String CHANNEL_CALLBACK_KEY = "channel.callback.invokers.key"; + + @Deprecated + public static final String SHUTDOWN_WAIT_SECONDS_KEY = "dubbo.service.shutdown.wait.seconds"; + + public static final String SHUTDOWN_WAIT_KEY = "dubbo.service.shutdown.wait"; + + public static final String IS_SERVER_KEY = "isserver"; + + public static final int DEFAULT_SERVER_SHUTDOWN_TIMEOUT = 10000; + + public static final String ON_CONNECT_KEY = "onconnect"; + + public static final String ON_DISCONNECT_KEY = "ondisconnect"; + + public static final String ON_INVOKE_METHOD_KEY = "oninvoke.method"; + + public static final String ON_RETURN_METHOD_KEY = "onreturn.method"; + + public static final String ON_THROW_METHOD_KEY = "onthrow.method"; + + public static final String ON_INVOKE_INSTANCE_KEY = "oninvoke.instance"; + + public static final String ON_RETURN_INSTANCE_KEY = "onreturn.instance"; + + public static final String ON_THROW_INSTANCE_KEY = "onthrow.instance"; + + public static final String OVERRIDE_PROTOCOL = "override"; + + public static final String PRIORITY_KEY = "priority"; + + public static final String RULE_KEY = "rule"; + + public static final String TYPE_KEY = "type"; + + public static final String RUNTIME_KEY = "runtime"; + + public static final String ROUTER_TYPE_CLEAR = "clean"; + + public static final String DEFAULT_SCRIPT_TYPE_KEY = "javascript"; + + public static final String STUB_EVENT_KEY = "dubbo.stub.event"; + + public static final boolean DEFAULT_STUB_EVENT = false; + + public static final String STUB_EVENT_METHODS_KEY = "dubbo.stub.event.methods"; + + public static final String INVOCATION_NEED_MOCK = "invocation.need.mock"; + + public static final String LOCAL_PROTOCOL = "injvm"; + + public static final String AUTO_ATTACH_INVOCATIONID_KEY = "invocationid.autoattach"; + + public static final String SCOPE_KEY = "scope"; + + public static final String SCOPE_LOCAL = "local"; + + public static final String SCOPE_REMOTE = "remote"; + + public static final String SCOPE_NONE = "none"; + + public static final String RELIABLE_PROTOCOL = "napoli"; + + public static final String TPS_LIMIT_RATE_KEY = "tps"; + + public static final String TPS_LIMIT_INTERVAL_KEY = "tps.interval"; + + public static final long DEFAULT_TPS_LIMIT_INTERVAL = 60 * 1000; + + public static final String DECODE_IN_IO_THREAD_KEY = "decode.in.io"; + + public static final boolean DEFAULT_DECODE_IN_IO_THREAD = true; + + public static final String INPUT_KEY = "input"; + + public static final String OUTPUT_KEY = "output"; + + public static final String EXECUTOR_SERVICE_COMPONENT_KEY = ExecutorService.class.getName(); + + public static final String GENERIC_SERIALIZATION_NATIVE_JAVA = "nativejava"; + + public static final String GENERIC_SERIALIZATION_DEFAULT = "true"; + + public static final String INVOKER_CONNECTED_KEY = "connected"; + + public static final String INVOKER_INSIDE_INVOKERS_KEY = "inside.invokers"; + + public static final String INVOKER_INSIDE_INVOKER_COUNT_KEY = "inside.invoker.count"; + + public static final String CLUSTER_SWITCH_FACTOR = "cluster.switch.factor"; + + public static final String CLUSTER_SWITCH_LOG_ERROR = "cluster.switch.log.error"; + + public static final double DEFAULT_CLUSTER_SWITCH_FACTOR = 2; + + public static final String DISPATHER_KEY = "dispather"; } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java index 2eda40f495..85e5cfcfe5 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java @@ -17,14 +17,15 @@ package com.alibaba.dubbo.rpc; +import org.apache.dubbo.rpc.model.ServiceModel; + +import java.beans.Transient; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; -import org.apache.dubbo.rpc.model.ServiceModel; - @Deprecated public interface Invocation extends org.apache.dubbo.rpc.Invocation { @@ -184,6 +185,7 @@ public interface Invocation extends org.apache.dubbo.rpc.Invocation { } @Override + @Transient public Invoker getInvoker() { return new Invoker.CompatibleInvoker(delegate.getInvoker()); } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java index 4c49bc1793..cfc5fb4b8b 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java @@ -37,6 +37,7 @@ import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; @Deprecated public class RpcContext { @@ -320,6 +321,25 @@ public class RpcContext { return isConsumerSide(); } + @Deprecated + public Invoker getInvoker() { + org.apache.dubbo.rpc.Invoker invoker = newRpcContext.getInvoker(); + if (invoker == null) { + return null; + } + return new Invoker.CompatibleInvoker<>(invoker); + } + + @Deprecated + public List> getInvokers() { + List> invokers = newRpcContext.getInvokers(); + if (CollectionUtils.isEmpty(invokers)) { + return Collections.emptyList(); + } + return invokers.stream() + .map(Invoker.CompatibleInvoker::new) + .collect(Collectors.toList()); + } /** * Async invocation. Timeout will be handled even if Future.get() is not called. * diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcException.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcException.java index 07923c6ee5..1e994019ac 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcException.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcException.java @@ -19,7 +19,7 @@ package com.alibaba.dubbo.rpc; @Deprecated public class RpcException extends org.apache.dubbo.rpc.RpcException { - + public RpcException() { super(); } @@ -51,4 +51,8 @@ public class RpcException extends org.apache.dubbo.rpc.RpcException { public RpcException(int code, Throwable cause) { super(code, cause); } + + public boolean isForbidded() { + return isForbidden(); + } } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java index 9035294927..d1cf40600d 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java @@ -17,6 +17,10 @@ package com.alibaba.dubbo.rpc; +import com.alibaba.dubbo.common.Constants; +import com.alibaba.dubbo.common.URL; + +import java.beans.Transient; import java.io.Serializable; import java.lang.reflect.Method; import java.util.Arrays; @@ -24,9 +28,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.common.URL; - public class RpcInvocation implements Invocation, Serializable { private static final long serialVersionUID = -4355285085441097045L; @@ -101,6 +102,7 @@ public class RpcInvocation implements Invocation, Serializable { this.invoker = invoker; } + @Transient public Invoker getInvoker() { return invoker; } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java index a8a39062ad..98f9aa78fd 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java @@ -17,6 +17,8 @@ package com.alibaba.dubbo.rpc.cluster.loadbalance; +import org.apache.dubbo.rpc.support.RpcUtils; + import com.alibaba.dubbo.common.Constants; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; @@ -40,7 +42,7 @@ public abstract class AbstractLoadBalance implements LoadBalance { protected abstract Invoker doSelect(List> invokers, URL url, Invocation invocation); protected int getWeight(Invoker invoker, Invocation invocation) { - int weight = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT); + int weight = invoker.getUrl().getMethodParameter(RpcUtils.getMethodName(invocation), Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT); if (weight > 0) { long timestamp = invoker.getUrl().getParameter(Constants.TIMESTAMP_KEY, 0L); if (timestamp > 0L) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index 50bf549a20..e8da1c28d4 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -57,7 +57,7 @@ import org.apache.dubbo.rpc.support.ProtocolUtils; import java.beans.Transient; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; +import java.util.TreeSet; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -409,9 +409,7 @@ public class ReferenceConfig extends ReferenceConfigBase { logger.warn(CONFIG_NO_METHOD_FOUND, "", "", "No method found in service interface: " + interfaceClass.getName()); map.put(METHODS_KEY, ANY_VALUE); } else { - List copyOfMethods = new ArrayList<>(Arrays.asList(methods)); - copyOfMethods.sort(Comparator.naturalOrder()); - map.put(METHODS_KEY, String.join(COMMA_SEPARATOR, copyOfMethods)); + map.put(METHODS_KEY, StringUtils.join(new TreeSet<>(Arrays.asList(methods)), COMMA_SEPARATOR)); } } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index 7fad3c8359..b22b0d2ab3 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -57,10 +57,10 @@ import java.beans.Transient; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TreeSet; import java.util.UUID; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -99,6 +99,7 @@ import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_BIND; import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_REGISTRY; import static org.apache.dubbo.config.Constants.SCOPE_NONE; import static org.apache.dubbo.registry.Constants.REGISTER_KEY; +import static org.apache.dubbo.registry.Constants.REGISTER_ORIGIN_KEY; import static org.apache.dubbo.remoting.Constants.BIND_IP_KEY; import static org.apache.dubbo.remoting.Constants.BIND_PORT_KEY; import static org.apache.dubbo.remoting.Constants.IS_PU_SERVER_KEY; @@ -310,7 +311,7 @@ public class ServiceConfig extends ServiceConfigBase { } @Override - public void register() { + public void register(boolean onlyDefault) { if (!this.exported) { return; } @@ -321,7 +322,9 @@ public class ServiceConfig extends ServiceConfigBase { } for (Exporter exporter : exporters) { - exporter.register(); + if (!onlyDefault || exporter.getInvoker().getUrl().getParameter(REGISTER_ORIGIN_KEY, true)) { + exporter.register(); + } } } } @@ -584,9 +587,7 @@ public class ServiceConfig extends ServiceConfigBase { logger.warn(CONFIG_NO_METHOD_FOUND, "", "", "No method found in service interface: " + interfaceClass.getName()); map.put(METHODS_KEY, ANY_VALUE); } else { - List copyOfMethods = new ArrayList<>(Arrays.asList(methods)); - copyOfMethods.sort(Comparator.naturalOrder()); - map.put(METHODS_KEY, String.join(COMMA_SEPARATOR, copyOfMethods)); + map.put(METHODS_KEY, StringUtils.join(new TreeSet<>(Arrays.asList(methods)), COMMA_SEPARATOR)); } } @@ -815,6 +816,7 @@ public class ServiceConfig extends ServiceConfigBase { @SuppressWarnings({"unchecked", "rawtypes"}) private void doExportUrl(URL url, boolean withMetaData, boolean register) { if (!register) { + url = url.addParameter(REGISTER_ORIGIN_KEY, url.getParameter(REGISTER_KEY, true)); url = url.addParameter(REGISTER_KEY, false); } Invoker invoker = proxyFactory.getInvoker(ref, (Class) interfaceClass, url); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java index 2002ec0cb0..bfb2278fb6 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java @@ -162,7 +162,7 @@ public final class DubboBootstrap { private DubboBootstrap(ApplicationModel applicationModel) { this.applicationModel = applicationModel; configManager = applicationModel.getApplicationConfigManager(); - environment = applicationModel.getModelEnvironment(); + environment = applicationModel.modelEnvironment(); executorRepository = ExecutorRepository.getInstance(applicationModel); applicationDeployer = applicationModel.getDeployer(); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/builders/InternalServiceConfigBuilder.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/builders/InternalServiceConfigBuilder.java index 6e37707f28..5a2dbdbaf6 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/builders/InternalServiceConfigBuilder.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/builders/InternalServiceConfigBuilder.java @@ -275,6 +275,7 @@ public class InternalServiceConfigBuilder { serviceConfig.setRef(this.ref); serviceConfig.setGroup(applicationConfig.getName()); serviceConfig.setVersion("1.0.0"); + serviceConfig.setFilter("-default"); serviceConfig.setExecutor(executor); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java index bf8d285681..ac012ee3d5 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java @@ -143,7 +143,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer impleme if (!sc.isExported()) { return; } - sc.register(); + sc.register(true); } private void unexportServices() { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java index ef5469b64a..4e9c20d415 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java @@ -475,7 +475,7 @@ public class ConfigValidationUtils { // backward compatibility ScopeModel scopeModel = ScopeModelUtil.getOrDefaultApplicationModel(config.getScopeModel()); - PropertiesConfiguration configuration = scopeModel.getModelEnvironment().getPropertiesConfiguration(); + PropertiesConfiguration configuration = scopeModel.modelEnvironment().getPropertiesConfiguration(); String wait = configuration.getProperty(SHUTDOWN_WAIT_KEY); if (wait != null && wait.trim().length() > 0) { System.setProperty(SHUTDOWN_WAIT_KEY, wait.trim()); @@ -670,8 +670,9 @@ public class ConfigValidationUtils { if (isNotEmpty(value)) { String[] values = value.split("\\s*[,]+\\s*"); for (String v : values) { + v = StringUtils.trim(v); if (v.startsWith(REMOVE_VALUE_PREFIX)) { - v = v.substring(1); + continue; } if (DEFAULT_KEY.equals(v)) { continue; diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java index 02e93d69b2..1a986a5884 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java @@ -207,8 +207,25 @@ class AbstractConfigTest { @Test void checkMultiExtension2() { + try { + ConfigValidationUtils.checkMultiExtension(ApplicationModel.defaultModel(), Greeting.class, "hello", "default,-world"); + } catch (Throwable t) { + Assertions.fail(t); + } + } + @Test + void checkMultiExtension3() { Assertions.assertThrows(IllegalStateException.class, - () -> ConfigValidationUtils.checkMultiExtension(ApplicationModel.defaultModel(), Greeting.class, "hello", "default,-world")); + () -> ConfigValidationUtils.checkMultiExtension(ApplicationModel.defaultModel(), Greeting.class, "hello", "default , world")); + } + + @Test + void checkMultiExtension4() { + try { + ConfigValidationUtils.checkMultiExtension(ApplicationModel.defaultModel(), Greeting.class, "hello", "default , -world "); + } catch (Throwable t) { + Assertions.fail(t); + } } @Test @@ -335,8 +352,8 @@ class AbstractConfigTest { external.put("dubbo.override.key", "external"); // @Parameter(key="key2", useKeyAsProperty=true) external.put("dubbo.override.key2", "external"); - ApplicationModel.defaultModel().getModelEnvironment().initialize(); - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(external); + ApplicationModel.defaultModel().modelEnvironment().initialize(); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(external); SysProps.setProperty("dubbo.override.address", "system://127.0.0.1:2181"); SysProps.setProperty("dubbo.override.protocol", "system"); @@ -353,7 +370,7 @@ class AbstractConfigTest { Assertions.assertEquals("external", overrideConfig.getKey()); Assertions.assertEquals("system", overrideConfig.getKey2()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -377,14 +394,14 @@ class AbstractConfigTest { Assertions.assertEquals("override-config://", overrideConfig.getEscape()); Assertions.assertEquals("system", overrideConfig.getKey()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @Test void testRefreshProperties() throws Exception { try { - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(new HashMap<>()); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(new HashMap<>()); OverrideConfig overrideConfig = new OverrideConfig(); overrideConfig.setAddress("override-config://127.0.0.1:2181"); overrideConfig.setProtocol("override-config"); @@ -392,7 +409,7 @@ class AbstractConfigTest { Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/dubbo.properties")); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperties(properties); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperties(properties); overrideConfig.refresh(); @@ -402,7 +419,7 @@ class AbstractConfigTest { Assertions.assertEquals("properties", overrideConfig.getKey2()); //Assertions.assertEquals("properties", overrideConfig.getUseKeyAsProperty()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -425,8 +442,8 @@ class AbstractConfigTest { external.put("dubbo.override.key", "external"); // @Parameter(key="key2", useKeyAsProperty=true) external.put("dubbo.override.key2", "external"); - ApplicationModel.defaultModel().getModelEnvironment().initialize(); - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(external); + ApplicationModel.defaultModel().modelEnvironment().initialize(); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(external); overrideConfig.refresh(); @@ -437,7 +454,7 @@ class AbstractConfigTest { Assertions.assertEquals("external", overrideConfig.getKey()); Assertions.assertEquals("external", overrideConfig.getKey2()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -457,8 +474,8 @@ class AbstractConfigTest { external.put("dubbo.overrides.override-id.key2", "external"); external.put("dubbo.override.address", "external://127.0.0.1:2181"); external.put("dubbo.override.exclude", "external"); - ApplicationModel.defaultModel().getModelEnvironment().initialize(); - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(external); + ApplicationModel.defaultModel().modelEnvironment().initialize(); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(external); // refresh config overrideConfig.refresh(); @@ -469,7 +486,7 @@ class AbstractConfigTest { Assertions.assertEquals("external", overrideConfig.getKey()); Assertions.assertEquals("external", overrideConfig.getKey2()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -485,8 +502,8 @@ class AbstractConfigTest { Map external = new HashMap<>(); external.put("dubbo.override.parameters", "[{key3:value3},{key4:value4},{key2:value5}]"); - ApplicationModel.defaultModel().getModelEnvironment().initialize(); - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(external); + ApplicationModel.defaultModel().modelEnvironment().initialize(); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(external); // refresh config overrideConfig.refresh(); @@ -502,7 +519,7 @@ class AbstractConfigTest { Assertions.assertEquals("value6", overrideConfig.getParameters().get("key3")); Assertions.assertEquals("value4", overrideConfig.getParameters().get("key4")); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -514,7 +531,7 @@ class AbstractConfigTest { overrideConfig.refresh(); assertEquals("value00", overrideConfig.getParameters().get("key00")); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -587,14 +604,14 @@ class AbstractConfigTest { external.put("notConflictKey", "value-from-external"); external.put("dubbo.override.notConflictKey2", "value-from-external"); - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(external); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(external); overrideConfig.refresh(); Assertions.assertEquals("value-from-config", overrideConfig.getNotConflictKey()); Assertions.assertEquals("value-from-external", overrideConfig.getNotConflictKey2()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -1021,8 +1038,8 @@ class AbstractConfigTest { external.put("dubbo.outer.a1", "1"); external.put("dubbo.outer.b.b1", "11"); external.put("dubbo.outer.b.b2", "12"); - ApplicationModel.defaultModel().getModelEnvironment().initialize(); - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(external); + ApplicationModel.defaultModel().modelEnvironment().initialize(); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(external); // refresh config outerConfig.refresh(); @@ -1031,7 +1048,7 @@ class AbstractConfigTest { Assertions.assertEquals(11, outerConfig.getB().getB1()); Assertions.assertEquals(12, outerConfig.getB().getB2()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java index 961feee93b..0af13133ca 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java @@ -160,8 +160,8 @@ class ConfigCenterConfigTest { ApplicationModel.defaultModel().getDefaultModule(); // Config instance has id, dubbo props has no id - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-center.check", "false"); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-center.timeout", "1234"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-center.check", "false"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-center.timeout", "1234"); try { // Config instance has id @@ -179,7 +179,7 @@ class ConfigCenterConfigTest { Assertions.assertEquals(3000L, configCenter.getTimeout()); Assertions.assertEquals(false, configCenter.isCheck()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().refresh(); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().refresh(); DubboBootstrap.getInstance().stop(); } } @@ -215,8 +215,8 @@ class ConfigCenterConfigTest { ApplicationModel.defaultModel().getDefaultModule(); // Config instance has id, dubbo props has id - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-centers.configcenterA.check", "false"); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-centers.configcenterA.timeout", "1234"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-centers.configcenterA.check", "false"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-centers.configcenterA.timeout", "1234"); try { // Config instance has id @@ -235,7 +235,7 @@ class ConfigCenterConfigTest { Assertions.assertEquals(3000L, configCenter.getTimeout()); Assertions.assertEquals(false, configCenter.isCheck()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().refresh(); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().refresh(); DubboBootstrap.getInstance().stop(); } } @@ -294,4 +294,4 @@ class ConfigCenterConfigTest { Assertions.assertEquals("pass123", cc.getPassword()); } -} \ No newline at end of file +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java index 7f2283e47d..1a303ced7b 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java @@ -187,9 +187,9 @@ class ConsumerConfigTest { @Test void testOverrideConfigByDubboProps() { ApplicationModel.defaultModel().getDefaultModule(); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.consumers.consumerA.check", "false"); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.consumers.consumerA.group", "demo"); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.consumers.consumerA.threads", "10"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.consumers.consumerA.check", "false"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.consumers.consumerA.group", "demo"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.consumers.consumerA.threads", "10"); try { ConsumerConfig consumerConfig = new ConsumerConfig(); @@ -208,7 +208,7 @@ class ConsumerConfigTest { Assertions.assertEquals("groupA", consumerConfig.getGroup()); Assertions.assertEquals(10, consumerConfig.getThreads()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().refresh(); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().refresh(); DubboBootstrap.getInstance().destroy(); } } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java index d65f110843..fe5a0ad643 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java @@ -683,4 +683,20 @@ class ServiceConfigTest { scheduledExecutorService.shutdown(); } + + @Test + void testToString() { + ServiceConfig serviceConfig = new ServiceConfig<>(); + service.setRef(new DemoServiceImpl() { + @Override + public String toString() { + throw new IllegalStateException(); + } + }); + try { + serviceConfig.toString(); + } catch (Throwable t) { + Assertions.fail(t); + } + } } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java index f65b14d0ba..2852bf55d4 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java @@ -115,13 +115,13 @@ class DubboBootstrapTest { System.clearProperty(SHUTDOWN_WAIT_SECONDS_KEY); writeDubboProperties(SHUTDOWN_WAIT_KEY, "100"); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().refresh(); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().refresh(); ConfigValidationUtils.validateApplicationConfig(new ApplicationConfig("demo")); Assertions.assertEquals("100", System.getProperty(SHUTDOWN_WAIT_KEY)); System.clearProperty(SHUTDOWN_WAIT_KEY); writeDubboProperties(SHUTDOWN_WAIT_SECONDS_KEY, "1000"); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().refresh(); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().refresh(); ConfigValidationUtils.validateApplicationConfig(new ApplicationConfig("demo")); Assertions.assertEquals("1000", System.getProperty(SHUTDOWN_WAIT_SECONDS_KEY)); } finally { @@ -369,4 +369,4 @@ class DubboBootstrapTest { } -} \ No newline at end of file +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployerTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployerTest.java index fab3cf577b..434fb55f17 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployerTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployerTest.java @@ -19,9 +19,8 @@ package org.apache.dubbo.config.deploy; import org.apache.dubbo.common.utils.Assert; import org.apache.dubbo.rpc.model.ApplicationModel; -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; class DefaultApplicationDeployerTest { diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterExporterListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterExporterListener.java index 74e1e69592..b62c15f4b6 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterExporterListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterExporterListener.java @@ -19,6 +19,7 @@ package org.apache.dubbo.config.integration; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.ExporterListener; import org.apache.dubbo.rpc.Filter; +import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder; import org.apache.dubbo.rpc.listener.ListenerExporterWrapper; @@ -56,7 +57,13 @@ public abstract class AbstractRegistryCenterExporterListener implements Exporter @Override public void exported(Exporter exporter) throws RpcException { ListenerExporterWrapper listenerExporterWrapper = (ListenerExporterWrapper) exporter; - FilterChainBuilder.CallbackRegistrationInvoker callbackRegistrationInvoker = (FilterChainBuilder.CallbackRegistrationInvoker) listenerExporterWrapper.getInvoker(); + + Invoker invoker = listenerExporterWrapper.getInvoker(); + if (!(invoker instanceof FilterChainBuilder.CallbackRegistrationInvoker)) { + exportedExporters.add(exporter); + return; + } + FilterChainBuilder.CallbackRegistrationInvoker callbackRegistrationInvoker = (FilterChainBuilder.CallbackRegistrationInvoker) invoker; if (callbackRegistrationInvoker == null || callbackRegistrationInvoker.getInterface() != getInterface()) { return; diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java index 7ed2e63358..d2f9b7ee2d 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java @@ -188,7 +188,7 @@ class MultipleRegistryCenterExportProviderIntegrationTest implements Integration // 1. InjvmExporter // 2. DubboExporter with service-discovery-registry protocol // 3. DubboExporter with registry protocol - Assertions.assertEquals(exporterListener.getExportedExporters().size(), 5); + Assertions.assertEquals(exporterListener.getExportedExporters().size(), 4); // The exported exporter contains MultipleRegistryCenterExportProviderFilter Assertions.assertTrue(exporterListener.getFilters().contains(filter)); diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java index 3f5df17128..227eaf2718 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java @@ -156,7 +156,7 @@ class MultipleRegistryCenterInjvmIntegrationTest implements IntegrationTest { // The MultipleRegistryCenterInjvmService is exported Assertions.assertTrue(serviceListener.getExportedServices().get(0).isExported()); // The exported exporter is only one - Assertions.assertEquals(exporterListener.getExportedExporters().size(), 1); + Assertions.assertEquals(exporterListener.getExportedExporters().size(), 3); // The exported exporter contains MultipleRegistryCenterInjvmFilter Assertions.assertTrue(exporterListener.getFilters().contains(filter)); } @@ -189,4 +189,4 @@ class MultipleRegistryCenterInjvmIntegrationTest implements IntegrationTest { serviceListener = null; logger.info(getClass().getSimpleName() + " testcase is ending..."); } -} \ No newline at end of file +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java index 50dca60a21..41de19efcb 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java @@ -195,7 +195,7 @@ class SingleRegistryCenterExportProviderIntegrationTest implements IntegrationTe // 1. InjvmExporter // 2. DubboExporter with service-discovery-registry protocol // 3. DubboExporter with registry protocol - Assertions.assertEquals(exporterListener.getExportedExporters().size(), 3); + Assertions.assertEquals(exporterListener.getExportedExporters().size(), 4); // The exported exporter contains SingleRegistryCenterExportProviderFilter Assertions.assertTrue(exporterListener.getFilters().contains(filter)); // The consumer can be notified and get provider's metadata through metadata mapping info. @@ -244,4 +244,4 @@ class SingleRegistryCenterExportProviderIntegrationTest implements IntegrationTe logger.info(getClass().getSimpleName() + " testcase is ending..."); registryProtocolListener = null; } -} \ No newline at end of file +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java index 62b72e80f3..b313d4461a 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java @@ -156,7 +156,7 @@ class SingleRegistryCenterInjvmIntegrationTest implements IntegrationTest { // The SingleRegistryCenterInjvmService is exported Assertions.assertTrue(serviceListener.getExportedServices().get(0).isExported()); // The exported exporter is only one - Assertions.assertEquals(exporterListener.getExportedExporters().size(), 1); + Assertions.assertEquals(exporterListener.getExportedExporters().size(), 3); // The exported exporter contains SingleRegistryCenterInjvmFilter Assertions.assertTrue(exporterListener.getFilters().contains(filter)); } @@ -188,4 +188,4 @@ class SingleRegistryCenterInjvmIntegrationTest implements IntegrationTest { serviceListener = null; logger.info(getClass().getSimpleName() + " testcase is ending..."); } -} \ No newline at end of file +} diff --git a/dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/pom.xml b/dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/pom.xml index e86b1e5e49..ef128333bd 100644 --- a/dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/pom.xml +++ b/dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/pom.xml @@ -224,7 +224,7 @@ org.graalvm.buildtools native-maven-plugin - 0.9.22 + 0.9.23 ${project.build.outputDirectory} diff --git a/dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/pom.xml b/dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/pom.xml index 3649d381e2..1f2fc06b5b 100644 --- a/dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/pom.xml +++ b/dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/pom.xml @@ -222,7 +222,7 @@ org.graalvm.buildtools native-maven-plugin - 0.9.22 + 0.9.23 ${project.build.outputDirectory} diff --git a/dubbo-demo/dubbo-demo-spring-boot/pom.xml b/dubbo-demo/dubbo-demo-spring-boot/pom.xml index 230e3fc196..6a5f84e772 100644 --- a/dubbo-demo/dubbo-demo-spring-boot/pom.xml +++ b/dubbo-demo/dubbo-demo-spring-boot/pom.xml @@ -38,7 +38,7 @@ true 2.7.12 2.7.12 - 1.11.0 + 1.11.1 diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index 8f9bf8f84b..da1b69c894 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -114,7 +114,7 @@ 3.5.5 0.18.1 4.0.66 - 3.23.2 + 3.23.3 1.3.2 3.1.0 9.4.51.v20230217 @@ -133,13 +133,13 @@ 3.12.0 1.8.0 0.1.35 - 1.11.0 + 1.11.1 - 1.1.1 + 1.1.2 3.3 0.16.0 1.0.4 - 3.5.6 + 3.5.7 2.2.21 3.14.9 @@ -149,7 +149,7 @@ 8.5.87 0.7.5 2.2.3 - 1.55.1 + 1.56.0 0.8.1 1.2.2 @@ -167,7 +167,7 @@ 1.10.18 - 6.7.1 + 6.6.2 1.0.11 @@ -179,7 +179,7 @@ 3.2.13 1.6.11 - 1.1.10.0 + 1.1.10.1 1.70 2.0.6 5.4.3 diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/RtStatComposite.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/RtStatComposite.java index a6e7a681d2..c440a35b77 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/RtStatComposite.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/RtStatComposite.java @@ -30,6 +30,7 @@ import org.apache.dubbo.metrics.model.sample.MetricSample; import org.apache.dubbo.metrics.report.AbstractMetricsExport; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.ArrayList; import java.util.Arrays; @@ -94,7 +95,7 @@ public class RtStatComposite extends AbstractMetricsExport { public void calcMethodKeyRt(Invocation invocation, String registryOpType, Long responseTime) { for (LongContainer container : rtStats.stream().filter(longContainer -> longContainer.specifyType(registryOpType)).collect(Collectors.toList())) { - Number current = (Number) ConcurrentHashMapUtils.computeIfAbsent(container, invocation.getTargetServiceUniqueName() + "_" + invocation.getMethodName(), container.getInitFunc()); + Number current = (Number) ConcurrentHashMapUtils.computeIfAbsent(container, invocation.getTargetServiceUniqueName() + "_" + RpcUtils.getMethodName(invocation), container.getInitFunc()); container.getConsumerFunc().accept(responseTime, current); } } diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MethodMetric.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MethodMetric.java index 1985dae228..d3f47a7d8a 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MethodMetric.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MethodMetric.java @@ -20,6 +20,7 @@ package org.apache.dubbo.metrics.model; import org.apache.dubbo.metrics.model.sample.MetricSample; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.Map; import java.util.Objects; @@ -40,7 +41,7 @@ public class MethodMetric extends ServiceKeyMetric { public MethodMetric(ApplicationModel applicationModel, Invocation invocation) { super(applicationModel, MetricsSupport.getInterfaceName(invocation)); - this.methodName = MetricsSupport.getMethodName(invocation); + this.methodName = RpcUtils.getMethodName(invocation); this.side = MetricsSupport.getSide(invocation); this.group = MetricsSupport.getGroup(invocation); this.version = MetricsSupport.getVersion(invocation); diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsSupport.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsSupport.java index a8f26efd13..b444f7a4a7 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsSupport.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsSupport.java @@ -30,7 +30,6 @@ import org.apache.dubbo.metrics.model.key.MetricsPlaceValue; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; -import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.model.ApplicationModel; import java.util.HashMap; @@ -55,7 +54,6 @@ import static org.apache.dubbo.common.utils.NetUtils.getLocalHostName; import static org.apache.dubbo.metrics.MetricsConstants.ATTACHMENT_KEY_SERVICE; import static org.apache.dubbo.metrics.MetricsConstants.INVOCATION; import static org.apache.dubbo.metrics.MetricsConstants.SELF_INCREMENT_SIZE; -import static org.apache.dubbo.rpc.support.RpcUtils.isGenericCall; public class MetricsSupport { @@ -159,17 +157,6 @@ public class MetricsSupport { return ivArr[0]; } - public static String getMethodName(Invocation invocation) { - String methodName = invocation.getMethodName(); - if (invocation instanceof RpcInvocation - && isGenericCall(((RpcInvocation) invocation).getParameterTypesDesc(), methodName) - && invocation.getArguments() != null - && invocation.getArguments().length == 3) { - methodName = ((String) invocation.getArguments()[0]).trim(); - } - return methodName; - } - public static String getGroup(Invocation invocation) { String serviceUniqueName = invocation.getTargetServiceUniqueName(); String group = null; diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/AbstractDefaultDubboObservationConvention.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/AbstractDefaultDubboObservationConvention.java index 8d8e963868..410af9d674 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/AbstractDefaultDubboObservationConvention.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/AbstractDefaultDubboObservationConvention.java @@ -16,15 +16,15 @@ */ package org.apache.dubbo.metrics.observation; -import io.micrometer.common.KeyValues; -import io.micrometer.common.docs.KeyName; -import io.micrometer.common.lang.Nullable; - import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.support.RpcUtils; +import io.micrometer.common.KeyValues; +import io.micrometer.common.docs.KeyName; +import io.micrometer.common.lang.Nullable; + import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_METHOD; import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_SERVICE; import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_SYSTEM; diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientContext.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientContext.java index 6cd559fa1e..910d6f74c0 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientContext.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientContext.java @@ -16,12 +16,13 @@ */ package org.apache.dubbo.metrics.observation; -import java.util.Objects; - -import io.micrometer.observation.transport.SenderContext; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; +import io.micrometer.observation.transport.SenderContext; + +import java.util.Objects; + /** * Provider context for RPC. */ diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerContext.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerContext.java index d4ad9d97f3..bb1d7005d7 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerContext.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerContext.java @@ -16,10 +16,11 @@ */ package org.apache.dubbo.metrics.observation; -import io.micrometer.observation.transport.ReceiverContext; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; +import io.micrometer.observation.transport.ReceiverContext; + /** * Consumer context for RPC. */ diff --git a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConventionTest.java b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConventionTest.java index 8b91e2531d..ce83f9e886 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConventionTest.java +++ b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConventionTest.java @@ -16,10 +16,11 @@ */ package org.apache.dubbo.metrics.observation; -import io.micrometer.common.KeyValues; import org.apache.dubbo.metrics.observation.utils.ObservationConventionUtils; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; + +import io.micrometer.common.KeyValues; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConventionTest.java b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConventionTest.java index faa49457e7..7ca6398c9e 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConventionTest.java +++ b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConventionTest.java @@ -16,10 +16,11 @@ */ package org.apache.dubbo.metrics.observation; -import io.micrometer.common.KeyValues; import org.apache.dubbo.metrics.observation.utils.ObservationConventionUtils; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; + +import io.micrometer.common.KeyValues; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/utils/ObservationConventionUtils.java b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/utils/ObservationConventionUtils.java index 4bf2abfa1e..e6de96f069 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/utils/ObservationConventionUtils.java +++ b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/utils/ObservationConventionUtils.java @@ -16,10 +16,11 @@ */ package org.apache.dubbo.metrics.observation.utils; -import io.micrometer.common.KeyValue; -import io.micrometer.common.KeyValues; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invoker; + +import io.micrometer.common.KeyValue; +import io.micrometer.common.KeyValues; import org.mockito.Mockito; import java.lang.reflect.Field; diff --git a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/AbstractObservationFilterTest.java b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/AbstractObservationFilterTest.java index 99bf615947..31715ca94b 100644 --- a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/AbstractObservationFilterTest.java +++ b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/AbstractObservationFilterTest.java @@ -17,7 +17,6 @@ package org.apache.dubbo.metrics.observation; -import io.micrometer.tracing.test.SampleTestRunner; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.TracingConfig; import org.apache.dubbo.rpc.AppResponse; @@ -25,6 +24,8 @@ import org.apache.dubbo.rpc.BaseFilter; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.model.ApplicationModel; + +import io.micrometer.tracing.test.SampleTestRunner; import org.junit.jupiter.api.AfterEach; import static org.mockito.BDDMockito.given; diff --git a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilterTest.java b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilterTest.java index 1fe702e193..91101e1aa0 100644 --- a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilterTest.java +++ b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilterTest.java @@ -17,11 +17,6 @@ package org.apache.dubbo.metrics.observation; -import io.micrometer.common.KeyValues; -import io.micrometer.core.tck.MeterRegistryAssert; -import io.micrometer.tracing.Span; -import io.micrometer.tracing.Tracer; -import io.micrometer.tracing.test.simple.SpansAssert; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.AppResponse; import org.apache.dubbo.rpc.Filter; @@ -31,6 +26,12 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.model.ApplicationModel; + +import io.micrometer.common.KeyValues; +import io.micrometer.core.tck.MeterRegistryAssert; +import io.micrometer.tracing.Span; +import io.micrometer.tracing.Tracer; +import io.micrometer.tracing.test.simple.SpansAssert; import org.assertj.core.api.BDDAssertions; class ObservationReceiverFilterTest extends AbstractObservationFilterTest { diff --git a/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java b/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java index f8afc4a588..2d0ec9823b 100644 --- a/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java +++ b/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java @@ -116,7 +116,7 @@ public class MonitorFilter implements Filter, Filter.Listener { * @return */ private AtomicInteger getConcurrent(Invoker invoker, Invocation invocation) { - String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); + String key = invoker.getInterface().getName() + "." + RpcUtils.getMethodName(invocation); return ConcurrentHashMapUtils.computeIfAbsent(concurrents, key, k -> new AtomicInteger()); } diff --git a/dubbo-plugin/dubbo-auth/src/main/java/org/apache/dubbo/auth/AccessKeyAuthenticator.java b/dubbo-plugin/dubbo-auth/src/main/java/org/apache/dubbo/auth/AccessKeyAuthenticator.java index d4c7750ed1..875a3c3304 100644 --- a/dubbo-plugin/dubbo-auth/src/main/java/org/apache/dubbo/auth/AccessKeyAuthenticator.java +++ b/dubbo-plugin/dubbo-auth/src/main/java/org/apache/dubbo/auth/AccessKeyAuthenticator.java @@ -27,6 +27,7 @@ import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.support.RpcUtils; public class AccessKeyAuthenticator implements Authenticator { private final ApplicationModel applicationModel; @@ -54,7 +55,7 @@ public class AccessKeyAuthenticator implements Authenticator { if (StringUtils.isAnyEmpty(accessKeyId, consumer, requestTimestamp, originSignature)) { throw new RpcAuthenticationException("Failed to authenticate, maybe consumer side did not enable the auth"); } - + AccessKeyPair accessKeyPair; try { accessKeyPair = getAccessKeyPair(invocation, url); @@ -86,7 +87,7 @@ public class AccessKeyAuthenticator implements Authenticator { } String getSignature(URL url, Invocation invocation, String secretKey, String time) { - String requestString = String.format(Constants.SIGNATURE_STRING_FORMAT, url.getColonSeparatedKey(), invocation.getMethodName(), secretKey, time); + String requestString = String.format(Constants.SIGNATURE_STRING_FORMAT, url.getColonSeparatedKey(), RpcUtils.getMethodName(invocation), secretKey, time); boolean parameterEncrypt = url.getParameter(Constants.PARAMETER_SIGNATURE_ENABLE_KEY, false); if (parameterEncrypt) { return SignatureUtils.sign(invocation.getArguments(), requestString, secretKey); diff --git a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/AuthenticationExceptionTranslatorFilter.java b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/AuthenticationExceptionTranslatorFilter.java index 7885250782..00dadabf59 100644 --- a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/AuthenticationExceptionTranslatorFilter.java +++ b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/AuthenticationExceptionTranslatorFilter.java @@ -24,12 +24,16 @@ import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; + import org.springframework.security.access.AccessDeniedException; import org.springframework.security.core.AuthenticationException; + import static org.apache.dubbo.rpc.RpcException.AUTHORIZATION_EXCEPTION; +import static org.apache.dubbo.spring.security.utils.SecurityNames.CORE_JACKSON_2_MODULE_CLASS_NAME; +import static org.apache.dubbo.spring.security.utils.SecurityNames.OBJECT_MAPPER_CLASS_NAME; import static org.apache.dubbo.spring.security.utils.SecurityNames.SECURITY_CONTEXT_HOLDER_CLASS_NAME; -@Activate(group = CommonConstants.PROVIDER, order =Integer.MAX_VALUE,onClass = SECURITY_CONTEXT_HOLDER_CLASS_NAME) +@Activate(group = CommonConstants.PROVIDER, order = Integer.MAX_VALUE, onClass = {SECURITY_CONTEXT_HOLDER_CLASS_NAME, CORE_JACKSON_2_MODULE_CLASS_NAME, OBJECT_MAPPER_CLASS_NAME}) public class AuthenticationExceptionTranslatorFilter implements Filter, Filter.Listener { diff --git a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationPrepareFilter.java b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationPrepareFilter.java index e2a8fe0bc6..6617f4be85 100644 --- a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationPrepareFilter.java +++ b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationPrepareFilter.java @@ -27,13 +27,17 @@ import org.apache.dubbo.rpc.cluster.filter.ClusterFilter; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.spring.security.jackson.ObjectMapperCodec; import org.apache.dubbo.spring.security.utils.SecurityNames; + import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; + +import static org.apache.dubbo.spring.security.utils.SecurityNames.CORE_JACKSON_2_MODULE_CLASS_NAME; +import static org.apache.dubbo.spring.security.utils.SecurityNames.OBJECT_MAPPER_CLASS_NAME; import static org.apache.dubbo.spring.security.utils.SecurityNames.SECURITY_CONTEXT_HOLDER_CLASS_NAME; -@Activate(group = CommonConstants.CONSUMER, order = -10000,onClass = SECURITY_CONTEXT_HOLDER_CLASS_NAME) -public class ContextHolderAuthenticationPrepareFilter implements ClusterFilter{ +@Activate(group = CommonConstants.CONSUMER, order = -10000, onClass = {SECURITY_CONTEXT_HOLDER_CLASS_NAME, CORE_JACKSON_2_MODULE_CLASS_NAME, OBJECT_MAPPER_CLASS_NAME}) +public class ContextHolderAuthenticationPrepareFilter implements ClusterFilter { private final ObjectMapperCodec mapper; diff --git a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationResolverFilter.java b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationResolverFilter.java index acd5026409..9f2567185a 100644 --- a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationResolverFilter.java +++ b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationResolverFilter.java @@ -27,11 +27,15 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.spring.security.jackson.ObjectMapperCodec; import org.apache.dubbo.spring.security.utils.SecurityNames; + import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; + +import static org.apache.dubbo.spring.security.utils.SecurityNames.CORE_JACKSON_2_MODULE_CLASS_NAME; +import static org.apache.dubbo.spring.security.utils.SecurityNames.OBJECT_MAPPER_CLASS_NAME; import static org.apache.dubbo.spring.security.utils.SecurityNames.SECURITY_CONTEXT_HOLDER_CLASS_NAME; -@Activate(group = CommonConstants.PROVIDER, order = -10000,onClass = SECURITY_CONTEXT_HOLDER_CLASS_NAME) +@Activate(group = CommonConstants.PROVIDER, order = -10000, onClass = {SECURITY_CONTEXT_HOLDER_CLASS_NAME, CORE_JACKSON_2_MODULE_CLASS_NAME, OBJECT_MAPPER_CLASS_NAME}) public class ContextHolderAuthenticationResolverFilter implements Filter { private final ObjectMapperCodec mapper; diff --git a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/model/SecurityScopeModelInitializer.java b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/model/SecurityScopeModelInitializer.java index 9679334f6f..286adedb1d 100644 --- a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/model/SecurityScopeModelInitializer.java +++ b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/model/SecurityScopeModelInitializer.java @@ -25,10 +25,14 @@ import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ScopeModelInitializer; import org.apache.dubbo.spring.security.jackson.ObjectMapperCodec; import org.apache.dubbo.spring.security.jackson.ObjectMapperCodecCustomer; + import java.util.Set; + +import static org.apache.dubbo.spring.security.utils.SecurityNames.CORE_JACKSON_2_MODULE_CLASS_NAME; +import static org.apache.dubbo.spring.security.utils.SecurityNames.OBJECT_MAPPER_CLASS_NAME; import static org.apache.dubbo.spring.security.utils.SecurityNames.SECURITY_CONTEXT_HOLDER_CLASS_NAME; -@Activate(onClass = SECURITY_CONTEXT_HOLDER_CLASS_NAME) +@Activate(onClass = {SECURITY_CONTEXT_HOLDER_CLASS_NAME, CORE_JACKSON_2_MODULE_CLASS_NAME, OBJECT_MAPPER_CLASS_NAME}) public class SecurityScopeModelInitializer implements ScopeModelInitializer { @Override diff --git a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/utils/SecurityNames.java b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/utils/SecurityNames.java index 010d8d4f17..97e167095b 100644 --- a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/utils/SecurityNames.java +++ b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/utils/SecurityNames.java @@ -22,6 +22,8 @@ final public class SecurityNames { public static final String SECURITY_AUTHENTICATION_CONTEXT_KEY = "security_authentication_context"; public static final String SECURITY_CONTEXT_HOLDER_CLASS_NAME = "org.springframework.security.core.context.SecurityContextHolder"; + public static final String CORE_JACKSON_2_MODULE_CLASS_NAME = "org.springframework.security.jackson2.CoreJackson2Module"; + public static final String OBJECT_MAPPER_CLASS_NAME = "com.fasterxml.jackson.databind.ObjectMapper"; private SecurityNames() {} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java index d21534436c..be991b256e 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java @@ -21,6 +21,7 @@ public interface Constants { String REGISTER_IP_KEY = "register.ip"; String REGISTER_KEY = "register"; + String REGISTER_ORIGIN_KEY = "register_origin"; String SUBSCRIBE_KEY = "subscribe"; diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryNotifier.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryNotifier.java index 168368690a..fe9296b8e3 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryNotifier.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryNotifier.java @@ -77,6 +77,14 @@ public abstract class RegistryNotifier { } scheduler.submit(new NotificationTask(this, notifyTime)); } + try { + while (this.lastEventTime == System.currentTimeMillis()) { + // wait to let event time refresh + Thread.sleep(1); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } } public long getDelayTime() { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryScopeModelInitializer.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryScopeModelInitializer.java index e2de1cbf86..a33ab61ecd 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryScopeModelInitializer.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryScopeModelInitializer.java @@ -18,6 +18,7 @@ package org.apache.dubbo.registry; import org.apache.dubbo.common.beans.factory.ScopeBeanFactory; import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation; +import org.apache.dubbo.registry.integration.ExporterFactory; import org.apache.dubbo.registry.support.RegistryManager; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.FrameworkModel; @@ -27,7 +28,8 @@ import org.apache.dubbo.rpc.model.ScopeModelInitializer; public class RegistryScopeModelInitializer implements ScopeModelInitializer { @Override public void initializeFrameworkModel(FrameworkModel frameworkModel) { - + ScopeBeanFactory beanFactory = frameworkModel.getBeanFactory(); + beanFactory.registerBean(ExporterFactory.class); } @Override diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java index eac73aec83..baec948745 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java @@ -124,7 +124,7 @@ public class ServiceDiscoveryRegistryDirectory extends DynamicDirectory { @Override public void subscribe(URL url) { - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, Constants.ENABLE_CONFIGURATION_LISTEN, true)) { enableConfigurationListen = true; getConsumerConfigurationListener(moduleModel).addNotifyListener(this); referenceConfigurationListener = new ReferenceConfigurationListener(this.moduleModel, this, url); @@ -143,7 +143,7 @@ public class ServiceDiscoveryRegistryDirectory extends DynamicDirectory { public void unSubscribe(URL url) { super.unSubscribe(url); this.originalUrls = null; - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, Constants.ENABLE_CONFIGURATION_LISTEN, true)) { getConsumerConfigurationListener(moduleModel).removeNotifyListener(this); referenceConfigurationListener.stop(); } @@ -152,7 +152,7 @@ public class ServiceDiscoveryRegistryDirectory extends DynamicDirectory { @Override public void destroy() { super.destroy(); - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, Constants.ENABLE_CONFIGURATION_LISTEN, true)) { getConsumerConfigurationListener(moduleModel).removeNotifyListener(this); referenceConfigurationListener.stop(); } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java index f1546815f8..9f9aaaa860 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java @@ -103,6 +103,7 @@ public interface ServiceInstance extends Serializable { void setApplicationModel(ApplicationModel applicationModel); + @Transient ApplicationModel getApplicationModel(); @Transient diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java index 02e877ca89..de6abfd39b 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java @@ -97,7 +97,7 @@ public class MigrationRuleListener implements RegistryProtocolListener, Configur private void init() { this.ruleKey = moduleModel.getApplicationModel().getApplicationName() + ".migration"; - this.configuration = moduleModel.getModelEnvironment().getDynamicConfiguration().orElse(null); + this.configuration = moduleModel.modelEnvironment().getDynamicConfiguration().orElse(null); if (this.configuration != null) { logger.info("Listening for migration rules on dataId " + ruleKey + ", group " + DUBBO_SERVICEDISCOVERY_MIGRATION); @@ -115,7 +115,7 @@ public class MigrationRuleListener implements RegistryProtocolListener, Configur setRawRule(INIT); } - String localRawRule = moduleModel.getModelEnvironment().getLocalMigrationRule(); + String localRawRule = moduleModel.modelEnvironment().getLocalMigrationRule(); if (!StringUtils.isEmpty(localRawRule)) { localRuleMigrationFuture = moduleModel.getApplicationModel().getFrameworkModel().getBeanFactory() .getBean(FrameworkExecutorRepository.class).getSharedScheduledExecutor() diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ExporterFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ExporterFactory.java new file mode 100644 index 0000000000..5eebc1bcaa --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ExporterFactory.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.registry.integration; + +import org.apache.dubbo.rpc.Exporter; + +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; + +public class ExporterFactory { + private final Map> exporters = new ConcurrentHashMap<>(); + + protected ReferenceCountExporter createExporter(String providerKey, Callable> exporterProducer) { + return exporters.computeIfAbsent(providerKey, + key -> { + try { + return new ReferenceCountExporter<>(exporterProducer.call(), key, this); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + + protected void remove(String key, ReferenceCountExporter exporter) { + exporters.remove(key, exporter); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ReferenceCountExporter.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ReferenceCountExporter.java new file mode 100644 index 0000000000..bcdce7172f --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ReferenceCountExporter.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.registry.integration; + +import org.apache.dubbo.rpc.Exporter; +import org.apache.dubbo.rpc.Invoker; + +import java.util.concurrent.atomic.AtomicInteger; + +public class ReferenceCountExporter implements Exporter { + private final Exporter exporter; + private final String providerKey; + private final ExporterFactory exporterFactory; + private final AtomicInteger count = new AtomicInteger(0); + + public ReferenceCountExporter(Exporter exporter, String providerKey, ExporterFactory exporterFactory) { + this.exporter = exporter; + this.providerKey = providerKey; + this.exporterFactory = exporterFactory; + } + + @Override + public Invoker getInvoker() { + return exporter.getInvoker(); + } + + public void increaseCount() { + count.incrementAndGet(); + } + + @Override + public void unexport() { + if (count.decrementAndGet() == 0) { + exporter.unexport(); + } + exporterFactory.remove(providerKey, this); + } + + @Override + public void register() { + + } + + @Override + public void unregister() { + + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java index 6405c75eab..2c58510507 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -138,7 +138,7 @@ public class RegistryDirectory extends DynamicDirectory { return null; } ); - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { consumerConfigurationListener.addNotifyListener(this); referenceConfigurationListener = new ReferenceConfigurationListener(moduleModel, this, url); } @@ -152,7 +152,7 @@ public class RegistryDirectory extends DynamicDirectory { @Override public void unSubscribe(URL url) { super.unSubscribe(url); - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { consumerConfigurationListener.removeNotifyListener(this); if (referenceConfigurationListener != null) { referenceConfigurationListener.stop(); @@ -163,7 +163,7 @@ public class RegistryDirectory extends DynamicDirectory { @Override public void destroy() { super.destroy(); - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { consumerConfigurationListener.removeNotifyListener(this); if (referenceConfigurationListener != null) { referenceConfigurationListener.stop(); @@ -183,7 +183,7 @@ public class RegistryDirectory extends DynamicDirectory { .filter(this::isNotCompatibleFor26x) .collect(Collectors.groupingBy(this::judgeCategory)); - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { List configuratorURLs = categoryUrls.getOrDefault(CONFIGURATORS_CATEGORY, Collections.emptyList()); this.configurators = Configurator.toConfigurators(configuratorURLs).orElse(this.configurators); diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java index 33f872ac75..b69376e784 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java @@ -171,6 +171,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { private ConcurrentMap reExportFailedTasks = new ConcurrentHashMap<>(); private HashedWheelTimer retryTimer = new HashedWheelTimer(new NamedThreadFactory("DubboReexportTimer", true), DEFAULT_REGISTRY_RETRY_PERIOD, TimeUnit.MILLISECONDS, 128); private FrameworkModel frameworkModel; + private ExporterFactory exporterFactory; //Filter the parameters that do not need to be output in url(Starting with .) private static String[] getFilteredKeys(URL url) { @@ -190,6 +191,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { @Override public void setFrameworkModel(FrameworkModel frameworkModel) { this.frameworkModel = frameworkModel; + this.exporterFactory = frameworkModel.getBeanFactory().getBean(ExporterFactory.class); } public void setProtocol(Protocol protocol) { @@ -276,7 +278,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { exporter.setRegistered(register); ApplicationModel applicationModel = getApplicationModel(providerUrl.getScopeModel()); - if (applicationModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { + if (applicationModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { if (!registry.isServiceDiscovery()) { // Deprecated! Subscribe to override rules in 2.6.x or before. registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener); @@ -312,11 +314,13 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { private ExporterChangeableWrapper doLocalExport(final Invoker originInvoker, URL providerUrl) { String providerUrlKey = getProviderUrlKey(originInvoker); String registryUrlKey = getRegistryUrlKey(originInvoker); + Invoker invokerDelegate = new InvokerDelegate<>(originInvoker, providerUrl); + ReferenceCountExporter exporter = exporterFactory.createExporter(providerUrlKey, () -> protocol.export(invokerDelegate)); return (ExporterChangeableWrapper) bounds.computeIfAbsent(providerUrlKey, _k -> new ConcurrentHashMap<>()) - .computeIfAbsent(registryUrlKey, s ->{ - Invoker invokerDelegate = new InvokerDelegate<>(originInvoker, providerUrl); - return new ExporterChangeableWrapper<>((Exporter) protocol.export(invokerDelegate), originInvoker); + .computeIfAbsent(registryUrlKey, s -> { + return new ExporterChangeableWrapper<>( + (ReferenceCountExporter) exporter, originInvoker); }); } @@ -657,7 +661,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { } for (ApplicationModel applicationModel : frameworkModel.getApplicationModels()) { - if (applicationModel.getModelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (applicationModel.modelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { for (ModuleModel moduleModel : applicationModel.getPubModuleModels()) { String applicationName = applicationModel.tryGetApplicationName(); if (applicationName == null) { @@ -869,7 +873,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { this.providerUrl = providerUrl; this.notifyListener = notifyListener; this.moduleModel = moduleModel; - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { this.initWith(DynamicConfiguration.getRuleKey(providerUrl) + CONFIGURATORS_SUFFIX); } } @@ -899,7 +903,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { public ProviderConfigurationListener(ModuleModel moduleModel) { super(moduleModel); this.moduleModel = moduleModel; - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { this.initWith(moduleModel.getApplicationModel().getApplicationName() + CONFIGURATORS_SUFFIX); } } @@ -953,8 +957,9 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { private NotifyListener notifyListener; private final AtomicBoolean registered = new AtomicBoolean(false); - public ExporterChangeableWrapper(Exporter exporter, Invoker originInvoker) { + public ExporterChangeableWrapper(ReferenceCountExporter exporter, Invoker originInvoker) { this.exporter = exporter; + exporter.increaseCount(); this.originInvoker = originInvoker; FrameworkExecutorRepository frameworkExecutorRepository = originInvoker.getUrl().getOrDefaultFrameworkModel().getBeanFactory() .getBean(FrameworkExecutorRepository.class); @@ -1009,12 +1014,12 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { if (listeners != null) { if (listeners.remove(notifyListener)) { ApplicationModel applicationModel = getApplicationModel(registerUrl.getScopeModel()); - if (applicationModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { + if (applicationModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { if (!registry.isServiceDiscovery()) { registry.unsubscribe(subscribeUrl, notifyListener); } } - if (applicationModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { + if (applicationModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { for (ModuleModel moduleModel : applicationModel.getPubModuleModels()) { if (moduleModel.getServiceRepository().getExportedServices().size() > 0) { moduleModel.getExtensionLoader(GovernanceRuleRepository.class).getDefaultExtension() diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java index 3a68a26433..1ba9b330b8 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java @@ -61,12 +61,12 @@ import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_LOCAL_FILE_CACHE_ENABLED; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_EMPTY_ADDRESS; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_NOTIFY_EVENT; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DESTROY_UNREGISTER_URL; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_READ_WRITE_CACHE_FILE; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DELETE_LOCKFILE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_EMPTY_ADDRESS; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DELETE_LOCKFILE; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DESTROY_UNREGISTER_URL; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_NOTIFY_EVENT; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_READ_WRITE_CACHE_FILE; import static org.apache.dubbo.common.constants.RegistryConstants.ACCEPTS_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/migration/MigrationRuleListenerTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/migration/MigrationRuleListenerTest.java index 79c74a70dc..6b06bf0f9b 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/migration/MigrationRuleListenerTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/migration/MigrationRuleListenerTest.java @@ -90,8 +90,8 @@ class MigrationRuleListenerTest { DynamicConfiguration dynamicConfiguration = Mockito.mock(DynamicConfiguration.class); ApplicationModel.reset(); - ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().setDynamicConfiguration(dynamicConfiguration); - ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().setLocalMigrationRule(localRule); + ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().setDynamicConfiguration(dynamicConfiguration); + ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().setLocalMigrationRule(localRule); ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("demo-consumer"); ApplicationModel.defaultModel().getApplicationConfigManager().setApplication(applicationConfig); @@ -134,8 +134,8 @@ class MigrationRuleListenerTest { */ @Test void testWithInitAndNoLocalRule() { - ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().setDynamicConfiguration(null); - ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().setLocalMigrationRule(""); + ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().setDynamicConfiguration(null); + ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().setLocalMigrationRule(""); ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("demo-consumer"); ApplicationModel.defaultModel().getApplicationConfigManager().setApplication(applicationConfig); @@ -170,8 +170,8 @@ class MigrationRuleListenerTest { DynamicConfiguration dynamicConfiguration = Mockito.mock(DynamicConfiguration.class); Mockito.doReturn(remoteRule).when(dynamicConfiguration).getConfig(Mockito.anyString(), Mockito.anyString()); - ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().setDynamicConfiguration(dynamicConfiguration); - ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().setLocalMigrationRule(localRule); + ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().setDynamicConfiguration(dynamicConfiguration); + ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().setLocalMigrationRule(localRule); ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("demo-consumer"); ApplicationModel.defaultModel().getApplicationConfigManager().setApplication(applicationConfig); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java index 3fd883d0aa..6a4c67da84 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java @@ -169,5 +169,5 @@ public interface Constants { String PORT_UNIFICATION_NETTY4_SERVER = "netty4"; List REST_SERVER = Arrays.asList("jetty", "tomcat", "netty"); - + String CONTENT_LENGTH_KEY = "content-length"; } diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java index 3539723adb..f49ef15867 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.resource.GlobalResourceInitializer; import org.apache.dubbo.common.serialize.SerializationException; +import org.apache.dubbo.common.threadpool.ThreadlessExecutor; import org.apache.dubbo.common.timer.HashedWheelTimer; import org.apache.dubbo.common.timer.Timeout; import org.apache.dubbo.common.timer.Timer; @@ -197,6 +198,7 @@ public class DefaultFuture extends CompletableFuture { t.cancel(); } future.doReceived(response); + shutdownExecutorIfNeeded(future); } else { logger.warn(PROTOCOL_TIMEOUT_SERVER, "", "", "The timeout response finally returned at " + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date())) @@ -215,12 +217,20 @@ public class DefaultFuture extends CompletableFuture { errorResult.setStatus(Response.CLIENT_ERROR); errorResult.setErrorMessage("request future has been canceled."); this.doReceived(errorResult); - FUTURES.remove(id); + DefaultFuture future = FUTURES.remove(id); + shutdownExecutorIfNeeded(future); CHANNELS.remove(id); timeoutCheckTask.cancel(); return true; } + private static void shutdownExecutorIfNeeded(DefaultFuture future) { + ExecutorService executor = future.getExecutor(); + if (executor instanceof ThreadlessExecutor && !executor.isShutdown()) { + executor.shutdownNow(); + } + } + public void cancel() { this.cancel(true); } diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/exchange/support/DefaultFutureTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/exchange/support/DefaultFutureTest.java index 1e28237370..8188720480 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/exchange/support/DefaultFutureTest.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/exchange/support/DefaultFutureTest.java @@ -161,7 +161,7 @@ class DefaultFutureTest { } @Test - void testClose() { + void testClose1() { Channel channel = new MockedChannel(); Request request = new Request(123); ExecutorService executor = ExtensionLoader.getExtensionLoader(ExecutorRepository.class) @@ -171,6 +171,16 @@ class DefaultFutureTest { Assertions.assertFalse(executor.isTerminated()); } + @Test + void testClose2() { + Channel channel = new MockedChannel(); + Request request = new Request(123); + ThreadlessExecutor threadlessExecutor = new ThreadlessExecutor(); + DefaultFuture.newFuture(channel, request, 1000, threadlessExecutor); + DefaultFuture.closeChannel(channel, 0); + Assertions.assertTrue(threadlessExecutor.isTerminated()); + } + /** * mock a default future */ diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java index 5e516c72a9..7244fa38fb 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java @@ -183,7 +183,7 @@ public class AsyncRpcResult implements Result { if (executor != null && executor instanceof ThreadlessExecutor) { ThreadlessExecutor threadlessExecutor = (ThreadlessExecutor) executor; try { - while (!responseFuture.isDone()) { + while (!responseFuture.isDone() && !threadlessExecutor.isShutdown()) { threadlessExecutor.waitAndDrain(Long.MAX_VALUE); } } finally { @@ -199,7 +199,7 @@ public class AsyncRpcResult implements Result { if (executor != null && executor instanceof ThreadlessExecutor) { ThreadlessExecutor threadlessExecutor = (ThreadlessExecutor) executor; try { - while (!responseFuture.isDone()) { + while (!responseFuture.isDone() && !threadlessExecutor.isShutdown()) { long restTime = deadline - System.nanoTime(); if (restTime > 0) { threadlessExecutor.waitAndDrain(deadline); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java index 1cb4177a90..b40fa05e8a 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java @@ -16,16 +16,17 @@ */ package org.apache.dubbo.rpc; -import java.util.List; -import java.util.Map; -import java.util.function.Consumer; -import java.util.stream.Stream; - import org.apache.dubbo.common.Experimental; import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ScopeModelUtil; import org.apache.dubbo.rpc.model.ServiceModel; +import java.beans.Transient; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Stream; + /** * Invocation. (API, Prototype, NonThreadSafe) * @@ -148,6 +149,7 @@ public interface Invocation { * @return invoker. * @transient */ + @Transient Invoker getInvoker(); void setServiceModel(ServiceModel serviceModel); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/PathResolver.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/PathResolver.java index c3e910a56d..83c5979cb8 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/PathResolver.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/PathResolver.java @@ -27,7 +27,9 @@ import org.apache.dubbo.common.extension.SPI; @SPI(value = CommonConstants.TRIPLE, scope = ExtensionScope.FRAMEWORK) public interface PathResolver { - void add(String path, Invoker invoker); + Invoker add(String path, Invoker invoker); + + Invoker addIfAbsent(String path, Invoker invoker); Invoker resolve(String path); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java index 0ad448d487..184aaf2001 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java @@ -30,6 +30,7 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.support.AccessLogData; +import org.apache.dubbo.rpc.support.RpcUtils; import java.io.File; import java.io.FileWriter; @@ -198,7 +199,7 @@ public class AccessLogFilter implements Filter { private AccessLogData buildAccessLogData(Invoker invoker, Invocation inv) { AccessLogData logData = AccessLogData.newLogData(); logData.setServiceName(invoker.getInterface().getName()); - logData.setMethodName(inv.getMethodName()); + logData.setMethodName(RpcUtils.getMethodName(inv)); logData.setVersion(invoker.getUrl().getVersion()); logData.setGroup(invoker.getUrl().getGroup()); logData.setInvocationTime(new Date()); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java index dc954d70e6..6123b5ba10 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java @@ -24,6 +24,7 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcStatus; +import org.apache.dubbo.rpc.support.RpcUtils; import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; @@ -49,11 +50,11 @@ public class ActiveLimitFilter implements Filter, Filter.Listener { @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); - String methodName = invocation.getMethodName(); + String methodName = RpcUtils.getMethodName(invocation); int max = invoker.getUrl().getMethodParameter(methodName, ACTIVES_KEY, 0); - final RpcStatus rpcStatus = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); + final RpcStatus rpcStatus = RpcStatus.getStatus(invoker.getUrl(), RpcUtils.getMethodName(invocation)); if (!RpcStatus.beginCount(url, methodName, max)) { - long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), TIMEOUT_KEY, 0); + long timeout = invoker.getUrl().getMethodParameter(RpcUtils.getMethodName(invocation), TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; synchronized (rpcStatus) { @@ -68,7 +69,7 @@ public class ActiveLimitFilter implements Filter, Filter.Listener { if (remain <= 0) { throw new RpcException(RpcException.LIMIT_EXCEEDED_EXCEPTION, "Waiting concurrent invoke timeout in client-side for service: " + - invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + + invoker.getInterface().getName() + ", method: " + RpcUtils.getMethodName(invocation) + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + rpcStatus.getActive() + ". max concurrent invoke limit: " + max); } @@ -83,7 +84,7 @@ public class ActiveLimitFilter implements Filter, Filter.Listener { @Override public void onResponse(Result appResponse, Invoker invoker, Invocation invocation) { - String methodName = invocation.getMethodName(); + String methodName = RpcUtils.getMethodName(invocation); URL url = invoker.getUrl(); int max = invoker.getUrl().getMethodParameter(methodName, ACTIVES_KEY, 0); @@ -93,7 +94,7 @@ public class ActiveLimitFilter implements Filter, Filter.Listener { @Override public void onError(Throwable t, Invoker invoker, Invocation invocation) { - String methodName = invocation.getMethodName(); + String methodName = RpcUtils.getMethodName(invocation); URL url = invoker.getUrl(); int max = invoker.getUrl().getMethodParameter(methodName, ACTIVES_KEY, 0); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java index 98654af030..228cc44a82 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java @@ -26,6 +26,7 @@ import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.Set; @@ -47,10 +48,10 @@ public class DeprecatedFilter implements Filter { @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); + String key = invoker.getInterface().getName() + "." + RpcUtils.getMethodName(invocation); if (!LOGGED.contains(key)) { LOGGED.add(key); - if (invoker.getUrl().getMethodParameter(invocation.getMethodName(), DEPRECATED_KEY, false)) { + if (invoker.getUrl().getMethodParameter(RpcUtils.getMethodName(invocation), DEPRECATED_KEY, false)) { LOGGER.error(COMMON_UNSUPPORTED_INVOKER, "", "", "The service method " + invoker.getInterface().getName() + "." + getMethodSignature(invocation) + " is DEPRECATED! Declare from " + invoker.getUrl()); } } @@ -58,7 +59,7 @@ public class DeprecatedFilter implements Filter { } private String getMethodSignature(Invocation invocation) { - StringBuilder buf = new StringBuilder(invocation.getMethodName()); + StringBuilder buf = new StringBuilder(RpcUtils.getMethodName(invocation)); buf.append('('); Class[] types = invocation.getParameterTypes(); if (types != null && types.length > 0) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java index 91c830cb53..2cadfec117 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java @@ -29,6 +29,7 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.service.GenericService; +import org.apache.dubbo.rpc.support.RpcUtils; import java.lang.reflect.Method; @@ -66,7 +67,7 @@ public class ExceptionFilter implements Filter, Filter.Listener { } // directly throw if the exception appears in the signature try { - Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes()); + Method method = invoker.getInterface().getMethod(RpcUtils.getMethodName(invocation), invocation.getParameterTypes()); Class[] exceptionClasses = method.getExceptionTypes(); for (Class exceptionClass : exceptionClasses) { if (exception.getClass().equals(exceptionClass)) { @@ -78,7 +79,10 @@ public class ExceptionFilter implements Filter, Filter.Listener { } // for the exception not found in method's signature, print ERROR message in server's log. - logger.error(CONFIG_FILTER_VALIDATION_EXCEPTION, "", "", "Got unchecked and undeclared exception which called by " + RpcContext.getServiceContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception); + logger.error(CONFIG_FILTER_VALIDATION_EXCEPTION, "", "", + "Got unchecked and undeclared exception which called by " + RpcContext.getServiceContext().getRemoteHost() + + ". service: " + invoker.getInterface().getName() + ", method: " + RpcUtils.getMethodName(invocation) + + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception); // directly throw if exception class and interface class are in the same jar file. String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface()); @@ -99,14 +103,20 @@ public class ExceptionFilter implements Filter, Filter.Listener { // otherwise, wrap with RuntimeException and throw back to the client appResponse.setException(new RuntimeException(StringUtils.toString(exception))); } catch (Throwable e) { - logger.warn(CONFIG_FILTER_VALIDATION_EXCEPTION, "", "", "Fail to ExceptionFilter when called by " + RpcContext.getServiceContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); + logger.warn(CONFIG_FILTER_VALIDATION_EXCEPTION, "", "", + "Fail to ExceptionFilter when called by " + RpcContext.getServiceContext().getRemoteHost() + + ". service: " + invoker.getInterface().getName() + ", method: " + RpcUtils.getMethodName(invocation) + + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); } } } @Override public void onError(Throwable e, Invoker invoker, Invocation invocation) { - logger.error(CONFIG_FILTER_VALIDATION_EXCEPTION, "", "", "Got unchecked and undeclared exception which called by " + RpcContext.getServiceContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); + logger.error(CONFIG_FILTER_VALIDATION_EXCEPTION, "", "", + "Got unchecked and undeclared exception which called by " + RpcContext.getServiceContext().getRemoteHost() + + ". service: " + invoker.getInterface().getName() + ", method: " + RpcUtils.getMethodName(invocation) + + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); } // For test purpose diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java index da36479724..e77e512f3e 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java @@ -26,9 +26,10 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcStatus; import org.apache.dubbo.rpc.service.GenericService; +import org.apache.dubbo.rpc.support.RpcUtils; + import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE; import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE_ASYNC; - import static org.apache.dubbo.rpc.Constants.EXECUTES_KEY; @@ -45,11 +46,11 @@ public class ExecuteLimitFilter implements Filter, Filter.Listener { @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); - String methodName = invocation.getMethodName(); + String methodName = RpcUtils.getMethodName(invocation); int max = url.getMethodParameter(methodName, EXECUTES_KEY, 0); if (!RpcStatus.beginCount(url, methodName, max)) { throw new RpcException(RpcException.LIMIT_EXCEEDED_EXCEPTION, - "Failed to invoke method " + invocation.getMethodName() + " in provider " + + "Failed to invoke method " + RpcUtils.getMethodName(invocation) + " in provider " + url + ", cause: The service using threads greater than limited."); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java index b69ba505f0..00f23815cd 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java @@ -115,7 +115,7 @@ public class GenericFilter implements Filter, Filter.Listener, ScopeModelAware { } else if (ProtocolUtils.isGsonGenericSerialization(generic)) { args = getGsonGenericArgs(args, method.getGenericParameterTypes()); } else if (ProtocolUtils.isJavaGenericSerialization(generic)) { - Configuration configuration = ApplicationModel.ofNullable(applicationModel).getModelEnvironment().getConfiguration(); + Configuration configuration = ApplicationModel.ofNullable(applicationModel).modelEnvironment().getConfiguration(); if (!configuration.getBoolean(CommonConstants.ENABLE_NATIVE_JAVA_GENERIC_SERIALIZE, false)) { String notice = "Trigger the safety barrier! " + "Native Java Serializer is not allowed by default." + diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java index 97f108d60b..36aa5c8ca0 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java @@ -103,7 +103,7 @@ public class ProfilerServerFilter implements Filter, BaseFilter.Listener { Long timeout = RpcUtils.convertToNumber(invocation.getObjectAttachmentWithoutConvert(TIMEOUT_KEY)); if (timeout == null) { - timeout = (long) invoker.getUrl().getMethodPositiveParameter(invocation.getMethodName(), TIMEOUT_KEY, DEFAULT_TIMEOUT); + timeout = (long) invoker.getUrl().getMethodPositiveParameter(RpcUtils.getMethodName(invocation), TIMEOUT_KEY, DEFAULT_TIMEOUT); } long usage = profiler.getEndTime() - profiler.getStartTime(); if (((usage / (1000_000L * ProfilerSwitch.getWarnPercent())) > timeout) && timeout != -1) { @@ -118,7 +118,7 @@ public class ProfilerServerFilter implements Filter, BaseFilter.Listener { "client: %s\n" + "invocation context:\n%s" + "thread info: \n%s", - invocation.getTargetServiceUniqueName(), invocation.getMethodName(), usage / 1000_000, usage % 1000_000, timeout, + invocation.getTargetServiceUniqueName(), RpcUtils.getMethodName(invocation), usage / 1000_000, usage % 1000_000, timeout, invocation.get(CLIENT_IP_KEY), attachment, Profiler.buildDetail(profiler))); } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TimeoutFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TimeoutFilter.java index f4dae94073..dac40680de 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TimeoutFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TimeoutFilter.java @@ -27,6 +27,7 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.TimeoutCountDown; +import org.apache.dubbo.rpc.support.RpcUtils; import static org.apache.dubbo.common.constants.CommonConstants.TIME_COUNTDOWN_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROXY_TIMEOUT_REQUEST; @@ -51,7 +52,7 @@ public class TimeoutFilter implements Filter, Filter.Listener { TimeoutCountDown countDown = (TimeoutCountDown) obj; if (countDown.isExpired()) { if (logger.isWarnEnabled()) { - logger.warn(PROXY_TIMEOUT_REQUEST, "", "", "invoke timed out. method: " + invocation.getMethodName() + + logger.warn(PROXY_TIMEOUT_REQUEST, "", "", "invoke timed out. method: " + RpcUtils.getMethodName(invocation) + " url is " + invoker.getUrl() + ", invoke elapsed " + countDown.elapsedMillis() + " ms."); } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenFilter.java index 056d27e6a1..f00dae649d 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenFilter.java @@ -25,6 +25,7 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.support.RpcUtils; import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; @@ -45,7 +46,7 @@ public class TokenFilter implements Filter { Class serviceType = invoker.getInterface(); String remoteToken = (String) inv.getObjectAttachmentWithoutConvert(TOKEN_KEY); if (!token.equals(remoteToken)) { - throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + + throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + RpcUtils.getMethodName(inv) + "() from consumer " + RpcContext.getServiceContext().getRemoteHost() + " to provider " + RpcContext.getServiceContext().getLocalHost()+ ", consumer incorrect token is " + remoteToken); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenHeaderFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenHeaderFilter.java index d72b790a47..583e91d4cc 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenHeaderFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenHeaderFilter.java @@ -23,6 +23,7 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.rpc.support.RpcUtils; import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; import static org.apache.dubbo.rpc.RpcException.FORBIDDEN_EXCEPTION; @@ -36,7 +37,7 @@ public class TokenHeaderFilter implements HeaderFilter { Class serviceType = invoker.getInterface(); String remoteToken = (String) invocation.getObjectAttachmentWithoutConvert(TOKEN_KEY); if (!token.equals(remoteToken)) { - throw new RpcException(FORBIDDEN_EXCEPTION, "Forbid invoke remote service " + serviceType + " method " + invocation.getMethodName() + + throw new RpcException(FORBIDDEN_EXCEPTION, "Forbid invoke remote service " + serviceType + " method " + RpcUtils.getMethodName(invocation) + "() from consumer " + RpcContext.getServiceContext().getRemoteHost() + " to provider " + RpcContext.getServiceContext().getLocalHost() + ", consumer incorrect token is " + remoteToken); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TpsLimitFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TpsLimitFilter.java index 4678e0109f..e06444d693 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TpsLimitFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TpsLimitFilter.java @@ -26,6 +26,7 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.filter.tps.DefaultTPSLimiter; import org.apache.dubbo.rpc.filter.tps.TPSLimiter; +import org.apache.dubbo.rpc.support.RpcUtils; import static org.apache.dubbo.rpc.Constants.TPS_LIMIT_RATE_KEY; @@ -49,7 +50,7 @@ public class TpsLimitFilter implements Filter { "Failed to invoke service " + invoker.getInterface().getName() + "." + - invocation.getMethodName() + + RpcUtils.getMethodName(invocation) + " because exceed max service tps."); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/tps/DefaultTPSLimiter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/tps/DefaultTPSLimiter.java index 05d32ca483..9d638c0278 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/tps/DefaultTPSLimiter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/tps/DefaultTPSLimiter.java @@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.filter.tps; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -38,8 +39,8 @@ public class DefaultTPSLimiter implements TPSLimiter { @Override public boolean isAllowable(URL url, Invocation invocation) { - int rate = url.getMethodParameter(invocation.getMethodName(), TPS_LIMIT_RATE_KEY, -1); - long interval = url.getMethodParameter(invocation.getMethodName(), TPS_LIMIT_INTERVAL_KEY, DEFAULT_TPS_LIMIT_INTERVAL); + int rate = url.getMethodParameter(RpcUtils.getMethodName(invocation), TPS_LIMIT_RATE_KEY, -1); + long interval = url.getMethodParameter(RpcUtils.getMethodName(invocation), TPS_LIMIT_INTERVAL_KEY, DEFAULT_TPS_LIMIT_INTERVAL); String serviceKey = url.getServiceKey(); if (rate > 0) { StatItem statItem = stats.get(serviceKey); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/AccessLogData.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/AccessLogData.java index 0265517eae..a3acfb2efd 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/AccessLogData.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/AccessLogData.java @@ -284,7 +284,7 @@ public final class AccessLogData { public void buildAccessLogData(Invoker invoker, Invocation inv) { setServiceName(invoker.getInterface().getName()); - setMethodName(inv.getMethodName()); + setMethodName(RpcUtils.getMethodName(inv)); setVersion(invoker.getUrl().getVersion()); setGroup(invoker.getUrl().getGroup()); setInvocationTime(new Date()); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java index 9723ebf78f..2bc90887fb 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java @@ -39,6 +39,7 @@ import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ProviderModel; import org.apache.dubbo.rpc.model.ServiceDescriptor; import org.apache.dubbo.rpc.model.ServiceMetadata; +import org.apache.dubbo.rpc.support.RpcUtils; import java.io.IOException; import java.util.HashMap; @@ -52,9 +53,9 @@ import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_PROPERTY_TYPE_MISMATCH; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_DESTROY_INVOKER; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_LOAD_MODEL; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_PROPERTY_TYPE_MISMATCH; import static org.apache.dubbo.rpc.Constants.IS_SERVER_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.CALLBACK_SERVICE_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.CALLBACK_SERVICE_PROXY_KEY; @@ -219,7 +220,7 @@ public class CallbackServiceCodec { channel.setAttribute(CHANNEL_CALLBACK_KEY, callbackInvokers); } callbackInvokers.add(invoker); - logger.info("method " + inv.getMethodName() + " include a callback service :" + invoker.getUrl() + ", a proxy :" + invoker + " has been created."); + logger.info("method " + RpcUtils.getMethodName(inv) + " include a callback service :" + invoker.getUrl() + ", a proxy :" + invoker + " has been created."); } } } else { @@ -307,7 +308,7 @@ public class CallbackServiceCodec { public Object encodeInvocationArgument(Channel channel, RpcInvocation inv, int paraIndex) throws IOException { // get URL directly URL url = inv.getInvoker() == null ? null : inv.getInvoker().getUrl(); - byte callbackStatus = isCallBack(url, inv.getProtocolServiceKey(), inv.getMethodName(), paraIndex); + byte callbackStatus = isCallBack(url, inv.getProtocolServiceKey(), RpcUtils.getMethodName(inv), paraIndex); Object[] args = inv.getArguments(); Class[] pts = inv.getParameterTypes(); switch (callbackStatus) { @@ -334,7 +335,7 @@ public class CallbackServiceCodec { } return inObject; } - byte callbackstatus = isCallBack(url, inv.getProtocolServiceKey(), inv.getMethodName(), paraIndex); + byte callbackstatus = isCallBack(url, inv.getProtocolServiceKey(), RpcUtils.getMethodName(inv), paraIndex); switch (callbackstatus) { case CallbackServiceCodec.CALLBACK_CREATE: try { diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java index 1b1b9a5999..71645f8dc6 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java @@ -81,7 +81,7 @@ class ChannelWrappedInvoker extends AbstractInvoker { try { if (RpcUtils.isOneway(getUrl(), inv)) { // may have concurrency issue - currentClient.send(request, getUrl().getMethodParameter(invocation.getMethodName(), SENT_KEY, false)); + currentClient.send(request, getUrl().getMethodParameter(RpcUtils.getMethodName(invocation), SENT_KEY, false)); return AsyncRpcResult.newDefaultAsyncResult(invocation); } else { CompletableFuture appResponseFuture = currentClient.request(request).thenApply(AppResponse.class::cast); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java index 3f2127c0b5..f23a7a9345 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java @@ -27,6 +27,7 @@ import org.apache.dubbo.common.utils.ReflectUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.Codec; +import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.Decodeable; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.exchange.Request; @@ -119,6 +120,9 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec @Override public Object decode(Channel channel, InputStream input) throws IOException { + int contentLength = input.available(); + getAttributes().put(Constants.CONTENT_LENGTH_KEY, contentLength); + ObjectInput in = CodecSupport.getSerialization(serializationType) .deserialize(channel.getUrl(), input); this.put(SERIALIZATION_ID_KEY, serializationType); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java index ef3b89bb31..ea6f94ed89 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java @@ -27,6 +27,7 @@ import org.apache.dubbo.common.utils.Assert; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.Codec; +import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.Decodeable; import org.apache.dubbo.remoting.exchange.Response; import org.apache.dubbo.remoting.transport.CodecSupport; @@ -82,6 +83,9 @@ public class DecodeableRpcResult extends AppResponse implements Codec, Decodeabl log.debug("Decoding in thread -- [" + thread.getName() + "#" + thread.getId() + "]"); } + int contentLength = input.available(); + setAttribute(Constants.CONTENT_LENGTH_KEY, contentLength); + // switch TCCL if (invocation != null && invocation.getServiceModel() != null) { Thread.currentThread().setContextClassLoader(invocation.getServiceModel().getClassLoader()); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java index 613ee79d58..9dfb716e75 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java @@ -19,10 +19,10 @@ package org.apache.dubbo.rpc.protocol.dubbo; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.Version; import org.apache.dubbo.common.config.ConfigurationUtils; +import org.apache.dubbo.common.serialize.SerializationException; import org.apache.dubbo.common.utils.AtomicPositiveInteger; import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.RemotingException; -import org.apache.dubbo.common.serialize.SerializationException; import org.apache.dubbo.remoting.TimeoutException; import org.apache.dubbo.remoting.exchange.ExchangeClient; import org.apache.dubbo.remoting.exchange.Request; @@ -102,7 +102,7 @@ public class DubboInvoker extends AbstractInvoker { if (timeout <= 0) { return AsyncRpcResult.newDefaultAsyncResult(new RpcException(RpcException.TIMEOUT_TERMINATE, "No time left for making the following call: " + invocation.getServiceName() + "." - + invocation.getMethodName() + ", terminate directly."), invocation); + + RpcUtils.getMethodName(invocation) + ", terminate directly."), invocation); } invocation.setAttachment(TIMEOUT_KEY, String.valueOf(timeout)); @@ -135,9 +135,9 @@ public class DubboInvoker extends AbstractInvoker { return result; } } catch (TimeoutException e) { - throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "Invoke remote method timeout. method: " + invocation.getMethodName() + ", provider: " + getUrl() + ", cause: " + e.getMessage(), e); + throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "Invoke remote method timeout. method: " + RpcUtils.getMethodName(invocation) + ", provider: " + getUrl() + ", cause: " + e.getMessage(), e); } catch (RemotingException e) { - String remoteExpMsg = "Failed to invoke remote method: " + invocation.getMethodName() + ", provider: " + getUrl() + ", cause: " + e.getMessage(); + String remoteExpMsg = "Failed to invoke remote method: " + RpcUtils.getMethodName(invocation) + ", provider: " + getUrl() + ", cause: " + e.getMessage(); if (e.getCause() instanceof IOException && e.getCause().getCause() instanceof SerializationException) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, remoteExpMsg, e); } else { diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java index b35e00d8d9..ce6d89555d 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java @@ -28,11 +28,11 @@ import org.apache.dubbo.rpc.cluster.filter.ClusterFilter; import org.apache.dubbo.rpc.model.AsyncMethodInfo; import org.apache.dubbo.rpc.model.ConsumerModel; import org.apache.dubbo.rpc.model.ServiceModel; +import org.apache.dubbo.rpc.support.RpcUtils; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_REQUEST; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.ASYNC_METHOD_INFO; @@ -180,10 +180,10 @@ public class FutureFilter implements ClusterFilter, ClusterFilter.Listener { } onthrowMethod.invoke(onthrowInst, params); } catch (Throwable e) { - logger.error(PROTOCOL_FAILED_REQUEST, "", "", invocation.getMethodName() + ".call back method invoke error . callback method :" + onthrowMethod + ", url:" + invoker.getUrl(), e); + logger.error(PROTOCOL_FAILED_REQUEST, "", "", RpcUtils.getMethodName(invocation) + ".call back method invoke error . callback method :" + onthrowMethod + ", url:" + invoker.getUrl(), e); } } else { - logger.error(PROTOCOL_FAILED_REQUEST, "", "", invocation.getMethodName() + ".call back method invoke error . callback method :" + onthrowMethod + ", url:" + invoker.getUrl(), exception); + logger.error(PROTOCOL_FAILED_REQUEST, "", "", RpcUtils.getMethodName(invocation) + ".call back method invoke error . callback method :" + onthrowMethod + ", url:" + invoker.getUrl(), exception); } } @@ -198,10 +198,7 @@ public class FutureFilter implements ClusterFilter, ClusterFilter.Listener { return null; } - String methodName = invocation.getMethodName(); - if (methodName.equals($INVOKE)) { - methodName = (String) invocation.getArguments()[0]; - } + String methodName = RpcUtils.getMethodName(invocation); return ((ConsumerModel) serviceModel).getAsyncInfo(methodName); } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java index badd7a6490..f26692e722 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java @@ -32,6 +32,7 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.ArrayList; import java.util.Set; @@ -79,7 +80,7 @@ public class TraceFilter implements Filter { Result result = invoker.invoke(invocation); long end = System.currentTimeMillis(); if (TRACERS.size() > 0) { - String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); + String key = invoker.getInterface().getName() + "." + RpcUtils.getMethodName(invocation); Set channels = TRACERS.get(key); if (CollectionUtils.isEmpty(channels)) { key = invoker.getInterface().getName(); @@ -105,7 +106,7 @@ public class TraceFilter implements Filter { String prompt = channel.getUrl().getParameter(Constants.PROMPT_KEY, Constants.DEFAULT_PROMPT); channel.send("\r\n" + RpcContext.getServiceContext().getRemoteAddress() + " -> " + invoker.getInterface().getName() - + "." + invocation.getMethodName() + + "." + RpcUtils.getMethodName(invocation) + "(" + JsonUtils.toJson(invocation.getArguments()) + ")" + " -> " + JsonUtils.toJson(result.getValue()) + "\r\nelapsed: " + (end - start) + " ms." + "\r\n\r\n" + prompt); diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java index 3f8665c8d6..70cf0b3534 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java @@ -94,7 +94,6 @@ public class InjvmInvoker extends AbstractInvoker { if (exporter == null) { throw new RpcException("Service [" + key + "] not found."); } - RpcContext.getServiceContext().setRemoteAddress(LOCALHOST_VALUE, 0); // Solve local exposure, the server opens the token, and the client call fails. Invoker invoker = exporter.getInvoker(); URL serverURL = invoker.getUrl(); @@ -103,11 +102,11 @@ public class InjvmInvoker extends AbstractInvoker { invocation.setAttachment(Constants.TOKEN_KEY, serverURL.getParameter(Constants.TOKEN_KEY)); } - int timeout = RpcUtils.calculateTimeout(getUrl(), invocation, invocation.getMethodName(), DEFAULT_TIMEOUT); + int timeout = RpcUtils.calculateTimeout(getUrl(), invocation, RpcUtils.getMethodName(invocation), DEFAULT_TIMEOUT); if (timeout <= 0) { return AsyncRpcResult.newDefaultAsyncResult(new RpcException(RpcException.TIMEOUT_TERMINATE, "No time left for making the following call: " + invocation.getServiceName() + "." - + invocation.getMethodName() + ", terminate directly."), invocation); + + RpcUtils.getMethodName(invocation) + ", terminate directly."), invocation); } invocation.setAttachment(TIMEOUT_KEY, String.valueOf(timeout)); @@ -122,16 +121,24 @@ public class InjvmInvoker extends AbstractInvoker { // use consumer executor ExecutorService executor = executorRepository.createExecutorIfAbsent(ExecutorUtil.setThreadName(getUrl(), SERVER_THREAD_POOL_NAME)); CompletableFuture appResponseFuture = CompletableFuture.supplyAsync(() -> { - Result result = invoker.invoke(copiedInvocation); - if (result.hasException()) { - AppResponse appResponse = new AppResponse(result.getException()); - appResponse.setObjectAttachments(new HashMap<>(result.getObjectAttachments())); - return appResponse; - } else { - rebuildValue(invocation, desc, result); - AppResponse appResponse = new AppResponse(result.getValue()); - appResponse.setObjectAttachments(new HashMap<>(result.getObjectAttachments())); - return appResponse; + // clear thread local before child invocation, prevent context pollution + InternalThreadLocalMap originTL = InternalThreadLocalMap.getAndRemove(); + try { + RpcContext.getServiceContext().setRemoteAddress(LOCALHOST_VALUE, 0); + RpcContext.getServiceContext().setRemoteApplicationName(getUrl().getApplication()); + Result result = invoker.invoke(copiedInvocation); + if (result.hasException()) { + AppResponse appResponse = new AppResponse(result.getException()); + appResponse.setObjectAttachments(new HashMap<>(result.getObjectAttachments())); + return appResponse; + } else { + rebuildValue(invocation, desc, result); + AppResponse appResponse = new AppResponse(result.getValue()); + appResponse.setObjectAttachments(new HashMap<>(result.getObjectAttachments())); + return appResponse; + } + } finally { + InternalThreadLocalMap.set(originTL); } }, executor); // save for 2.6.x compatibility, for example, TraceFilter in Zipkin uses com.alibaba.xxx.FutureAdapter @@ -144,6 +151,8 @@ public class InjvmInvoker extends AbstractInvoker { // clear thread local before child invocation, prevent context pollution InternalThreadLocalMap originTL = InternalThreadLocalMap.getAndRemove(); try { + RpcContext.getServiceContext().setRemoteAddress(LOCALHOST_VALUE, 0); + RpcContext.getServiceContext().setRemoteApplicationName(getUrl().getApplication()); result = invoker.invoke(copiedInvocation); } finally { InternalThreadLocalMap.set(originTL); @@ -229,7 +238,7 @@ public class InjvmInvoker extends AbstractInvoker { if (pts != null && args != null && pts.length == args.length) { realArgument = new Object[pts.length]; for (int i = 0; i < pts.length; i++) { - realArgument[i] = paramDeepCopyUtil.copy(invoker.getUrl(), args[i], pts[i]); + realArgument[i] = paramDeepCopyUtil.copy(getUrl(), args[i], pts[i]); } } if (realArgument == null) { diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoService.java b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoService.java index c9d2e63d49..9a09ed9617 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoService.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoService.java @@ -40,4 +40,8 @@ public interface DemoService { Type enumlength(Type... types); String getAsyncResult(); + + String getApplication(); + + String getRemoteAddress(); } diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoServiceImpl.java b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoServiceImpl.java index c59847b298..b4d2314a6d 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoServiceImpl.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoServiceImpl.java @@ -80,4 +80,13 @@ public class DemoServiceImpl implements DemoService { return "DONE"; } + @Override + public String getApplication() { + return RpcContext.getServiceContext().getRemoteApplicationName(); + } + + @Override + public String getRemoteAddress() { + return RpcContext.getServiceContext().getRemoteAddressString(); + } } diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java index 5d4103a840..3ef342e8ea 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java @@ -19,10 +19,13 @@ package org.apache.dubbo.rpc.protocol.injvm; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Exporter; +import org.apache.dubbo.rpc.FutureContext; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.ProxyFactory; +import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.FrameworkModel; @@ -32,7 +35,9 @@ import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.concurrent.ExecutionException; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; @@ -129,7 +134,7 @@ class InjvmProtocolTest { } @Test - void testLocalProtocolAsync() { + void testLocalProtocolAsync() throws ExecutionException, InterruptedException { DemoService service = new DemoServiceImpl(); URL url = URL.valueOf("injvm://127.0.0.1/TestService") .addParameter(ASYNC_KEY, true) @@ -141,6 +146,39 @@ class InjvmProtocolTest { exporters.add(exporter); service = proxy.getProxy(protocol.refer(DemoService.class, url)); assertNull(service.getAsyncResult()); + assertEquals("DONE", FutureContext.getContext().getCompletableFuture().get()); + } + + @Test + void testApplication() { + DemoService service = new DemoServiceImpl(); + URL url = URL.valueOf("injvm://127.0.0.1/TestService") + .addParameter(INTERFACE_KEY, DemoService.class.getName()).addParameter("application", "consumer") + .addParameter(APPLICATION_KEY, "test-app") + .setScopeModel(ApplicationModel.defaultModel().getDefaultModule()); + Invoker invoker = proxy.getInvoker(service, DemoService.class, url); + assertTrue(invoker.isAvailable()); + Exporter exporter = protocol.export(invoker); + exporters.add(exporter); + service = proxy.getProxy(protocol.refer(DemoService.class, url)); + assertEquals("test-app", service.getApplication()); + assertTrue(StringUtils.isEmpty(RpcContext.getServiceContext().getRemoteApplicationName())); + } + + @Test + void testRemoteAddress() { + DemoService service = new DemoServiceImpl(); + URL url = URL.valueOf("injvm://127.0.0.1/TestService") + .addParameter(INTERFACE_KEY, DemoService.class.getName()).addParameter("application", "consumer") + .addParameter(APPLICATION_KEY, "test-app") + .setScopeModel(ApplicationModel.defaultModel().getDefaultModule()); + Invoker invoker = proxy.getInvoker(service, DemoService.class, url); + assertTrue(invoker.isAvailable()); + Exporter exporter = protocol.export(invoker); + exporters.add(exporter); + service = proxy.getProxy(protocol.refer(DemoService.class, url)); + assertEquals("127.0.0.1:0", service.getRemoteAddress()); + assertNull(RpcContext.getServiceContext().getRemoteAddress()); } } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java index b6bad67e5f..cda6a57c22 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java @@ -219,11 +219,11 @@ public class TripleInvoker extends AbstractInvoker { AsyncRpcResult invokeUnary(MethodDescriptor methodDescriptor, Invocation invocation, ClientCall call, Executor callbackExecutor) { - int timeout = RpcUtils.calculateTimeout(getUrl(), invocation, invocation.getMethodName(), 3000); + int timeout = RpcUtils.calculateTimeout(getUrl(), invocation, RpcUtils.getMethodName(invocation), 3000); if (timeout <= 0) { return AsyncRpcResult.newDefaultAsyncResult(new RpcException(RpcException.TIMEOUT_TERMINATE, "No time left for making the following call: " + invocation.getServiceName() + "." - + invocation.getMethodName() + ", terminate directly."), invocation); + + RpcUtils.getMethodName(invocation)+ ", terminate directly."), invocation); } invocation.setAttachment(TIMEOUT_KEY, String.valueOf(timeout)); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriplePathResolver.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriplePathResolver.java index a508e936cf..f3f9ebbc68 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriplePathResolver.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriplePathResolver.java @@ -28,8 +28,13 @@ public class TriplePathResolver implements PathResolver { private final ConcurrentHashMap nativeStub = new ConcurrentHashMap<>(); @Override - public void add(String path, Invoker invoker) { - path2Invoker.put(path, invoker); + public Invoker add(String path, Invoker invoker) { + return path2Invoker.put(path, invoker); + } + + @Override + public Invoker addIfAbsent(String path, Invoker invoker) { + return path2Invoker.putIfAbsent(path, invoker); } @Override diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java index 49650083be..4ec09e4a56 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java @@ -44,9 +44,9 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.ExecutorService; +import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_NAME; import static org.apache.dubbo.rpc.Constants.H2_IGNORE_1_0_0_KEY; import static org.apache.dubbo.rpc.Constants.H2_RESOLVE_FALLBACK_TO_DEFAULT_KEY; -import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_NAME; import static org.apache.dubbo.rpc.Constants.H2_SUPPORT_NO_LOWER_HEADER_KEY; public class TripleProtocol extends AbstractProtocol { @@ -65,7 +65,7 @@ public class TripleProtocol extends AbstractProtocol { public static boolean IGNORE_1_0_0_VERSION = false; - public static boolean RESOLVE_FALLBACK_TO_DEFAULT = false; + public static boolean RESOLVE_FALLBACK_TO_DEFAULT = true; public TripleProtocol(FrameworkModel frameworkModel) { this.frameworkModel = frameworkModel; @@ -77,7 +77,7 @@ public class TripleProtocol extends AbstractProtocol { IGNORE_1_0_0_VERSION = ConfigurationUtils.getEnvConfiguration(ApplicationModel.defaultModel()) .getBoolean(H2_IGNORE_1_0_0_KEY, false); RESOLVE_FALLBACK_TO_DEFAULT = ConfigurationUtils.getEnvConfiguration(ApplicationModel.defaultModel()) - .getBoolean(H2_RESOLVE_FALLBACK_TO_DEFAULT_KEY, false); + .getBoolean(H2_RESOLVE_FALLBACK_TO_DEFAULT_KEY, true); Set supported = frameworkModel.getExtensionLoader(DeCompressor.class) .getSupportedExtensions(); this.acceptEncodings = String.join(",", supported); @@ -113,9 +113,27 @@ public class TripleProtocol extends AbstractProtocol { invokers.add(invoker); - pathResolver.add(url.getServiceKey(), invoker); + Invoker previous = pathResolver.add(url.getServiceKey(), invoker); + if (previous != null) { + if (url.getServiceKey().equals(url.getServiceModel().getServiceModel().getInterfaceName())) { + logger.info("Already exists an invoker[" + previous.getUrl() + "] on path[" + url.getServiceKey() + + "], dubbo will override with invoker[" + url + "]"); + } else { + throw new IllegalStateException("Already exists an invoker[" + previous.getUrl() + "] on path[" + + url.getServiceKey() + "], failed to add invoker[" + url + + "] , please use unique serviceKey."); + } + } if (RESOLVE_FALLBACK_TO_DEFAULT) { - pathResolver.add(url.getServiceModel().getServiceModel().getInterfaceName(), invoker); + previous = pathResolver.addIfAbsent(url.getServiceModel().getServiceModel().getInterfaceName(), invoker); + if (previous != null) { + logger.info("Already exists an invoker[" + previous.getUrl() + "] on path[" + + url.getServiceModel().getServiceModel().getInterfaceName() + + "], dubbo will skip override with invoker[" + url + "]"); + } else { + logger.info("Add fallback triple invoker[" + url + "] to path[" + + url.getServiceModel().getServiceModel().getInterfaceName() + "] with invoker[" + url + "]"); + } } // set service status diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCall.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCall.java index 623e731ec4..8dddc8daf6 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCall.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCall.java @@ -52,8 +52,8 @@ import java.util.concurrent.TimeUnit; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_CREATE_STREAM_TRIPLE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_PARSE; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_SERIALIZE_TRIPLE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_REQUEST; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_SERIALIZE_TRIPLE; public abstract class AbstractServerCall implements ServerCall, ServerStream.Listener { @@ -212,7 +212,7 @@ public abstract class AbstractServerCall implements ServerCall, ServerStream.Lis .getContextClassLoader(); try { Object instance = parseSingleMessage(message); - listener.onMessage(instance); + listener.onMessage(instance, message.length); } catch (Exception e) { final TriRpcStatus status = TriRpcStatus.UNKNOWN.withDescription("Server error") .withCause(e); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/BiStreamServerCallListener.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/BiStreamServerCallListener.java index 754ef77f3c..2d3346b5c6 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/BiStreamServerCallListener.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/BiStreamServerCallListener.java @@ -40,7 +40,7 @@ public class BiStreamServerCallListener extends AbstractServerCallListener { } @Override - public void onMessage(Object message) { + public void onMessage(Object message, int actualContentLength) { if (message instanceof Object[]) { message = ((Object[]) message)[0]; } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ClientCall.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ClientCall.java index 6f5b43b6b8..d99c8c3bf0 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ClientCall.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ClientCall.java @@ -44,8 +44,9 @@ public interface ClientCall { * Callback when message received. * * @param message message received + * @param actualContentLength actual content length from body */ - void onMessage(Object message); + void onMessage(Object message, int actualContentLength); /** * Callback when call is finished. diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ObserverToClientCallListenerAdapter.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ObserverToClientCallListenerAdapter.java index 5d427e05ee..f52bf4e8d1 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ObserverToClientCallListenerAdapter.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ObserverToClientCallListenerAdapter.java @@ -38,7 +38,7 @@ public class ObserverToClientCallListenerAdapter implements ClientCall.Listener } @Override - public void onMessage(Object message) { + public void onMessage(Object message, int actualContentLength) { delegate.onNext(message); if (call.isAutoRequest()) { call.request(1); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerCall.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerCall.java index d43eaab973..45742b9a80 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerCall.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerCall.java @@ -37,8 +37,9 @@ public interface ServerCall { * Callback when a request message is received. * * @param message message received + * @param actualContentLength actual content length from body */ - void onMessage(Object message); + void onMessage(Object message, int actualContentLength); /** * @param status when the call is canceled. diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerStreamServerCallListener.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerStreamServerCallListener.java index d518047321..c6b42e50e2 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerStreamServerCallListener.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerStreamServerCallListener.java @@ -34,7 +34,7 @@ public class ServerStreamServerCallListener extends AbstractServerCallListener { } @Override - public void onMessage(Object message) { + public void onMessage(Object message, int actualContentLength) { if (message instanceof Object[]) { message = ((Object[]) message)[0]; } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java index 59aeede63b..4ba712e843 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java @@ -18,7 +18,6 @@ package org.apache.dubbo.rpc.protocol.tri.call; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; -import io.netty.handler.codec.http2.Http2Exception; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.stream.StreamObserver; import org.apache.dubbo.remoting.api.connection.AbstractConnectionClient; @@ -34,14 +33,15 @@ import org.apache.dubbo.rpc.protocol.tri.stream.TripleClientStream; import org.apache.dubbo.rpc.protocol.tri.transport.TripleWriteQueue; import io.netty.channel.Channel; +import io.netty.handler.codec.http2.Http2Exception; import java.util.Map; import java.util.concurrent.Executor; +import static io.netty.handler.codec.http2.Http2Error.FLOW_CONTROL_ERROR; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_RESPONSE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_SERIALIZE_TRIPLE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_STREAM_LISTENER; -import static io.netty.handler.codec.http2.Http2Error.FLOW_CONTROL_ERROR; public class TripleClientCall implements ClientCall, ClientStream.Listener { private static final ErrorTypeAwareLogger LOGGER = LoggerFactory.getErrorTypeAwareLogger(TripleClientCall.class); @@ -78,7 +78,7 @@ public class TripleClientCall implements ClientCall, ClientStream.Listener { } try { final Object unpacked = requestMetadata.packableMethod.parseResponse(message, isReturnTriException); - listener.onMessage(unpacked); + listener.onMessage(unpacked, message.length); } catch (Throwable t) { TriRpcStatus status = TriRpcStatus.INTERNAL.withDescription("Deserialize response failed") .withCause(t); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryClientCallListener.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryClientCallListener.java index 57dbb625f8..b08ee0618f 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryClientCallListener.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryClientCallListener.java @@ -17,6 +17,7 @@ package org.apache.dubbo.rpc.protocol.tri.call; +import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.rpc.AppResponse; import org.apache.dubbo.rpc.TriRpcStatus; import org.apache.dubbo.rpc.protocol.tri.DeadlineFuture; @@ -27,14 +28,16 @@ public class UnaryClientCallListener implements ClientCall.Listener { private final DeadlineFuture future; private Object appResponse; + private int actualContentLength; public UnaryClientCallListener(DeadlineFuture deadlineFuture) { this.future = deadlineFuture; } @Override - public void onMessage(Object message) { + public void onMessage(Object message, int actualContentLength) { this.appResponse = message; + this.actualContentLength = actualContentLength; } @Override @@ -50,6 +53,7 @@ public class UnaryClientCallListener implements ClientCall.Listener { } else { result.setException(status.asException()); } + result.setAttribute(Constants.CONTENT_LENGTH_KEY, actualContentLength); future.received(status, result); } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryServerCallListener.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryServerCallListener.java index 36011c5b3f..e53b72079a 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryServerCallListener.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryServerCallListener.java @@ -17,6 +17,7 @@ package org.apache.dubbo.rpc.protocol.tri.call; +import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcInvocation; @@ -40,12 +41,13 @@ public class UnaryServerCallListener extends AbstractServerCallListener { } @Override - public void onMessage(Object message) { + public void onMessage(Object message, int actualContentLength) { if (message instanceof Object[]) { invocation.setArguments((Object[]) message); } else { invocation.setArguments(new Object[]{message}); } + invocation.put(Constants.CONTENT_LENGTH_KEY, actualContentLength); } @Override diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml index 17343de508..77065023c9 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml @@ -38,8 +38,8 @@ - 1.11.0 - 1.1.1 + 1.11.1 + 1.1.2 1.27.0 2.16.4 0.16.0 diff --git a/dubbo-xds/src/main/java/org/apache/dubbo/rpc/cluster/router/xds/XdsRouter.java b/dubbo-xds/src/main/java/org/apache/dubbo/rpc/cluster/router/xds/XdsRouter.java index 299fcd6417..c994a219ad 100644 --- a/dubbo-xds/src/main/java/org/apache/dubbo/rpc/cluster/router/xds/XdsRouter.java +++ b/dubbo-xds/src/main/java/org/apache/dubbo/rpc/cluster/router/xds/XdsRouter.java @@ -16,15 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.router.xds; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ThreadLocalRandom; -import java.util.stream.Collectors; - import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.ConcurrentHashSet; @@ -45,6 +36,16 @@ import org.apache.dubbo.rpc.cluster.router.xds.rule.HeaderMatcher; import org.apache.dubbo.rpc.cluster.router.xds.rule.HttpRequestMatch; import org.apache.dubbo.rpc.cluster.router.xds.rule.PathMatcher; import org.apache.dubbo.rpc.cluster.router.xds.rule.XdsRouteRule; +import org.apache.dubbo.rpc.support.RpcUtils; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ThreadLocalRandom; +import java.util.stream.Collectors; public class XdsRouter extends AbstractStateRouter implements XdsRouteRuleListener, EdsEndpointListener { @@ -171,7 +172,7 @@ public class XdsRouter extends AbstractStateRouter implements XdsRouteRule } PathMatcher pathMatcher = requestMatch.getPathMatcher(); if (pathMatcher != null) { - String path = "/" + invocation.getInvoker().getUrl().getPath() + "/" + invocation.getMethodName(); + String path = "/" + invocation.getInvoker().getUrl().getPath() + "/" + RpcUtils.getMethodName(invocation); if (!pathMatcher.isMatch(path)) { return null; }