Skip to content

Commit

Permalink
Ehance gRPC protocol and configurator reExport procedure (apache#5423)
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenlj authored Dec 5, 2019
1 parent 083748d commit 1cd29b6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@
import java.util.Map;
import java.util.Set;

import static org.apache.dubbo.rpc.cluster.Constants.CONFIG_VERSION_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.OVERRIDE_PROVIDERS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACES;
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.COMPATIBLE_CONFIG_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.CONFIG_VERSION_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.OVERRIDE_PROVIDERS_KEY;

/**
* AbstractOverrideConfigurator
Expand Down Expand Up @@ -128,6 +129,7 @@ private URL configureIfMatch(String host, URL url) {
conditionKeys.add(SIDE_KEY);
conditionKeys.add(CONFIG_VERSION_KEY);
conditionKeys.add(COMPATIBLE_CONFIG_KEY);
conditionKeys.add(INTERFACES);
for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,6 @@ public interface CommonConstants {

String DUBBO_INVOCATION_PREFIX = "_DUBBO_IGNORE_ATTACH_";

String INTERFACES = "interfaces";

}
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ public synchronized void doOverrideIfNecessary() {
//The current, may have been merged many times
URL currentUrl = exporter.getInvoker().getUrl();
//Merged with this configuration
URL newUrl = getConfigedInvokerUrl(configurators, originUrl);
URL newUrl = getConfigedInvokerUrl(configurators, currentUrl);
newUrl = getConfigedInvokerUrl(providerConfigurationListener.getConfigurators(), newUrl);
newUrl = getConfigedInvokerUrl(serviceConfigurationListeners.get(originUrl.getServiceKey())
.getConfigurators(), newUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.ReferenceConfigBase;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.ProtocolServer;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ProviderModel;
Expand All @@ -44,8 +40,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import static org.apache.dubbo.rpc.Constants.INTERFACES;

/**
*
*/
Expand Down Expand Up @@ -101,11 +95,6 @@ protected <T> Runnable doExport(T proxiedImpl, Class<T> type, URL url) throws Rp
return () -> grpcServer.getRegistry().removeService(url.getServiceKey());
}

@Override
public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
return super.export(new GrpcServerProxyInvoker<>(invoker));
}

@Override
protected <T> Invoker<T> protocolBindingRefer(final Class<T> type, final URL url) throws RpcException {
Class<?> enclosingClass = type.getEnclosingClass();
Expand Down Expand Up @@ -211,50 +200,4 @@ public void close() {
}
}

/**
* TODO, If IGreeter extends BindableService we can avoid the existence of this wrapper invoker.
*
* @param <T>
*/
private class GrpcServerProxyInvoker<T> implements Invoker<T> {

private Invoker<T> invoker;

public GrpcServerProxyInvoker(Invoker<T> invoker) {
this.invoker = invoker;
}

@Override
public Class<T> getInterface() {
return invoker.getInterface();
}

@Override
public Result invoke(Invocation invocation) throws RpcException {
return invoker.invoke(invocation);
}

@Override
public URL getUrl() {
URL url = invoker.getUrl();
String interfaces = url.getParameter(INTERFACES);
if (StringUtils.isNotEmpty(interfaces)) {
interfaces += ("," + BindableService.class.getName());
} else {
interfaces = BindableService.class.getName();
}
return url.addParameter(INTERFACES, interfaces);
}

@Override
public boolean isAvailable() {
return invoker.isAvailable();
}

@Override
public void destroy() {
invoker.destroy();
}
}

}

0 comments on commit 1cd29b6

Please sign in to comment.