Merge branch 'remove_jdk_ser' of https://github.com/wcy666103/dubbo into remove_jdk_ser

This commit is contained in:
王聪洋 2024-06-25 14:52:42 +08:00
commit fdb82ec7e3
26 changed files with 3984 additions and 117 deletions

View File

@ -295,6 +295,27 @@ public class ApplicationConfig extends AbstractConfig {
*/
private String executorManagementMode;
/**
* Only use the new version of metadataService (MetadataServiceV2).
* <br> MetadataServiceV2 have better compatibility with other language's dubbo implement (dubbo-go).
* <br> If set to false (default):
* <br> 1. If your services are using triple protocol and {@link #metadataServiceProtocol} is not set
* <br> - Dubbo will export both MetadataService and MetadataServiceV2 with triple
* <br> 2. Set {@link #metadataServiceProtocol} = tri
* <br> - Dubbo will export both MetadataService and MetadataServiceV2 with triple
* <br> 3. Set {@link #metadataServiceProtocol} != tri
* <br> - Dubbo will only export MetadataService
* <br> 4. Your services are not using triple protocol, and {@link #metadataServiceProtocol} is not set
* <br> - Dubbo will only export MetadataService
* <br>
* <br> If set to true, dubbo will try to only use MetadataServiceV2.
* <br> It only activates when meet at least one of the following cases:
* <br> 1. Manually set {@link #metadataServiceProtocol} = tri
* <br> 2. Your services are using triple protocol
* <br>
*/
private Boolean onlyUseMetadataV2;
public ApplicationConfig() {}
public ApplicationConfig(ApplicationModel applicationModel) {
@ -794,6 +815,15 @@ public class ApplicationConfig extends AbstractConfig {
return executorManagementMode;
}
@Parameter(excluded = true)
public Boolean getOnlyUseMetadataV2() {
return onlyUseMetadataV2;
}
public void setOnlyUseMetadataV2(Boolean onlyUseMetadataV2) {
this.onlyUseMetadataV2 = onlyUseMetadataV2;
}
@Override
public void refresh() {
super.refresh();

View File

@ -188,7 +188,8 @@ public class ModuleModel extends ScopeModel {
this.moduleEnvironment = moduleEnvironment;
}
public ConsumerModel registerInternalConsumer(Class<?> internalService, URL url) {
public ConsumerModel registerInternalConsumer(
Class<?> internalService, URL url, ServiceDescriptor serviceDescriptor, Object proxyObject) {
ServiceMetadata serviceMetadata = new ServiceMetadata();
serviceMetadata.setVersion(url.getVersion());
serviceMetadata.setGroup(url.getGroup());
@ -197,11 +198,12 @@ public class ModuleModel extends ScopeModel {
serviceMetadata.setServiceType(internalService);
String serviceKey = URL.buildKey(internalService.getName(), url.getGroup(), url.getVersion());
serviceMetadata.setServiceKey(serviceKey);
ConsumerModel consumerModel = new ConsumerModel(
serviceMetadata.getServiceKey(),
"jdk",
serviceRepository.lookupService(serviceMetadata.getServiceInterfaceName()),
proxyObject,
serviceDescriptor == null
? serviceRepository.lookupService(serviceMetadata.getServiceInterfaceName())
: serviceDescriptor,
this,
serviceMetadata,
new HashMap<>(0),
@ -212,6 +214,15 @@ public class ModuleModel extends ScopeModel {
return consumerModel;
}
public ConsumerModel registerInternalConsumer(
Class<?> internalService, URL url, ServiceDescriptor serviceDescriptor) {
return registerInternalConsumer(internalService, url, serviceDescriptor, null);
}
public ConsumerModel registerInternalConsumer(Class<?> internalService, URL url) {
return registerInternalConsumer(internalService, url, null, null);
}
public boolean isLifeCycleManagedExternally() {
return lifeCycleManagedExternally;
}

View File

@ -43,7 +43,11 @@ public class ServiceRepository {
.getSupportedExtensionInstances();
if (CollectionUtils.isNotEmpty(builtinServices)) {
for (BuiltinServiceDetector service : builtinServices) {
applicationModel.getInternalModule().getServiceRepository().registerService(service.getService());
Class<?> serviceClass = service.getService();
if (serviceClass == null) {
continue;
}
applicationModel.getInternalModule().getServiceRepository().registerService(serviceClass);
}
}
}

View File

@ -61,6 +61,7 @@ public class InternalServiceConfigBuilder<T> {
private Class<T> interfaceClass;
private Executor executor;
private T ref;
private String version;
private InternalServiceConfigBuilder(ApplicationModel applicationModel) {
this.applicationModel = applicationModel;
@ -103,6 +104,11 @@ public class InternalServiceConfigBuilder<T> {
return getThis();
}
public InternalServiceConfigBuilder<T> version(String version) {
this.version = version;
return getThis();
}
/**
* Get other configured protocol from environment in priority order. If get nothing, use default dubbo.
*
@ -296,7 +302,12 @@ public class InternalServiceConfigBuilder<T> {
serviceConfig.setInterface(interfaceClass);
serviceConfig.setRef(this.ref);
serviceConfig.setGroup(applicationConfig.getName());
serviceConfig.setVersion("1.0.0");
if (StringUtils.isNotEmpty(version)) {
serviceConfig.setVersion(version);
} else {
serviceConfig.setVersion("1.0.0");
}
serviceConfig.setFilter("-default");
serviceConfig.setExecutor(executor);

View File

@ -16,7 +16,6 @@
*/
package org.apache.dubbo.config.metadata;
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.threadpool.manager.FrameworkExecutorRepository;
@ -26,17 +25,22 @@ import org.apache.dubbo.config.MethodConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.bootstrap.builders.InternalServiceConfigBuilder;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.MetadataServiceV2;
import org.apache.dubbo.metadata.util.MetadataServiceVersionUtils;
import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation;
import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegationV2;
import org.apache.dubbo.rpc.model.ApplicationModel;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import static java.util.Collections.emptyList;
import static org.apache.dubbo.common.constants.CommonConstants.METADATA_SERVICE_PORT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.METADATA_SERVICE_PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TRIPLE;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_METADATA_SERVICE_EXPORTED;
import static org.apache.dubbo.metadata.util.MetadataServiceVersionUtils.V1;
import static org.apache.dubbo.metadata.util.MetadataServiceVersionUtils.V2;
/**
* Export metadata service
@ -45,39 +49,34 @@ public class ConfigurableMetadataServiceExporter {
private final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass());
private MetadataServiceDelegation metadataService;
@Deprecated
private final MetadataServiceDelegation metadataService;
private final MetadataServiceDelegationV2 metadataServiceV2;
@Deprecated
private volatile ServiceConfig<MetadataService> serviceConfig;
private volatile ServiceConfig<MetadataServiceV2> serviceConfigV2;
private final ApplicationModel applicationModel;
public ConfigurableMetadataServiceExporter(
ApplicationModel applicationModel, MetadataServiceDelegation metadataService) {
ApplicationModel applicationModel,
MetadataServiceDelegation metadataService,
MetadataServiceDelegationV2 metadataServiceV2) {
this.applicationModel = applicationModel;
this.metadataService = metadataService;
this.metadataServiceV2 = metadataServiceV2;
}
public synchronized ConfigurableMetadataServiceExporter export() {
if (serviceConfig == null || !isExported()) {
ExecutorService internalServiceExecutor = applicationModel
.getFrameworkModel()
.getBeanFactory()
.getBean(FrameworkExecutorRepository.class)
.getInternalServiceExecutor();
this.serviceConfig = InternalServiceConfigBuilder.<MetadataService>newBuilder(applicationModel)
.interfaceClass(MetadataService.class)
.protocol(getApplicationConfig().getMetadataServiceProtocol(), METADATA_SERVICE_PROTOCOL_KEY)
.port(getApplicationConfig().getMetadataServicePort(), METADATA_SERVICE_PORT_KEY)
.registryId("internal-metadata-registry")
.executor(internalServiceExecutor)
.ref(metadataService)
.build(configConsumer -> configConsumer.setMethods(generateMethodConfig()));
// export
serviceConfig.export();
metadataService.setMetadataURL(serviceConfig.getExportedUrls().get(0));
if (logger.isInfoEnabled()) {
logger.info("The MetadataService exports urls : " + serviceConfig.getExportedUrls());
if (MetadataServiceVersionUtils.needExportV1(applicationModel)) {
exportV1();
}
if (MetadataServiceVersionUtils.needExportV2(applicationModel)) {
exportV2();
}
} else {
if (logger.isWarnEnabled()) {
@ -92,18 +91,77 @@ public class ConfigurableMetadataServiceExporter {
return this;
}
private static final String INTERNAL_METADATA_REGISTRY_ID = "internal-metadata-registry";
private void exportV1() {
ExecutorService internalServiceExecutor = applicationModel
.getFrameworkModel()
.getBeanFactory()
.getBean(FrameworkExecutorRepository.class)
.getInternalServiceExecutor();
this.serviceConfig = InternalServiceConfigBuilder.<MetadataService>newBuilder(applicationModel)
.interfaceClass(MetadataService.class)
.protocol(getApplicationConfig().getMetadataServiceProtocol(), METADATA_SERVICE_PROTOCOL_KEY)
.port(getApplicationConfig().getMetadataServicePort(), METADATA_SERVICE_PORT_KEY)
.registryId(INTERNAL_METADATA_REGISTRY_ID)
.executor(internalServiceExecutor)
.ref(metadataService)
.version(V1)
.build(configConsumer -> configConsumer.setMethods(generateMethodConfig()));
serviceConfig.export();
metadataService.setMetadataURL(serviceConfig.getExportedUrls().get(0));
if (logger.isInfoEnabled()) {
logger.info("The MetadataService exports urls : " + serviceConfig.getExportedUrls());
}
}
private void exportV2() {
ExecutorService internalServiceExecutor = applicationModel
.getFrameworkModel()
.getBeanFactory()
.getBean(FrameworkExecutorRepository.class)
.getInternalServiceExecutor();
this.serviceConfigV2 = InternalServiceConfigBuilder.<MetadataServiceV2>newBuilder(applicationModel)
.interfaceClass(MetadataServiceV2.class)
.protocol(TRIPLE, METADATA_SERVICE_PROTOCOL_KEY)
.port(getApplicationConfig().getMetadataServicePort(), METADATA_SERVICE_PORT_KEY)
.registryId(INTERNAL_METADATA_REGISTRY_ID)
.executor(internalServiceExecutor)
.ref(metadataServiceV2)
.version(V2)
.build();
serviceConfigV2.export();
metadataServiceV2.setMetadataUrl(serviceConfigV2.getExportedUrls().get(0));
if (logger.isInfoEnabled()) {
logger.info("The MetadataServiceV2 exports urls : " + serviceConfigV2.getExportedUrls());
}
}
public ConfigurableMetadataServiceExporter unexport() {
if (isExported()) {
serviceConfig.unexport();
serviceConfigV2.unexport();
metadataService.setMetadataURL(null);
}
return this;
}
public boolean isExported() {
private boolean v1Exported() {
return serviceConfig != null && serviceConfig.isExported() && !serviceConfig.isUnexported();
}
private boolean v2Exported() {
return serviceConfigV2 != null && serviceConfigV2.isExported() && !serviceConfigV2.isUnexported();
}
public boolean isExported() {
return v1Exported() || v2Exported();
}
private ApplicationConfig getApplicationConfig() {
return applicationModel.getApplicationConfigManager().getApplication().get();
}
@ -129,14 +187,4 @@ public class ConfigurableMetadataServiceExporter {
return Collections.singletonList(methodConfig);
}
// for unit test
public void setMetadataService(MetadataServiceDelegation metadataService) {
this.metadataService = metadataService;
}
// for unit test
public List<URL> getExportedURLs() {
return serviceConfig != null ? serviceConfig.getExportedUrls() : emptyList();
}
}

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.deploy.ApplicationDeployListener;
import org.apache.dubbo.common.lang.Prioritized;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation;
import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegationV2;
import org.apache.dubbo.rpc.model.ApplicationModel;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE;
@ -78,10 +79,16 @@ public class ExporterDeployListener implements ApplicationDeployListener, Priori
@Override
public synchronized void onModuleStarted(ApplicationModel applicationModel) {
// start metadata service exporter
@Deprecated
MetadataServiceDelegation metadataService =
applicationModel.getBeanFactory().getOrRegisterBean(MetadataServiceDelegation.class);
MetadataServiceDelegationV2 metadataServiceV2 =
applicationModel.getBeanFactory().getOrRegisterBean(MetadataServiceDelegationV2.class);
if (metadataServiceExporter == null) {
metadataServiceExporter = new ConfigurableMetadataServiceExporter(applicationModel, metadataService);
metadataServiceExporter =
new ConfigurableMetadataServiceExporter(applicationModel, metadataService, metadataServiceV2);
// fixme, let's disable local metadata service export at this moment
if (!REMOTE_METADATA_STORAGE_TYPE.equals(getMetadataType(applicationModel))
&& !INTERFACE_REGISTER_MODE.equals(getRegisterMode(applicationModel))) {

View File

@ -20,8 +20,12 @@ import org.apache.dubbo.common.BaseServiceMetadata;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.MetadataServiceV2;
import org.apache.dubbo.metadata.util.MetadataServiceVersionUtils;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.client.ServiceInstanceCustomizer;
import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation;
import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegationV2;
import org.apache.dubbo.registry.client.metadata.SpringCloudMetadataServiceURLBuilder;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ModuleServiceRepository;
@ -32,6 +36,7 @@ import java.util.Map;
import static org.apache.dubbo.common.utils.StringUtils.isBlank;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_VERSION_NAME;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataServiceParameter;
/**
@ -41,15 +46,26 @@ public class MetadataServiceURLParamsMetadataCustomizer implements ServiceInstan
@Override
public void customize(ServiceInstance serviceInstance, ApplicationModel applicationModel) {
Map<String, String> metadata = serviceInstance.getMetadata();
String propertyName = resolveMetadataPropertyName(serviceInstance);
String propertyValue = resolveMetadataPropertyValue(applicationModel);
if (!isBlank(propertyName) && !isBlank(propertyValue)) {
metadata.put(propertyName, propertyValue);
}
String version = resolveMetadataServiceVersion(applicationModel);
metadata.put(METADATA_SERVICE_VERSION_NAME, version);
}
public static String resolveMetadataServiceVersion(ApplicationModel applicationModel) {
boolean needExportV2 = MetadataServiceVersionUtils.needExportV2(applicationModel);
String version;
if (needExportV2) {
version = MetadataServiceDelegationV2.VERSION;
} else {
version = MetadataServiceDelegation.VERSION;
}
return version;
}
private String resolveMetadataPropertyName(ServiceInstance serviceInstance) {
@ -59,8 +75,20 @@ public class MetadataServiceURLParamsMetadataCustomizer implements ServiceInstan
private String resolveMetadataPropertyValue(ApplicationModel applicationModel) {
ModuleServiceRepository serviceRepository =
applicationModel.getInternalModule().getServiceRepository();
String key = BaseServiceMetadata.buildServiceKey(
MetadataService.class.getName(), applicationModel.getApplicationName(), MetadataService.VERSION);
String key;
if (MetadataServiceVersionUtils.needExportV2(applicationModel)) {
key = BaseServiceMetadata.buildServiceKey(
MetadataServiceV2.class.getName(),
applicationModel.getApplicationName(),
MetadataServiceDelegationV2.VERSION);
} else {
// If MetadataService and MetadataServiceV2 are both exported, use v1 path for capacity.
// Client will use version and protocol to judge if it needs to refer v2 path.
key = BaseServiceMetadata.buildServiceKey(
MetadataService.class.getName(), applicationModel.getApplicationName(), MetadataService.VERSION);
}
ProviderModel providerModel = serviceRepository.lookupExportedService(key);
String metadataValue = "";
if (providerModel != null) {

View File

@ -74,6 +74,11 @@
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-triple</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,200 @@
/*
* 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.metadata;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.PathResolver;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.ServerService;
import org.apache.dubbo.rpc.TriRpcStatus;
import org.apache.dubbo.rpc.model.MethodDescriptor;
import org.apache.dubbo.rpc.model.ServiceDescriptor;
import org.apache.dubbo.rpc.model.StubMethodDescriptor;
import org.apache.dubbo.rpc.model.StubServiceDescriptor;
import org.apache.dubbo.rpc.stub.StubInvocationUtil;
import org.apache.dubbo.rpc.stub.StubInvoker;
import org.apache.dubbo.rpc.stub.StubMethodHandler;
import org.apache.dubbo.rpc.stub.StubSuppliers;
import org.apache.dubbo.rpc.stub.UnaryStubMethodHandler;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import com.google.protobuf.Message;
public final class DubboMetadataServiceV2Triple {
public static final String SERVICE_NAME = MetadataServiceV2.SERVICE_NAME;
private static final StubServiceDescriptor serviceDescriptor =
new StubServiceDescriptor(SERVICE_NAME, MetadataServiceV2.class);
static {
org.apache.dubbo.rpc.protocol.tri.service.SchemaDescriptorRegistry.addSchemaDescriptor(
SERVICE_NAME, MetadataServiceV2OuterClass.getDescriptor());
StubSuppliers.addSupplier(SERVICE_NAME, DubboMetadataServiceV2Triple::newStub);
StubSuppliers.addSupplier(MetadataServiceV2.JAVA_SERVICE_NAME, DubboMetadataServiceV2Triple::newStub);
StubSuppliers.addDescriptor(SERVICE_NAME, serviceDescriptor);
StubSuppliers.addDescriptor(MetadataServiceV2.JAVA_SERVICE_NAME, serviceDescriptor);
}
@SuppressWarnings("all")
public static MetadataServiceV2 newStub(Invoker<?> invoker) {
return new MetadataServiceV2Stub((Invoker<MetadataServiceV2>) invoker);
}
private static final StubMethodDescriptor getMetadataInfoMethod = new StubMethodDescriptor(
"GetMetadataInfo",
Revision.class,
MetadataInfoV2.class,
MethodDescriptor.RpcType.UNARY,
obj -> ((Message) obj).toByteArray(),
obj -> ((Message) obj).toByteArray(),
Revision::parseFrom,
MetadataInfoV2::parseFrom);
private static final StubMethodDescriptor getMetadataInfoAsyncMethod = new StubMethodDescriptor(
"GetMetadataInfo",
Revision.class,
CompletableFuture.class,
MethodDescriptor.RpcType.UNARY,
obj -> ((Message) obj).toByteArray(),
obj -> ((Message) obj).toByteArray(),
Revision::parseFrom,
MetadataInfoV2::parseFrom);
private static final StubMethodDescriptor getMetadataInfoProxyAsyncMethod = new StubMethodDescriptor(
"GetMetadataInfoAsync",
Revision.class,
MetadataInfoV2.class,
MethodDescriptor.RpcType.UNARY,
obj -> ((Message) obj).toByteArray(),
obj -> ((Message) obj).toByteArray(),
Revision::parseFrom,
MetadataInfoV2::parseFrom);
static {
serviceDescriptor.addMethod(getMetadataInfoMethod);
serviceDescriptor.addMethod(getMetadataInfoProxyAsyncMethod);
}
public static class MetadataServiceV2Stub implements MetadataServiceV2 {
private final Invoker<MetadataServiceV2> invoker;
public MetadataServiceV2Stub(Invoker<MetadataServiceV2> invoker) {
this.invoker = invoker;
}
@Override
public MetadataInfoV2 getMetadataInfo(Revision request) {
return StubInvocationUtil.unaryCall(invoker, getMetadataInfoMethod, request);
}
public CompletableFuture<MetadataInfoV2> getMetadataInfoAsync(Revision request) {
return StubInvocationUtil.unaryCall(invoker, getMetadataInfoAsyncMethod, request);
}
public void getMetadataInfo(Revision request, StreamObserver<MetadataInfoV2> responseObserver) {
StubInvocationUtil.unaryCall(invoker, getMetadataInfoMethod, request, responseObserver);
}
}
public abstract static class MetadataServiceV2ImplBase
implements MetadataServiceV2, ServerService<MetadataServiceV2> {
private <T, R> BiConsumer<T, StreamObserver<R>> syncToAsync(java.util.function.Function<T, R> syncFun) {
return new BiConsumer<T, StreamObserver<R>>() {
@Override
public void accept(T t, StreamObserver<R> observer) {
try {
R ret = syncFun.apply(t);
observer.onNext(ret);
observer.onCompleted();
} catch (Throwable e) {
observer.onError(e);
}
}
};
}
@Override
public CompletableFuture<MetadataInfoV2> getMetadataInfoAsync(Revision request) {
return CompletableFuture.completedFuture(getMetadataInfo(request));
}
/**
* This server stream type unary method is <b>only</b> used for generated stub to support async unary method.
* It will not be called if you are NOT using Dubbo3 generated triple stub and <b>DO NOT</b> implement this method.
*/
public void getMetadataInfo(Revision request, StreamObserver<MetadataInfoV2> responseObserver) {
getMetadataInfoAsync(request).whenComplete((r, t) -> {
if (t != null) {
responseObserver.onError(t);
} else {
responseObserver.onNext(r);
responseObserver.onCompleted();
}
});
}
@Override
public final Invoker<MetadataServiceV2> getInvoker(URL url) {
PathResolver pathResolver = url.getOrDefaultFrameworkModel()
.getExtensionLoader(PathResolver.class)
.getDefaultExtension();
Map<String, StubMethodHandler<?, ?>> handlers = new HashMap<>();
pathResolver.addNativeStub("/" + SERVICE_NAME + "/GetMetadataInfo");
pathResolver.addNativeStub("/" + SERVICE_NAME + "/GetMetadataInfoAsync");
// for compatibility
pathResolver.addNativeStub("/" + JAVA_SERVICE_NAME + "/GetMetadataInfo");
pathResolver.addNativeStub("/" + JAVA_SERVICE_NAME + "/GetMetadataInfoAsync");
BiConsumer<Revision, StreamObserver<MetadataInfoV2>> getMetadataInfoFunc = this::getMetadataInfo;
handlers.put(getMetadataInfoMethod.getMethodName(), new UnaryStubMethodHandler<>(getMetadataInfoFunc));
BiConsumer<Revision, StreamObserver<MetadataInfoV2>> getMetadataInfoAsyncFunc =
syncToAsync(this::getMetadataInfo);
handlers.put(
getMetadataInfoProxyAsyncMethod.getMethodName(),
new UnaryStubMethodHandler<>(getMetadataInfoAsyncFunc));
return new StubInvoker<>(this, url, MetadataServiceV2.class, handlers);
}
@Override
public MetadataInfoV2 getMetadataInfo(Revision request) {
throw unimplementedMethodException(getMetadataInfoMethod);
}
@Override
public final ServiceDescriptor getServiceDescriptor() {
return serviceDescriptor;
}
private RpcException unimplementedMethodException(StubMethodDescriptor methodDescriptor) {
return TriRpcStatus.UNIMPLEMENTED
.withDescription(String.format(
"Method %s is unimplemented",
"/" + serviceDescriptor.getInterfaceName() + "/" + methodDescriptor.getMethodName()))
.asException();
}
}
}

View File

@ -0,0 +1,895 @@
/*
* 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.metadata;
/**
* Protobuf type {@code org.apache.dubbo.metadata.MetadataInfoV2}
*/
public final class MetadataInfoV2 extends com.google.protobuf.GeneratedMessageV3
implements
// @@protoc_insertion_point(message_implements:org.apache.dubbo.metadata.MetadataInfoV2)
MetadataInfoV2OrBuilder {
private static final long serialVersionUID = 0L;
// Use MetadataInfoV2.newBuilder() to construct.
private MetadataInfoV2(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private MetadataInfoV2() {
app_ = "";
version_ = "";
}
@Override
@SuppressWarnings({"unused"})
protected Object newInstance(UnusedPrivateParameter unused) {
return new MetadataInfoV2();
}
public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() {
return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor;
}
@SuppressWarnings({"rawtypes"})
@Override
protected com.google.protobuf.MapField internalGetMapField(int number) {
switch (number) {
case 3:
return internalGetServices();
default:
throw new RuntimeException("Invalid map field number: " + number);
}
}
@Override
protected FieldAccessorTable internalGetFieldAccessorTable() {
return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_MetadataInfoV2_fieldAccessorTable
.ensureFieldAccessorsInitialized(MetadataInfoV2.class, Builder.class);
}
public static final int APP_FIELD_NUMBER = 1;
@SuppressWarnings("serial")
private volatile Object app_ = "";
/**
* <code>string app = 1;</code>
* @return The app.
*/
@Override
public String getApp() {
Object ref = app_;
if (ref instanceof String) {
return (String) ref;
} else {
com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
app_ = s;
return s;
}
}
/**
* <code>string app = 1;</code>
* @return The bytes for app.
*/
@Override
public com.google.protobuf.ByteString getAppBytes() {
Object ref = app_;
if (ref instanceof String) {
com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref);
app_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int VERSION_FIELD_NUMBER = 2;
@SuppressWarnings("serial")
private volatile Object version_ = "";
/**
* <code>string version = 2;</code>
* @return The version.
*/
@Override
public String getVersion() {
Object ref = version_;
if (ref instanceof String) {
return (String) ref;
} else {
com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
version_ = s;
return s;
}
}
/**
* <code>string version = 2;</code>
* @return The bytes for version.
*/
@Override
public com.google.protobuf.ByteString getVersionBytes() {
Object ref = version_;
if (ref instanceof String) {
com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref);
version_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int SERVICES_FIELD_NUMBER = 3;
private static final class ServicesDefaultEntryHolder {
static final com.google.protobuf.MapEntry<String, ServiceInfoV2> defaultEntry =
com.google.protobuf.MapEntry.<String, ServiceInfoV2>newDefaultInstance(
MetadataServiceV2OuterClass
.internal_static_org_apache_dubbo_metadata_MetadataInfoV2_ServicesEntry_descriptor,
com.google.protobuf.WireFormat.FieldType.STRING,
"",
com.google.protobuf.WireFormat.FieldType.MESSAGE,
ServiceInfoV2.getDefaultInstance());
}
@SuppressWarnings("serial")
private com.google.protobuf.MapField<String, ServiceInfoV2> services_;
private com.google.protobuf.MapField<String, ServiceInfoV2> internalGetServices() {
if (services_ == null) {
return com.google.protobuf.MapField.emptyMapField(ServicesDefaultEntryHolder.defaultEntry);
}
return services_;
}
public int getServicesCount() {
return internalGetServices().getMap().size();
}
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
@Override
public boolean containsServices(String key) {
if (key == null) {
throw new NullPointerException("map key");
}
return internalGetServices().getMap().containsKey(key);
}
/**
* Use {@link #getServicesMap()} instead.
*/
@Override
@Deprecated
public java.util.Map<String, ServiceInfoV2> getServices() {
return getServicesMap();
}
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
@Override
public java.util.Map<String, ServiceInfoV2> getServicesMap() {
return internalGetServices().getMap();
}
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
@Override
public /* nullable */ ServiceInfoV2 getServicesOrDefault(
String key,
/* nullable */
ServiceInfoV2 defaultValue) {
if (key == null) {
throw new NullPointerException("map key");
}
java.util.Map<String, ServiceInfoV2> map = internalGetServices().getMap();
return map.containsKey(key) ? map.get(key) : defaultValue;
}
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
@Override
public ServiceInfoV2 getServicesOrThrow(String key) {
if (key == null) {
throw new NullPointerException("map key");
}
java.util.Map<String, ServiceInfoV2> map = internalGetServices().getMap();
if (!map.containsKey(key)) {
throw new IllegalArgumentException();
}
return map.get(key);
}
private byte memoizedIsInitialized = -1;
@Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@Override
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException {
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(app_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, app_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(version_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, version_);
}
com.google.protobuf.GeneratedMessageV3.serializeStringMapTo(
output, internalGetServices(), ServicesDefaultEntryHolder.defaultEntry, 3);
getUnknownFields().writeTo(output);
}
@Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(app_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, app_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(version_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, version_);
}
for (java.util.Map.Entry<String, ServiceInfoV2> entry :
internalGetServices().getMap().entrySet()) {
com.google.protobuf.MapEntry<String, ServiceInfoV2> services__ = ServicesDefaultEntryHolder.defaultEntry
.newBuilderForType()
.setKey(entry.getKey())
.setValue(entry.getValue())
.build();
size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, services__);
}
size += getUnknownFields().getSerializedSize();
memoizedSize = size;
return size;
}
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof MetadataInfoV2)) {
return super.equals(obj);
}
MetadataInfoV2 other = (MetadataInfoV2) obj;
if (!getApp().equals(other.getApp())) return false;
if (!getVersion().equals(other.getVersion())) return false;
if (!internalGetServices().equals(other.internalGetServices())) return false;
if (!getUnknownFields().equals(other.getUnknownFields())) return false;
return true;
}
@Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + APP_FIELD_NUMBER;
hash = (53 * hash) + getApp().hashCode();
hash = (37 * hash) + VERSION_FIELD_NUMBER;
hash = (53 * hash) + getVersion().hashCode();
if (!internalGetServices().getMap().isEmpty()) {
hash = (37 * hash) + SERVICES_FIELD_NUMBER;
hash = (53 * hash) + internalGetServices().hashCode();
}
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
return hash;
}
public static MetadataInfoV2 parseFrom(java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static MetadataInfoV2 parseFrom(
java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static MetadataInfoV2 parseFrom(com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static MetadataInfoV2 parseFrom(
com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static MetadataInfoV2 parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static MetadataInfoV2 parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static MetadataInfoV2 parseFrom(java.io.InputStream input) throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input);
}
public static MetadataInfoV2 parseFrom(
java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry);
}
public static MetadataInfoV2 parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input);
}
public static MetadataInfoV2 parseDelimitedFrom(
java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static MetadataInfoV2 parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input);
}
public static MetadataInfoV2 parseFrom(
com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry);
}
@Override
public Builder newBuilderForType() {
return newBuilder();
}
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(MetadataInfoV2 prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this);
}
@Override
protected Builder newBuilderForType(BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* Protobuf type {@code org.apache.dubbo.metadata.MetadataInfoV2}
*/
public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder<Builder>
implements
// @@protoc_insertion_point(builder_implements:org.apache.dubbo.metadata.MetadataInfoV2)
MetadataInfoV2OrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() {
return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor;
}
@SuppressWarnings({"rawtypes"})
protected com.google.protobuf.MapField internalGetMapField(int number) {
switch (number) {
case 3:
return internalGetServices();
default:
throw new RuntimeException("Invalid map field number: " + number);
}
}
@SuppressWarnings({"rawtypes"})
protected com.google.protobuf.MapField internalGetMutableMapField(int number) {
switch (number) {
case 3:
return internalGetMutableServices();
default:
throw new RuntimeException("Invalid map field number: " + number);
}
}
@Override
protected FieldAccessorTable internalGetFieldAccessorTable() {
return MetadataServiceV2OuterClass
.internal_static_org_apache_dubbo_metadata_MetadataInfoV2_fieldAccessorTable
.ensureFieldAccessorsInitialized(MetadataInfoV2.class, Builder.class);
}
// Construct using org.apache.dubbo.metadata.MetadataInfoV2.newBuilder()
private Builder() {}
private Builder(BuilderParent parent) {
super(parent);
}
@Override
public Builder clear() {
super.clear();
bitField0_ = 0;
app_ = "";
version_ = "";
internalGetMutableServices().clear();
return this;
}
@Override
public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() {
return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor;
}
@Override
public MetadataInfoV2 getDefaultInstanceForType() {
return MetadataInfoV2.getDefaultInstance();
}
@Override
public MetadataInfoV2 build() {
MetadataInfoV2 result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@Override
public MetadataInfoV2 buildPartial() {
MetadataInfoV2 result = new MetadataInfoV2(this);
if (bitField0_ != 0) {
buildPartial0(result);
}
onBuilt();
return result;
}
private void buildPartial0(MetadataInfoV2 result) {
int from_bitField0_ = bitField0_;
if (((from_bitField0_ & 0x00000001) != 0)) {
result.app_ = app_;
}
if (((from_bitField0_ & 0x00000002) != 0)) {
result.version_ = version_;
}
if (((from_bitField0_ & 0x00000004) != 0)) {
result.services_ = internalGetServices();
result.services_.makeImmutable();
}
}
@Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof MetadataInfoV2) {
return mergeFrom((MetadataInfoV2) other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(MetadataInfoV2 other) {
if (other == MetadataInfoV2.getDefaultInstance()) return this;
if (!other.getApp().isEmpty()) {
app_ = other.app_;
bitField0_ |= 0x00000001;
onChanged();
}
if (!other.getVersion().isEmpty()) {
version_ = other.version_;
bitField0_ |= 0x00000002;
onChanged();
}
internalGetMutableServices().mergeFrom(other.internalGetServices());
bitField0_ |= 0x00000004;
this.mergeUnknownFields(other.getUnknownFields());
onChanged();
return this;
}
@Override
public final boolean isInitialized() {
return true;
}
@Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
if (extensionRegistry == null) {
throw new NullPointerException();
}
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 10: {
app_ = input.readStringRequireUtf8();
bitField0_ |= 0x00000001;
break;
} // case 10
case 18: {
version_ = input.readStringRequireUtf8();
bitField0_ |= 0x00000002;
break;
} // case 18
case 26: {
com.google.protobuf.MapEntry<String, ServiceInfoV2> services__ = input.readMessage(
ServicesDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry);
internalGetMutableServices()
.getMutableMap()
.put(services__.getKey(), services__.getValue());
bitField0_ |= 0x00000004;
break;
} // case 26
default: {
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
done = true; // was an endgroup tag
}
break;
} // default:
} // switch (tag)
} // while (!done)
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.unwrapIOException();
} finally {
onChanged();
} // finally
return this;
}
private int bitField0_;
private Object app_ = "";
/**
* <code>string app = 1;</code>
* @return The app.
*/
public String getApp() {
Object ref = app_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
app_ = s;
return s;
} else {
return (String) ref;
}
}
/**
* <code>string app = 1;</code>
* @return The bytes for app.
*/
public com.google.protobuf.ByteString getAppBytes() {
Object ref = app_;
if (ref instanceof String) {
com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref);
app_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string app = 1;</code>
* @param value The app to set.
* @return This builder for chaining.
*/
public Builder setApp(String value) {
if (value == null) {
throw new NullPointerException();
}
app_ = value;
bitField0_ |= 0x00000001;
onChanged();
return this;
}
/**
* <code>string app = 1;</code>
* @return This builder for chaining.
*/
public Builder clearApp() {
app_ = getDefaultInstance().getApp();
bitField0_ = (bitField0_ & ~0x00000001);
onChanged();
return this;
}
/**
* <code>string app = 1;</code>
* @param value The bytes for app to set.
* @return This builder for chaining.
*/
public Builder setAppBytes(com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
app_ = value;
bitField0_ |= 0x00000001;
onChanged();
return this;
}
private Object version_ = "";
/**
* <code>string version = 2;</code>
* @return The version.
*/
public String getVersion() {
Object ref = version_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
version_ = s;
return s;
} else {
return (String) ref;
}
}
/**
* <code>string version = 2;</code>
* @return The bytes for version.
*/
public com.google.protobuf.ByteString getVersionBytes() {
Object ref = version_;
if (ref instanceof String) {
com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref);
version_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string version = 2;</code>
* @param value The version to set.
* @return This builder for chaining.
*/
public Builder setVersion(String value) {
if (value == null) {
throw new NullPointerException();
}
version_ = value;
bitField0_ |= 0x00000002;
onChanged();
return this;
}
/**
* <code>string version = 2;</code>
* @return This builder for chaining.
*/
public Builder clearVersion() {
version_ = getDefaultInstance().getVersion();
bitField0_ = (bitField0_ & ~0x00000002);
onChanged();
return this;
}
/**
* <code>string version = 2;</code>
* @param value The bytes for version to set.
* @return This builder for chaining.
*/
public Builder setVersionBytes(com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
version_ = value;
bitField0_ |= 0x00000002;
onChanged();
return this;
}
private com.google.protobuf.MapField<String, ServiceInfoV2> services_;
private com.google.protobuf.MapField<String, ServiceInfoV2> internalGetServices() {
if (services_ == null) {
return com.google.protobuf.MapField.emptyMapField(ServicesDefaultEntryHolder.defaultEntry);
}
return services_;
}
private com.google.protobuf.MapField<String, ServiceInfoV2> internalGetMutableServices() {
if (services_ == null) {
services_ = com.google.protobuf.MapField.newMapField(ServicesDefaultEntryHolder.defaultEntry);
}
if (!services_.isMutable()) {
services_ = services_.copy();
}
bitField0_ |= 0x00000004;
onChanged();
return services_;
}
public int getServicesCount() {
return internalGetServices().getMap().size();
}
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
@Override
public boolean containsServices(String key) {
if (key == null) {
throw new NullPointerException("map key");
}
return internalGetServices().getMap().containsKey(key);
}
/**
* Use {@link #getServicesMap()} instead.
*/
@Override
@Deprecated
public java.util.Map<String, ServiceInfoV2> getServices() {
return getServicesMap();
}
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
@Override
public java.util.Map<String, ServiceInfoV2> getServicesMap() {
return internalGetServices().getMap();
}
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
@Override
public /* nullable */ ServiceInfoV2 getServicesOrDefault(
String key,
/* nullable */
ServiceInfoV2 defaultValue) {
if (key == null) {
throw new NullPointerException("map key");
}
java.util.Map<String, ServiceInfoV2> map = internalGetServices().getMap();
return map.containsKey(key) ? map.get(key) : defaultValue;
}
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
@Override
public ServiceInfoV2 getServicesOrThrow(String key) {
if (key == null) {
throw new NullPointerException("map key");
}
java.util.Map<String, ServiceInfoV2> map = internalGetServices().getMap();
if (!map.containsKey(key)) {
throw new IllegalArgumentException();
}
return map.get(key);
}
public Builder clearServices() {
bitField0_ = (bitField0_ & ~0x00000004);
internalGetMutableServices().getMutableMap().clear();
return this;
}
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
public Builder removeServices(String key) {
if (key == null) {
throw new NullPointerException("map key");
}
internalGetMutableServices().getMutableMap().remove(key);
return this;
}
/**
* Use alternate mutation accessors instead.
*/
@Deprecated
public java.util.Map<String, ServiceInfoV2> getMutableServices() {
bitField0_ |= 0x00000004;
return internalGetMutableServices().getMutableMap();
}
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
public Builder putServices(String key, ServiceInfoV2 value) {
if (key == null) {
throw new NullPointerException("map key");
}
if (value == null) {
throw new NullPointerException("map value");
}
internalGetMutableServices().getMutableMap().put(key, value);
bitField0_ |= 0x00000004;
return this;
}
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
public Builder putAllServices(java.util.Map<String, ServiceInfoV2> values) {
internalGetMutableServices().getMutableMap().putAll(values);
bitField0_ |= 0x00000004;
return this;
}
@Override
public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@Override
public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:org.apache.dubbo.metadata.MetadataInfoV2)
}
// @@protoc_insertion_point(class_scope:org.apache.dubbo.metadata.MetadataInfoV2)
private static final MetadataInfoV2 DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new MetadataInfoV2();
}
public static MetadataInfoV2 getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<MetadataInfoV2> PARSER =
new com.google.protobuf.AbstractParser<MetadataInfoV2>() {
@Override
public MetadataInfoV2 parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
Builder builder = newBuilder();
try {
builder.mergeFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(builder.buildPartial());
} catch (com.google.protobuf.UninitializedMessageException e) {
throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial());
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(e)
.setUnfinishedMessage(builder.buildPartial());
}
return builder.buildPartial();
}
};
public static com.google.protobuf.Parser<MetadataInfoV2> parser() {
return PARSER;
}
@Override
public com.google.protobuf.Parser<MetadataInfoV2> getParserForType() {
return PARSER;
}
@Override
public MetadataInfoV2 getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}

