Skip to content

Commit

Permalink
Make stub implement Destroyable
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenlj committed Sep 27, 2024
1 parent a9db42a commit e40e117
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ 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.service.Destroyable;
import org.apache.dubbo.rpc.stub.BiStreamMethodHandler;
import org.apache.dubbo.rpc.stub.ServerStreamMethodHandler;
import org.apache.dubbo.rpc.stub.StubInvocationUtil;
Expand Down Expand Up @@ -130,13 +131,18 @@ public final class {{className}} {
{{/biStreamingWithoutClientStreamMethods}}
}

public static class {{interfaceClassName}}Stub implements {{interfaceClassName}}{
public static class {{interfaceClassName}}Stub implements {{interfaceClassName}}, Destroyable {
private final Invoker<{{interfaceClassName}}> invoker;

public {{interfaceClassName}}Stub(Invoker<{{interfaceClassName}}> invoker) {
this.invoker = invoker;
}

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

{{#unaryMethods}}
{{#javaDoc}}
{{{javaDoc}}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static RemoteMetadataService referMetadataService(ServiceInstance instanc
}

remoteMetadataService =
new RemoteMetadataService(consumerModel, proxyFactory.getProxy(invoker), invoker, internalModel);
new RemoteMetadataService(consumerModel, proxyFactory.getProxy(invoker), internalModel);
} else {
Invoker<MetadataService> invoker = protocol.refer(MetadataService.class, url);

Expand All @@ -198,7 +198,7 @@ public static RemoteMetadataService referMetadataService(ServiceInstance instanc
}

remoteMetadataService =
new RemoteMetadataService(consumerModel, proxyFactory.getProxy(invoker), invoker, internalModel);
new RemoteMetadataService(consumerModel, proxyFactory.getProxy(invoker), internalModel);
}

Object metadataServiceProxy = remoteMetadataService.getInternalProxy();
Expand Down Expand Up @@ -320,36 +320,28 @@ public static class RemoteMetadataService {

private MetadataServiceV2 proxyV2;

private Invoker<?> invoker;

private final ModuleModel internalModel;

public RemoteMetadataService(
ConsumerModel consumerModel, MetadataService proxy, Invoker<?> invoker, ModuleModel internalModel) {
public RemoteMetadataService(ConsumerModel consumerModel, MetadataService proxy, ModuleModel internalModel) {
this.consumerModel = consumerModel;
this.proxy = proxy;
this.invoker = invoker;
this.internalModel = internalModel;
}

public RemoteMetadataService(
ConsumerModel consumerModel, MetadataServiceV2 proxyV2, Invoker<?> invoker, ModuleModel internalModel) {
ConsumerModel consumerModel, MetadataServiceV2 proxyV2, ModuleModel internalModel) {
this.consumerModel = consumerModel;
this.proxyV2 = proxyV2;
this.invoker = invoker;
this.internalModel = internalModel;
}

public void destroy() {
// proxy is a reflection proxy that implements Destroyable, call $destroy() will delegate to
// invoker.destroy()
if (proxy instanceof Destroyable) {
((Destroyable) proxy).$destroy();
}

// proxyV2 is a stub proxy so it's not an instance of Destroyable
if (proxyV2 != null) {
this.invoker.destroy();
if (proxyV2 instanceof Destroyable) {
((Destroyable) proxyV2).$destroy();
}

internalModel.getServiceRepository().unregisterConsumer(consumerModel);
Expand Down

0 comments on commit e40e117

Please sign in to comment.