diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/DubboStub.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/DubboStub.java new file mode 100644 index 00000000000..7047eeaa1de --- /dev/null +++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/DubboStub.java @@ -0,0 +1,25 @@ +/* + * 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.rpc.model; + +/** + * Marker interface implemented by all stub. Used to detect + * whether objects are Dubbo-generated stub. + */ +public interface DubboStub { +} diff --git a/dubbo-compiler/src/main/resources/Dubbo3InterfaceStub.mustache b/dubbo-compiler/src/main/resources/Dubbo3InterfaceStub.mustache index f97b7183b0b..ebbaad9f7d7 100644 --- a/dubbo-compiler/src/main/resources/Dubbo3InterfaceStub.mustache +++ b/dubbo-compiler/src/main/resources/Dubbo3InterfaceStub.mustache @@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicBoolean; {{#deprecated}} @java.lang.Deprecated {{/deprecated}} -public interface {{interfaceClassName}} { +public interface {{interfaceClassName}} extends org.apache.dubbo.rpc.model.DubboStub { static final String JAVA_SERVICE_NAME = "{{packageName}}.{{serviceName}}"; static final String SERVICE_NAME = "{{commonPackageName}}.{{serviceName}}"; diff --git a/dubbo-compiler/src/main/resources/Dubbo3TripleInterfaceStub.mustache b/dubbo-compiler/src/main/resources/Dubbo3TripleInterfaceStub.mustache index 6788bfb6538..72b68c3d677 100644 --- a/dubbo-compiler/src/main/resources/Dubbo3TripleInterfaceStub.mustache +++ b/dubbo-compiler/src/main/resources/Dubbo3TripleInterfaceStub.mustache @@ -27,7 +27,7 @@ import java.util.Map; import java.util.function.BiConsumer; import java.util.concurrent.CompletableFuture; -public interface {{interfaceClassName}} { +public interface {{interfaceClassName}} extends org.apache.dubbo.rpc.model.DubboStub { String JAVA_SERVICE_NAME = "{{packageName}}.{{serviceName}}"; String SERVICE_NAME = "{{commonPackageName}}.{{serviceName}}"; diff --git a/dubbo-compiler/src/main/resources/DubboStub.mustache b/dubbo-compiler/src/main/resources/DubboStub.mustache index c45995587c6..8bf729e8dd3 100644 --- a/dubbo-compiler/src/main/resources/DubboStub.mustache +++ b/dubbo-compiler/src/main/resources/DubboStub.mustache @@ -51,7 +51,7 @@ public static final String SERVICE_NAME = "{{packageName}}.{{serviceName}}"; /** * Code generated for Dubbo */ -public interface I{{serviceName}} { +public interface I{{serviceName}} extends org.apache.dubbo.rpc.model.DubboStub { static Class clazz = init(); diff --git a/dubbo-compiler/src/main/resources/DubboStub3Single.mustache b/dubbo-compiler/src/main/resources/DubboStub3Single.mustache index 25a45e86d7f..b46653b488a 100644 --- a/dubbo-compiler/src/main/resources/DubboStub3Single.mustache +++ b/dubbo-compiler/src/main/resources/DubboStub3Single.mustache @@ -51,7 +51,7 @@ public static final String SERVICE_NAME = "{{packageName}}.{{serviceName}}"; /** * Code generated for Dubbo */ -public interface I{{serviceName}} { +public interface I{{serviceName}} extends org.apache.dubbo.rpc.model.DubboStub { static Class clazz = init(); diff --git a/dubbo-compiler/src/main/resources/ReactorDubbo3TripleInterfaceStub.mustache b/dubbo-compiler/src/main/resources/ReactorDubbo3TripleInterfaceStub.mustache index b3b900831e9..43e427f9f33 100644 --- a/dubbo-compiler/src/main/resources/ReactorDubbo3TripleInterfaceStub.mustache +++ b/dubbo-compiler/src/main/resources/ReactorDubbo3TripleInterfaceStub.mustache @@ -22,7 +22,7 @@ package {{packageName}}; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -public interface {{interfaceClassName}} { +public interface {{interfaceClassName}} extends org.apache.dubbo.rpc.model.DubboStub { String JAVA_SERVICE_NAME = "{{packageName}}.{{serviceName}}"; diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index fb34d5110ca..fd2868864b6 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -43,6 +43,7 @@ import org.apache.dubbo.rpc.cluster.support.registry.ZoneAwareCluster; import org.apache.dubbo.rpc.model.AsyncMethodInfo; import org.apache.dubbo.rpc.model.ConsumerModel; +import org.apache.dubbo.rpc.model.DubboStub; import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ModuleServiceRepository; import org.apache.dubbo.rpc.model.ScopeModel; @@ -264,6 +265,12 @@ protected synchronized void init() { if (!this.isRefreshed()) { this.refresh(); } + //auto detect proxy type + String proxyType = getProxy(); + if (StringUtils.isBlank(proxyType) + && DubboStub.class.isAssignableFrom(interfaceClass)) { + setProxy(CommonConstants.NATIVE_STUB); + } // init serviceMetadata initServiceMetadata(consumer);