View File

@ -0,0 +1,75 @@
/*
* 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.metadata;
public interface MetadataInfoV2OrBuilder
extends
// @@protoc_insertion_point(interface_extends:org.apache.dubbo.metadata.MetadataInfoV2)
com.google.protobuf.MessageOrBuilder {
/**
* <code>string app = 1;</code>
* @return The app.
*/
String getApp();
/**
* <code>string app = 1;</code>
* @return The bytes for app.
*/
com.google.protobuf.ByteString getAppBytes();
/**
* <code>string version = 2;</code>
* @return The version.
*/
String getVersion();
/**
* <code>string version = 2;</code>
* @return The bytes for version.
*/
com.google.protobuf.ByteString getVersionBytes();
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
int getServicesCount();
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
boolean containsServices(String key);
/**
* Use {@link #getServicesMap()} instead.
*/
@Deprecated
java.util.Map<String, ServiceInfoV2> getServices();
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
java.util.Map<String, ServiceInfoV2> getServicesMap();
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
/* nullable */
ServiceInfoV2 getServicesOrDefault(
String key,
/* nullable */
ServiceInfoV2 defaultValue);
/**
* <code>map&lt;string, .org.apache.dubbo.metadata.ServiceInfoV2&gt; services = 3;</code>
*/
ServiceInfoV2 getServicesOrThrow(String key);
}

