Skip to content

Commit

Permalink
auto detect proxy type (#12232)
Browse files Browse the repository at this point in the history
* auto detect proxy type

* auto detect proxy type
  • Loading branch information
icodening authored May 5, 2023
1 parent 0724e94 commit c5f8ce6
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}";
Expand Down
2 changes: 1 addition & 1 deletion dubbo-compiler/src/main/resources/DubboStub.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c5f8ce6

Please sign in to comment.