View File

@ -0,0 +1,29 @@
/*
* 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.metadata;
import java.util.concurrent.CompletableFuture;
public interface MetadataServiceV2 extends org.apache.dubbo.rpc.model.DubboStub {
String JAVA_SERVICE_NAME = "org.apache.dubbo.metadata.MetadataServiceV2";
String SERVICE_NAME = "org.apache.dubbo.metadata.MetadataServiceV2";
MetadataInfoV2 getMetadataInfo(Revision request);
CompletableFuture<MetadataInfoV2> getMetadataInfoAsync(Revision request);
}

View File

@ -0,0 +1,53 @@
/*
* 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.metadata;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.rpc.model.BuiltinServiceDetector;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_CLASS_NOT_FOUND;
public class MetadataServiceV2Detector implements BuiltinServiceDetector {
private static final ErrorTypeAwareLogger logger =
LoggerFactory.getErrorTypeAwareLogger(MetadataServiceV2Detector.class);
public static final String NAME = "metadataV2";
@Override
public Class<?> getService() {
if (!support()) {
logger.warn(
COMMON_CLASS_NOT_FOUND,
"",
"",
"To use MetadataServiceV2, Protobuf dependencies are required. Fallback to MetadataService(V1).");
return null;
}
return org.apache.dubbo.metadata.MetadataServiceV2.class;
}
public static boolean support() {
try {
Class.forName("com.google.protobuf.Message");
} catch (ClassNotFoundException classNotFoundException) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,122 @@
/*
* 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.metadata;
public final class MetadataServiceV2OuterClass {
private MetadataServiceV2OuterClass() {}
public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {}
public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry);
}
static final com.google.protobuf.Descriptors.Descriptor
internal_static_org_apache_dubbo_metadata_Revision_descriptor;
static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_org_apache_dubbo_metadata_Revision_fieldAccessorTable;
static final com.google.protobuf.Descriptors.Descriptor
internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor;
static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_org_apache_dubbo_metadata_MetadataInfoV2_fieldAccessorTable;
static final com.google.protobuf.Descriptors.Descriptor
internal_static_org_apache_dubbo_metadata_MetadataInfoV2_ServicesEntry_descriptor;
static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_org_apache_dubbo_metadata_MetadataInfoV2_ServicesEntry_fieldAccessorTable;
static final com.google.protobuf.Descriptors.Descriptor
internal_static_org_apache_dubbo_metadata_ServiceInfoV2_descriptor;
static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_org_apache_dubbo_metadata_ServiceInfoV2_fieldAccessorTable;
static final com.google.protobuf.Descriptors.Descriptor
internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_descriptor;
static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor descriptor;
static {
String[] descriptorData = {
"\n\031metadata_service_v2.proto\022\031org.apache."
+ "dubbo.metadata\"\031\n\010Revision\022\r\n\005value\030\001 \001("
+ "\t\"\324\001\n\016MetadataInfoV2\022\013\n\003app\030\001 \001(\t\022\017\n\007ver"
+ "sion\030\002 \001(\t\022I\n\010services\030\003 \003(\01327.org.apach"
+ "e.dubbo.metadata.MetadataInfoV2.Services"
+ "Entry\032Y\n\rServicesEntry\022\013\n\003key\030\001 \001(\t\0227\n\005v"
+ "alue\030\002 \001(\0132(.org.apache.dubbo.metadata.S"
+ "erviceInfoV2:\0028\001\"\340\001\n\rServiceInfoV2\022\014\n\004na"
+ "me\030\001 \001(\t\022\r\n\005group\030\002 \001(\t\022\017\n\007version\030\003 \001(\t"
+ "\022\020\n\010protocol\030\004 \001(\t\022\014\n\004port\030\005 \001(\005\022\014\n\004path"
+ "\030\006 \001(\t\022D\n\006params\030\007 \003(\01324.org.apache.dubb"
+ "o.metadata.ServiceInfoV2.ParamsEntry\032-\n\013"
+ "ParamsEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t:"
+ "\0028\0012v\n\021MetadataServiceV2\022a\n\017GetMetadataI"
+ "nfo\022#.org.apache.dubbo.metadata.Revision"
+ "\032).org.apache.dubbo.metadata.MetadataInf"
+ "oV2BO\n\031org.apache.dubbo.metadataP\001Z0dubb"
+ "o.apache.org/dubbo-go/v3/metadata/triple"
+ "_apib\006proto3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom(
descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] {});
internal_static_org_apache_dubbo_metadata_Revision_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_org_apache_dubbo_metadata_Revision_fieldAccessorTable =
new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_org_apache_dubbo_metadata_Revision_descriptor, new String[] {
"Value",
});
internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor =
getDescriptor().getMessageTypes().get(1);
internal_static_org_apache_dubbo_metadata_MetadataInfoV2_fieldAccessorTable =
new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor, new String[] {
"App", "Version", "Services",
});
internal_static_org_apache_dubbo_metadata_MetadataInfoV2_ServicesEntry_descriptor =
internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor
.getNestedTypes()
.get(0);
internal_static_org_apache_dubbo_metadata_MetadataInfoV2_ServicesEntry_fieldAccessorTable =
new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_org_apache_dubbo_metadata_MetadataInfoV2_ServicesEntry_descriptor,
new String[] {
"Key", "Value",
});
internal_static_org_apache_dubbo_metadata_ServiceInfoV2_descriptor =
getDescriptor().getMessageTypes().get(2);
internal_static_org_apache_dubbo_metadata_ServiceInfoV2_fieldAccessorTable =
new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_org_apache_dubbo_metadata_ServiceInfoV2_descriptor, new String[] {
"Name", "Group", "Version", "Protocol", "Port", "Path", "Params",
});
internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_descriptor =
internal_static_org_apache_dubbo_metadata_ServiceInfoV2_descriptor
.getNestedTypes()
.get(0);
internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_fieldAccessorTable =
new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_descriptor, new String[] {
"Key", "Value",
});
}
// @@protoc_insertion_point(outer_class_scope)
}

View File

@ -0,0 +1,497 @@
/*
* 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.metadata;
/**
* Protobuf type {@code org.apache.dubbo.metadata.Revision}
*/
public final class Revision extends com.google.protobuf.GeneratedMessageV3
implements
// @@protoc_insertion_point(message_implements:org.apache.dubbo.metadata.Revision)
RevisionOrBuilder {
private static final long serialVersionUID = 0L;
// Use Revision.newBuilder() to construct.
private Revision(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private Revision() {
value_ = "";
}
@Override
@SuppressWarnings({"unused"})
protected Object newInstance(UnusedPrivateParameter unused) {
return new Revision();
}
public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() {
return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_Revision_descriptor;
}
@Override
protected FieldAccessorTable internalGetFieldAccessorTable() {
return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_Revision_fieldAccessorTable
.ensureFieldAccessorsInitialized(Revision.class, Builder.class);
}
public static final int VALUE_FIELD_NUMBER = 1;
@SuppressWarnings("serial")
private volatile Object value_ = "";
/**
* <code>string value = 1;</code>
* @return The value.
*/
@Override
public String getValue() {
Object ref = value_;
if (ref instanceof String) {
return (String) ref;
} else {
com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
value_ = s;
return s;
}
}
/**
* <code>string value = 1;</code>
* @return The bytes for value.
*/
@Override
public com.google.protobuf.ByteString getValueBytes() {
Object ref = value_;
if (ref instanceof String) {
com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref);
value_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
private byte memoizedIsInitialized = -1;
@Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@Override
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException {
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(value_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, value_);
}
getUnknownFields().writeTo(output);
}
@Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(value_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, value_);
}
size += getUnknownFields().getSerializedSize();
memoizedSize = size;
return size;
}
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Revision)) {
return super.equals(obj);
}
Revision other = (Revision) obj;
if (!getValue().equals(other.getValue())) return false;
if (!getUnknownFields().equals(other.getUnknownFields())) return false;
return true;
}
@Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + VALUE_FIELD_NUMBER;
hash = (53 * hash) + getValue().hashCode();
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
return hash;
}
public static Revision parseFrom(java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static Revision parseFrom(
java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static Revision parseFrom(com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static Revision parseFrom(
com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static Revision parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static Revision parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static Revision parseFrom(java.io.InputStream input) throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input);
}
public static Revision parseFrom(
java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry);
}
public static Revision parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input);
}
public static Revision parseDelimitedFrom(
java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static Revision parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input);
}
public static Revision parseFrom(
com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry);
}
@Override
public Builder newBuilderForType() {
return newBuilder();
}
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(Revision prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this);
}
@Override
protected Builder newBuilderForType(BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* Protobuf type {@code org.apache.dubbo.metadata.Revision}
*/
public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder<Builder>
implements
// @@protoc_insertion_point(builder_implements:org.apache.dubbo.metadata.Revision)
RevisionOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() {
return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_Revision_descriptor;
}
@Override
protected FieldAccessorTable internalGetFieldAccessorTable() {
return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_Revision_fieldAccessorTable
.ensureFieldAccessorsInitialized(Revision.class, Builder.class);
}
// Construct using org.apache.dubbo.metadata.Revision.newBuilder()
private Builder() {}
private Builder(BuilderParent parent) {
super(parent);
}
@Override
public Builder clear() {
super.clear();
bitField0_ = 0;
value_ = "";
return this;
}
@Override
public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() {
return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_Revision_descriptor;
}
@Override
public Revision getDefaultInstanceForType() {
return Revision.getDefaultInstance();
}
@Override
public Revision build() {
Revision result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@Override
public Revision buildPartial() {
Revision result = new Revision(this);
if (bitField0_ != 0) {
buildPartial0(result);
}
onBuilt();
return result;
}
private void buildPartial0(Revision result) {
int from_bitField0_ = bitField0_;
if (((from_bitField0_ & 0x00000001) != 0)) {
result.value_ = value_;
}
}
@Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof Revision) {
return mergeFrom((Revision) other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(Revision other) {
if (other == Revision.getDefaultInstance()) return this;
if (!other.getValue().isEmpty()) {
value_ = other.value_;
bitField0_ |= 0x00000001;
onChanged();
}
this.mergeUnknownFields(other.getUnknownFields());
onChanged();
return this;
}
@Override
public final boolean isInitialized() {
return true;
}
@Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
if (extensionRegistry == null) {
throw new NullPointerException();
}
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 10: {
value_ = input.readStringRequireUtf8();
bitField0_ |= 0x00000001;
break;
} // case 10
default: {
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
done = true; // was an endgroup tag
}
break;
} // default:
} // switch (tag)
} // while (!done)
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.unwrapIOException();
} finally {
onChanged();
} // finally
return this;
}
private int bitField0_;
private Object value_ = "";
/**
* <code>string value = 1;</code>
* @return The value.
*/
public String getValue() {
Object ref = value_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
value_ = s;
return s;
} else {
return (String) ref;
}
}
/**
* <code>string value = 1;</code>
* @return The bytes for value.
*/
public com.google.protobuf.ByteString getValueBytes() {
Object ref = value_;
if (ref instanceof String) {
com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref);
value_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string value = 1;</code>
* @param value The value to set.
* @return This builder for chaining.
*/
public Builder setValue(String value) {
if (value == null) {
throw new NullPointerException();
}
value_ = value;
bitField0_ |= 0x00000001;
onChanged();
return this;
}
/**
* <code>string value = 1;</code>
* @return This builder for chaining.
*/
public Builder clearValue() {
value_ = getDefaultInstance().getValue();
bitField0_ = (bitField0_ & ~0x00000001);
onChanged();
return this;
}
/**
* <code>string value = 1;</code>
* @param value The bytes for value to set.
* @return This builder for chaining.
*/
public Builder setValueBytes(com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
value_ = value;
bitField0_ |= 0x00000001;
onChanged();
return this;
}
@Override
public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@Override
public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:org.apache.dubbo.metadata.Revision)
}
// @@protoc_insertion_point(class_scope:org.apache.dubbo.metadata.Revision)
private static final Revision DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new Revision();
}
public static Revision getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<Revision> PARSER =
new com.google.protobuf.AbstractParser<Revision>() {
@Override
public Revision parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
Builder builder = newBuilder();
try {
builder.mergeFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(builder.buildPartial());
} catch (com.google.protobuf.UninitializedMessageException e) {
throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial());
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(e)
.setUnfinishedMessage(builder.buildPartial());
}
return builder.buildPartial();
}
};
public static com.google.protobuf.Parser<Revision> parser() {
return PARSER;
}
@Override
public com.google.protobuf.Parser<Revision> getParserForType() {
return PARSER;
}
@Override
public Revision getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}

View File

@ -0,0 +1,34 @@
/*
* 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.metadata;
public interface RevisionOrBuilder
extends
// @@protoc_insertion_point(interface_extends:org.apache.dubbo.metadata.Revision)
com.google.protobuf.MessageOrBuilder {
/**
* <code>string value = 1;</code>
* @return The value.
*/
String getValue();
/**
* <code>string value = 1;</code>
* @return The bytes for value.
*/
com.google.protobuf.ByteString getValueBytes();
}

View File

@ -0,0 +1,114 @@
/*
* 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.metadata;
public interface ServiceInfoV2OrBuilder
extends
// @@protoc_insertion_point(interface_extends:org.apache.dubbo.metadata.ServiceInfoV2)
com.google.protobuf.MessageOrBuilder {
/**
* <code>string name = 1;</code>
* @return The name.
*/
String getName();
/**
* <code>string name = 1;</code>
* @return The bytes for name.
*/
com.google.protobuf.ByteString getNameBytes();
/**
* <code>string group = 2;</code>
* @return The group.
*/
String getGroup();
/**
* <code>string group = 2;</code>
* @return The bytes for group.
*/
com.google.protobuf.ByteString getGroupBytes();
/**
* <code>string version = 3;</code>
* @return The version.
*/
String getVersion();
/**
* <code>string version = 3;</code>
* @return The bytes for version.
*/
com.google.protobuf.ByteString getVersionBytes();
/**
* <code>string protocol = 4;</code>
* @return The protocol.
*/
String getProtocol();
/**
* <code>string protocol = 4;</code>
* @return The bytes for protocol.
*/
com.google.protobuf.ByteString getProtocolBytes();
/**
* <code>int32 port = 5;</code>
* @return The port.
*/
int getPort();
/**
* <code>string path = 6;</code>
* @return The path.
*/
String getPath();
/**
* <code>string path = 6;</code>
* @return The bytes for path.
*/
com.google.protobuf.ByteString getPathBytes();
/**
* <code>map&lt;string, string&gt; params = 7;</code>
*/
int getParamsCount();
/**
* <code>map&lt;string, string&gt; params = 7;</code>
*/
boolean containsParams(String key);
/**
* Use {@link #getParamsMap()} instead.
*/
@Deprecated
java.util.Map<String, String> getParams();
/**
* <code>map&lt;string, string&gt; params = 7;</code>
*/
java.util.Map<String, String> getParamsMap();
/**
* <code>map&lt;string, string&gt; params = 7;</code>
*/
/* nullable */
String getParamsOrDefault(
String key,
/* nullable */
String defaultValue);
/**
* <code>map&lt;string, string&gt; params = 7;</code>
*/
String getParamsOrThrow(String key);
}

View File

@ -0,0 +1,154 @@
/*
* 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.metadata.util;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.context.ConfigManager;
import org.apache.dubbo.metadata.MetadataInfo;
import org.apache.dubbo.metadata.MetadataInfo.ServiceInfo;
import org.apache.dubbo.metadata.MetadataInfoV2;
import org.apache.dubbo.metadata.MetadataServiceV2Detector;
import org.apache.dubbo.metadata.ServiceInfoV2;
import org.apache.dubbo.rpc.model.ApplicationModel;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import static org.apache.dubbo.common.constants.CommonConstants.TRIPLE;
public class MetadataServiceVersionUtils {
public static final String V1 = "1.0.0";
public static final String V2 = "2.0.0";
public static MetadataInfoV2 toV2(MetadataInfo metadataInfo) {
if (metadataInfo == null) {
return MetadataInfoV2.newBuilder().build();
}
Map<String, ServiceInfoV2> servicesV2 = new HashMap<>();
metadataInfo.getServices().forEach((name, serviceInfo) -> servicesV2.put(name, toV2(serviceInfo)));
return MetadataInfoV2.newBuilder()
.setVersion(ifNullSetEmpty(metadataInfo.getRevision()))
.setApp(ifNullSetEmpty(metadataInfo.getApp()))
.putAllServices(servicesV2)
.build();
}
public static ServiceInfoV2 toV2(ServiceInfo serviceInfo) {
if (serviceInfo == null) {
return ServiceInfoV2.newBuilder().build();
}
return ServiceInfoV2.newBuilder()
.setVersion(ifNullSetEmpty(serviceInfo.getVersion()))
.setGroup(ifNullSetEmpty(serviceInfo.getGroup()))
.setName(ifNullSetEmpty(serviceInfo.getName()))
.setPort(serviceInfo.getPort())
.setPath(ifNullSetEmpty(serviceInfo.getPath()))
.setProtocol(ifNullSetEmpty(serviceInfo.getProtocol()))
.putAllParams(serviceInfo.getAllParams())
.build();
}
private static String ifNullSetEmpty(String value) {
return value == null ? "" : value;
}
public static MetadataInfo toV1(MetadataInfoV2 metadataInfoV2) {
Map<String, ServiceInfoV2> servicesV2Map = metadataInfoV2.getServicesMap();
Map<String, ServiceInfo> serviceMap = new HashMap<>(servicesV2Map.size());
servicesV2Map.forEach((s, serviceInfoV2) -> serviceMap.put(s, toV1(serviceInfoV2)));
return new MetadataInfo(metadataInfoV2.getApp(), metadataInfoV2.getVersion(), serviceMap);
}
public static ServiceInfo toV1(ServiceInfoV2 serviceInfoV2) {
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setGroup(serviceInfoV2.getGroup());
serviceInfo.setVersion(serviceInfoV2.getVersion());
serviceInfo.setName(serviceInfoV2.getName());
serviceInfo.setPort(serviceInfoV2.getPort());
serviceInfo.setParams(serviceInfoV2.getParamsMap());
serviceInfo.setProtocol(serviceInfoV2.getProtocol());
serviceInfo.setPath(serviceInfoV2.getPath());
return serviceInfo;
}
/**
* check if we should export MetadataService
*/
public static boolean needExportV1(ApplicationModel applicationModel) {
return !MetadataServiceV2Detector.support() || !onlyExportV2(applicationModel);
}
/**
* check if we should export MetadataServiceV2
*/
public static boolean needExportV2(ApplicationModel applicationModel) {
return MetadataServiceV2Detector.support()
&& (onlyExportV2(applicationModel) || tripleConfigured(applicationModel));
}
/**
* check if we should only export MetadataServiceV2
*/
public static boolean onlyExportV2(ApplicationModel applicationModel) {
Optional<ApplicationConfig> applicationConfig = getApplicationConfig(applicationModel);
return applicationConfig
.filter(config ->
Boolean.TRUE.equals(config.getOnlyUseMetadataV2()) && tripleConfigured(applicationModel))
.isPresent();
}
/**
* check if we can use triple as MetadataService protocol
*/
public static boolean tripleConfigured(ApplicationModel applicationModel) {
Optional<ConfigManager> configManager = Optional.ofNullable(applicationModel.getApplicationConfigManager());
Optional<ApplicationConfig> appConfig = getApplicationConfig(applicationModel);
// if user configured MetadataService protocol
if (appConfig.isPresent() && appConfig.get().getMetadataServiceProtocol() != null) {
return TRIPLE.equals(appConfig.get().getMetadataServiceProtocol());
}
// if not specified, check all protocol configs
if (configManager.isPresent()
&& CollectionUtils.isNotEmpty(configManager.get().getProtocols())) {
Collection<ProtocolConfig> protocols = configManager.get().getProtocols();
for (ProtocolConfig protocolConfig : protocols) {
if (TRIPLE.equals(protocolConfig.getName())) {
return true;
}
}
}
return false;
}
private static Optional<ApplicationConfig> getApplicationConfig(ApplicationModel applicationModel) {
Optional<ConfigManager> configManager = Optional.ofNullable(applicationModel.getApplicationConfigManager());
if (configManager.isPresent() && configManager.get().getApplication().isPresent()) {
return configManager.get().getApplication();
}
return Optional.empty();
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.
*/
syntax = "proto3";
package org.apache.dubbo.metadata;
option go_package = "dubbo.apache.org/dubbo-go/v3/metadata/triple_api";
option java_package = "org.apache.dubbo.metadata";
option java_multiple_files = true;
service MetadataServiceV2{
rpc GetMetadataInfo(Revision) returns (MetadataInfoV2);
}
message Revision{
string value = 1;
}
message MetadataInfoV2{
string app = 1;
string version = 2;
map<string,ServiceInfoV2> services = 3;
}
message ServiceInfoV2{
string name = 1;
string group = 2;
string version = 3;
string protocol = 4;
int32 port = 5;
string path = 6;
map<string,string> params = 7;
}

View File

@ -1 +1,2 @@
metadata=org.apache.dubbo.metadata.MetadataServiceDetector
metadataV2=org.apache.dubbo.metadata.MetadataServiceV2Detector

View File

@ -277,9 +277,14 @@ public class ReflectionBasedServiceDiscovery extends AbstractServiceDiscovery {
}
private synchronized MetadataService getMetadataServiceProxy(ServiceInstance instance) {
return ConcurrentHashMapUtils.computeIfAbsent(
metadataServiceProxies, computeKey(instance), k -> MetadataUtils.referProxy(instance)
.getProxy());
Object internalProxy = MetadataUtils.referMetadataService(instance).getInternalProxy();
if (internalProxy instanceof MetadataService) {
return ConcurrentHashMapUtils.computeIfAbsent(
metadataServiceProxies, computeKey(instance), k -> (MetadataService) internalProxy);
}
throw new RuntimeException("Service " + instance.getServiceName() + " at " + instance.getHost() + ":"
+ instance.getPort() + "are using MetadataServiceV2, which is not support ");
}
private synchronized void destroyMetadataServiceProxy(ServiceInstance instance) {

View File

@ -61,6 +61,8 @@ public class MetadataServiceDelegation implements MetadataService, Disposable {
// works only for DNS service discovery
private String instanceMetadata;
public static final String VERSION = "1.0.0";
public MetadataServiceDelegation(ApplicationModel applicationModel) {
this.applicationModel = applicationModel;
registryManager = RegistryManager.getInstance(applicationModel);
@ -96,21 +98,25 @@ public class MetadataServiceDelegation implements MetadataService, Disposable {
for (ServiceDiscovery sd : serviceDiscoveries) {
MetadataInfo metadataInfo = sd.getLocalMetadata();
Map<String, SortedSet<URL>> serviceURLs = metadataInfo.getExportedServiceURLs();
if (serviceURLs == null) {
continue;
}
for (Map.Entry<String, SortedSet<URL>> entry : serviceURLs.entrySet()) {
SortedSet<URL> urls = entry.getValue();
if (urls != null) {
for (URL url : urls) {
if (!MetadataService.class.getName().equals(url.getServiceInterface())) {
bizURLs.add(url);
}
joinNonMetadataServiceUrls(bizURLs, serviceURLs);
}
return MetadataService.toSortedStrings(bizURLs);
}
private void joinNonMetadataServiceUrls(SortedSet<URL> bizURLs, Map<String, SortedSet<URL>> serviceURLs) {
if (serviceURLs == null) {
return;
}
for (Map.Entry<String, SortedSet<URL>> entry : serviceURLs.entrySet()) {
SortedSet<URL> urls = entry.getValue();
if (urls != null) {
for (URL url : urls) {
if (!MetadataService.class.getName().equals(url.getServiceInterface())) {
bizURLs.add(url);
}
}
}
}
return MetadataService.toSortedStrings(bizURLs);
}
private SortedSet<String> getAllUnmodifiableSubscribedURLs() {
@ -119,19 +125,7 @@ public class MetadataServiceDelegation implements MetadataService, Disposable {
for (ServiceDiscovery sd : serviceDiscoveries) {
MetadataInfo metadataInfo = sd.getLocalMetadata();
Map<String, SortedSet<URL>> serviceURLs = metadataInfo.getSubscribedServiceURLs();
if (serviceURLs == null) {
continue;
}
for (Map.Entry<String, SortedSet<URL>> entry : serviceURLs.entrySet()) {
SortedSet<URL> urls = entry.getValue();
if (urls != null) {
for (URL url : urls) {
if (!MetadataService.class.getName().equals(url.getServiceInterface())) {
bizURLs.add(url);
}
}
}
}
joinNonMetadataServiceUrls(bizURLs, serviceURLs);
}
return MetadataService.toSortedStrings(bizURLs);
}

View File

@ -0,0 +1,78 @@
/*
* 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.client.metadata;
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.utils.StringUtils;
import org.apache.dubbo.metadata.DubboMetadataServiceV2Triple.MetadataServiceV2ImplBase;
import org.apache.dubbo.metadata.MetadataInfo;
import org.apache.dubbo.registry.client.ServiceDiscovery;
import org.apache.dubbo.registry.support.RegistryManager;
import org.apache.dubbo.rpc.model.ApplicationModel;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_LOAD_METADATA;
import static org.apache.dubbo.metadata.util.MetadataServiceVersionUtils.toV2;
public class MetadataServiceDelegationV2 extends MetadataServiceV2ImplBase {
ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass());
private final ApplicationModel applicationModel;
private final RegistryManager registryManager;
private URL metadataUrl;
public static final String VERSION = "2.0.0";
public MetadataServiceDelegationV2(ApplicationModel applicationModel) {
this.applicationModel = applicationModel;
this.registryManager = RegistryManager.getInstance(applicationModel);
}
@Override
public org.apache.dubbo.metadata.MetadataInfoV2 getMetadataInfo(org.apache.dubbo.metadata.Revision revisionV2) {
String revision = revisionV2.getValue();
MetadataInfo info = null;
if (StringUtils.isEmpty(revision)) {
return null;
}
for (ServiceDiscovery sd : registryManager.getServiceDiscoveries()) {
info = sd.getLocalMetadata(revision);
if (info != null && revision.equals(info.getRevision())) {
return toV2(info);
}
}
if (logger.isWarnEnabled()) {
logger.warn(REGISTRY_FAILED_LOAD_METADATA, "", "", "metadataV2 not found for revision: " + revisionV2);
}
return null;
}
public URL getMetadataUrl() {
return metadataUrl;
}
public void setMetadataUrl(URL metadataUrl) {
this.metadataUrl = metadataUrl;
}
}

View File

@ -25,11 +25,15 @@ import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.metadata.MetadataInfo;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.MetadataServiceV2;
import org.apache.dubbo.metadata.MetadataServiceV2Detector;
import org.apache.dubbo.metadata.Revision;
import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
import org.apache.dubbo.metadata.report.MetadataReport;
import org.apache.dubbo.metadata.report.MetadataReportInstance;
import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
import org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
import org.apache.dubbo.metadata.util.MetadataServiceVersionUtils;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
@ -39,6 +43,7 @@ import org.apache.dubbo.rpc.model.ConsumerModel;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ServiceDescriptor;
import org.apache.dubbo.rpc.service.Destroyable;
import org.apache.dubbo.rpc.stub.StubSuppliers;
import java.util.HashMap;
import java.util.List;
@ -46,20 +51,25 @@ import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
import static org.apache.dubbo.common.constants.CommonConstants.NATIVE_STUB;
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
import static org.apache.dubbo.common.constants.CommonConstants.PROXY_CLASS_REF;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_CREATE_INSTANCE;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_LOAD_METADATA;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_CLUSTER_KEY;
import static org.apache.dubbo.metadata.util.MetadataServiceVersionUtils.V2;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_URLS_PROPERTY_NAME;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_VERSION_NAME;
import static org.apache.dubbo.rpc.Constants.PROXY_KEY;
public class MetadataUtils {
public static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(MetadataUtils.class);
public static void publishServiceDefinition(
URL url, ServiceDescriptor serviceDescriptor, ApplicationModel applicationModel) {
if (getMetadataReports(applicationModel).size() == 0) {
if (getMetadataReports(applicationModel).isEmpty()) {
String msg =
"Remote Metadata Report Server is not provided or unavailable, will stop registering service definition to remote center!";
logger.warn(REGISTRY_FAILED_LOAD_METADATA, "", "", msg);
@ -115,7 +125,70 @@ public class MetadataUtils {
}
}
public static ProxyHolder referProxy(ServiceInstance instance) {
public static RemoteMetadataService referMetadataService(ServiceInstance instance) {
URL url = buildMetadataUrl(instance);
// Simply rely on the first metadata url, as stated in MetadataServiceURLBuilder.
ApplicationModel applicationModel = instance.getApplicationModel();
ModuleModel internalModel = applicationModel.getInternalModule();
ConsumerModel consumerModel;
boolean useV2 = MetadataServiceDelegationV2.VERSION.equals(url.getAttribute(METADATA_SERVICE_VERSION_NAME));
if (!MetadataServiceV2Detector.support()) {
useV2 = false;
}
boolean inNativeImage = NativeDetector.inNativeImage();
if (useV2 && !inNativeImage) {
// If provider supports, we use MetadataServiceV2 in priority
url = url.addParameter(PROXY_KEY, NATIVE_STUB);
url = url.setPath(MetadataServiceV2.class.getName());
url = url.addParameter(VERSION_KEY, V2);
consumerModel = applicationModel
.getInternalModule()
.registerInternalConsumer(
MetadataServiceV2.class,
url,
StubSuppliers.getServiceDescriptor(MetadataServiceV2.class.getName()));
} else {
consumerModel = applicationModel.getInternalModule().registerInternalConsumer(MetadataService.class, url);
}
if (inNativeImage) {
url = url.addParameter(PROXY_KEY, "jdk");
}
Protocol protocol = applicationModel.getExtensionLoader(Protocol.class).getExtension(url.getProtocol(), false);
url = url.setServiceModel(consumerModel);
RemoteMetadataService remoteMetadataService;
ProxyFactory proxyFactory =
applicationModel.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
if (useV2) {
Invoker<MetadataServiceV2> invoker = protocol.refer(MetadataServiceV2.class, url);
remoteMetadataService =
new RemoteMetadataService(consumerModel, proxyFactory.getProxy(invoker), internalModel);
} else {
Invoker<MetadataService> invoker = protocol.refer(MetadataService.class, url);
remoteMetadataService =
new RemoteMetadataService(consumerModel, proxyFactory.getProxy(invoker), internalModel);
}
Object metadataServiceProxy = remoteMetadataService.getInternalProxy();
consumerModel.getServiceMetadata().setTarget(metadataServiceProxy);
consumerModel.getServiceMetadata().addAttribute(PROXY_CLASS_REF, metadataServiceProxy);
consumerModel.setProxyObject(metadataServiceProxy);
consumerModel.initMethodModels();
return remoteMetadataService;
}
private static URL buildMetadataUrl(ServiceInstance instance) {
MetadataServiceURLBuilder builder;
ExtensionLoader<MetadataServiceURLBuilder> loader =
instance.getApplicationModel().getExtensionLoader(MetadataServiceURLBuilder.class);
@ -134,36 +207,12 @@ public class MetadataUtils {
throw new IllegalStateException("Introspection service discovery mode is enabled " + instance
+ ", but no metadata service can build from it.");
}
URL url = urls.get(0);
// Simply rely on the first metadata url, as stated in MetadataServiceURLBuilder.
ApplicationModel applicationModel = instance.getApplicationModel();
ModuleModel internalModel = applicationModel.getInternalModule();
ConsumerModel consumerModel =
applicationModel.getInternalModule().registerInternalConsumer(MetadataService.class, url);
String version = metadata.get(METADATA_SERVICE_VERSION_NAME);
url = url.putAttribute(METADATA_SERVICE_VERSION_NAME, version);
Protocol protocol = applicationModel.getExtensionLoader(Protocol.class).getExtension(url.getProtocol(), false);
url = url.setServiceModel(consumerModel);
if (NativeDetector.inNativeImage()) {
url = url.addParameter("proxy", "jdk");
}
Invoker<MetadataService> invoker = protocol.refer(MetadataService.class, url);
ProxyFactory proxyFactory =
applicationModel.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
MetadataService metadataService = proxyFactory.getProxy(invoker);
consumerModel.getServiceMetadata().setTarget(metadataService);
consumerModel.getServiceMetadata().addAttribute(PROXY_CLASS_REF, metadataService);
consumerModel.setProxyObject(metadataService);
consumerModel.initMethodModels();
return new ProxyHolder(consumerModel, metadataService, internalModel);
return url;
}
public static MetadataInfo getRemoteMetadata(
@ -179,14 +228,13 @@ public class MetadataUtils {
metadataInfo = MetadataUtils.getMetadata(revision, instance, metadataReport);
} else {
// change the instance used to communicate to avoid all requests route to the same instance
ProxyHolder proxyHolder = null;
RemoteMetadataService remoteMetadataService = null;
try {
proxyHolder = MetadataUtils.referProxy(instance);
metadataInfo = proxyHolder
.getProxy()
.getMetadataInfo(ServiceInstanceMetadataUtils.getExportedServicesRevision(instance));
remoteMetadataService = MetadataUtils.referMetadataService(instance);
metadataInfo = remoteMetadataService.getRemoteMetadata(
ServiceInstanceMetadataUtils.getExportedServicesRevision(instance));
} finally {
MetadataUtils.destroyProxy(proxyHolder);
MetadataUtils.destroyProxy(remoteMetadataService);
}
}
} catch (Exception e) {
@ -206,9 +254,9 @@ public class MetadataUtils {
return metadataInfo;
}
public static void destroyProxy(ProxyHolder proxyHolder) {
if (proxyHolder != null) {
proxyHolder.destroy();
public static void destroyProxy(RemoteMetadataService remoteMetadataService) {
if (remoteMetadataService != null) {
remoteMetadataService.destroy();
}
}
@ -242,21 +290,38 @@ public class MetadataUtils {
return instances.get(ThreadLocalRandom.current().nextInt(0, instances.size()));
}
public static class ProxyHolder {
public static class RemoteMetadataService {
private final ConsumerModel consumerModel;
private final MetadataService proxy;
@Deprecated
private MetadataService proxy;
private MetadataServiceV2 proxyV2;
private final ModuleModel internalModel;
public ProxyHolder(ConsumerModel consumerModel, MetadataService proxy, ModuleModel internalModel) {
public RemoteMetadataService(ConsumerModel consumerModel, MetadataService proxy, ModuleModel internalModel) {
this.consumerModel = consumerModel;
this.proxy = proxy;
this.internalModel = internalModel;
}
public RemoteMetadataService(
ConsumerModel consumerModel, MetadataServiceV2 proxyV2, ModuleModel internalModel) {
this.consumerModel = consumerModel;
this.proxyV2 = proxyV2;
this.internalModel = internalModel;
}
public void destroy() {
if (proxy instanceof Destroyable) {
((Destroyable) proxy).$destroy();
}
if (proxyV2 instanceof Destroyable) {
((Destroyable) proxyV2).$destroy();
}
internalModel.getServiceRepository().unregisterConsumer(consumerModel);
}
@ -264,12 +329,23 @@ public class MetadataUtils {
return consumerModel;
}
public MetadataService getProxy() {
return proxy;
public Object getInternalProxy() {
return proxy == null ? proxyV2 : proxy;
}
public ModuleModel getInternalModel() {
return internalModel;
}
public MetadataInfo getRemoteMetadata(String revision) {
Object existProxy = getInternalProxy();
if (existProxy instanceof MetadataService) {
return ((MetadataService) existProxy).getMetadataInfo(revision);
} else {
return MetadataServiceVersionUtils.toV1(((MetadataServiceV2) existProxy)
.getMetadataInfo(
Revision.newBuilder().setValue(revision).build()));
}
}
}
}

View File

@ -96,6 +96,8 @@ public class ServiceInstanceMetadataUtils {
*/
public static final String METADATA_STORAGE_TYPE_PROPERTY_NAME = "dubbo.metadata.storage-type";
public static final String METADATA_SERVICE_VERSION_NAME = "meta-v";
public static final String METADATA_CLUSTER_PROPERTY_NAME = "dubbo.metadata.cluster";
public static String getMetadataServiceParameter(URL url) {