Skip to content

Commit

Permalink
feat:remove ZookeeperTransporter SPI (#13960)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stellar1999 committed Apr 8, 2024
1 parent cb220be commit 5ceb6e4
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 102 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ check 2.7.5 milestone for details.

### Notice

'zkclient' extension for 'org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter' is removed from Dubbo 2.7.1, and 'curator' extension becomes the default extension. If you happen to config your application to use 'zkclient' explicitly, pls. switch to use 'curator' instead.
'zkclient' extension for 'org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperTransporter' is removed from Dubbo 2.7.1, and 'curator' extension becomes the default extension. If you happen to config your application to use 'zkclient' explicitly, pls. switch to use 'curator' instead.

### New Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
package com.alibaba.dubbo.remoting.zookeeper;

@Deprecated
public interface ZookeeperTransporter extends org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter {}
public interface ZookeeperTransporter extends org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperTransporter {}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperTransporter;
import org.apache.dubbo.rpc.model.ApplicationModel;

import java.util.Collection;
Expand Down Expand Up @@ -107,7 +107,7 @@ protected void doClose() throws Exception {

// zkClient is shared in framework, should not close it here
// zkClient.close();
// See: org.apache.dubbo.remoting.zookeeper.AbstractZookeeperTransporter#destroy()
// See: org.apache.dubbo.remoting.zookeeper.curator5.AbstractZookeeperTransporter#destroy()
// All zk clients is created and destroyed in ZookeeperTransporter.
zkClient = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory;
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperTransporter;
import org.apache.dubbo.rpc.model.ApplicationModel;

public class ZookeeperDynamicConfigurationFactory extends AbstractDynamicConfigurationFactory {
Expand All @@ -30,7 +30,7 @@ public class ZookeeperDynamicConfigurationFactory extends AbstractDynamicConfigu

public ZookeeperDynamicConfigurationFactory(ApplicationModel applicationModel) {
this.applicationModel = applicationModel;
this.zookeeperTransporter = ZookeeperTransporter.getExtension(applicationModel);
this.zookeeperTransporter = ZookeeperTransporter.getInstance(applicationModel);
}

@Override
Expand Down
3 changes: 0 additions & 3 deletions dubbo-distribution/dubbo-all-shaded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,6 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.rpc.ExporterListener</resource>
</transformer>
Expand Down
3 changes: 0 additions & 3 deletions dubbo-distribution/dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,6 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.rpc.ExporterListener</resource>
</transformer>
Expand Down
3 changes: 0 additions & 3 deletions dubbo-distribution/dubbo-core-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,6 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.rpc.ExporterListener</resource>
</transformer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.apache.dubbo.remoting.zookeeper.DataListener;
import org.apache.dubbo.remoting.zookeeper.EventType;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperTransporter;

import java.util.ArrayList;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.dubbo.common.extension.DisableInject;
import org.apache.dubbo.metadata.report.MetadataReport;
import org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperTransporter;
import org.apache.dubbo.rpc.model.ApplicationModel;

/**
Expand All @@ -34,7 +34,7 @@ public class ZookeeperMetadataReportFactory extends AbstractMetadataReportFactor

public ZookeeperMetadataReportFactory(ApplicationModel applicationModel) {
this.applicationModel = applicationModel;
this.zookeeperTransporter = ZookeeperTransporter.getExtension(applicationModel);
this.zookeeperTransporter = ZookeeperTransporter.getInstance(applicationModel);
}

@DisableInject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.apache.dubbo.remoting.zookeeper.ChildListener;
import org.apache.dubbo.remoting.zookeeper.StateListener;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperTransporter;
import org.apache.dubbo.rpc.RpcException;

import java.util.ArrayList;
Expand Down Expand Up @@ -156,7 +156,7 @@ public void destroy() {
zkListeners.clear();

// Just release zkClient reference, but can not close zk client here for zk client is shared somewhere else.
// See org.apache.dubbo.remoting.zookeeper.AbstractZookeeperTransporter#destroy()
// See org.apache.dubbo.remoting.zookeeper.curator5.AbstractZookeeperTransporter#destroy()
zkClient = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.dubbo.common.extension.DisableInject;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.support.AbstractRegistryFactory;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperTransporter;
import org.apache.dubbo.rpc.model.ApplicationModel;

/**
Expand All @@ -37,7 +37,7 @@ public ZookeeperRegistryFactory() {

public ZookeeperRegistryFactory(ApplicationModel applicationModel) {
this.applicationModel = applicationModel;
this.zookeeperTransporter = ZookeeperTransporter.getExtension(applicationModel);
this.zookeeperTransporter = ZookeeperTransporter.getInstance(applicationModel);
}

@DisableInject
Expand Down
1 change: 1 addition & 0 deletions dubbo-remoting/dubbo-remoting-zookeeper-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>

</dependencies>
</project>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.remoting.zookeeper;
package org.apache.dubbo.remoting.zookeeper.curator5;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.url.component.ServiceConfigURL;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -78,7 +79,7 @@ public ZookeeperClient connect(URL url) {
/**
* @param url the url that will create zookeeper connection .
* The url in AbstractZookeeperTransporter#connect parameter is rewritten by this one.
* such as: zookeeper://127.0.0.1:2181/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter
* such as: zookeeper://127.0.0.1:2181/org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperTransporter
* @return
*/
protected abstract ZookeeperClient createZookeeperClient(URL url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.dubbo.remoting.zookeeper.curator5;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperTransporter;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;

public class Curator5ZookeeperTransporter extends AbstractZookeeperTransporter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.remoting;
package org.apache.dubbo.remoting.zookeeper.curator5;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ScopeModelInitializer;

import java.util.List;

import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_DESTROY_ZOOKEEPER;

/**
* Scope model initializer for remoting-api
*/
public class RemotingScopeModelInitializer implements ScopeModelInitializer {
public interface ZookeeperTransporter {

private static final ErrorTypeAwareLogger logger =
LoggerFactory.getErrorTypeAwareLogger(RemotingScopeModelInitializer.class);
ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(ZookeeperTransporter.class);

@Override
public void initializeFrameworkModel(FrameworkModel frameworkModel) {}
ZookeeperClient connect(URL url);

@Override
public void initializeApplicationModel(ApplicationModel applicationModel) {
void destroy();

static ZookeeperTransporter getInstance(ApplicationModel applicationModel) {
ZookeeperTransporter transporter = new Curator5ZookeeperTransporter();
applicationModel.addDestroyListener(m -> {
// destroy zookeeper clients if any
try {
List<ZookeeperTransporter> transporters = applicationModel
.getExtensionLoader(ZookeeperTransporter.class)
.getLoadedExtensionInstances();
for (ZookeeperTransporter zkTransporter : transporters) {
zkTransporter.destroy();
}
transporter.destroy();
} catch (Exception e) {
logger.error(
TRANSPORT_FAILED_DESTROY_ZOOKEEPER,
Expand All @@ -59,8 +47,6 @@ public void initializeApplicationModel(ApplicationModel applicationModel) {
e);
}
});
return transporter;
}

@Override
public void initializeModuleModel(ModuleModel moduleModel) {}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package org.apache.dubbo.remoting.zookeeper.curator5.support;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperTransporter;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
import org.apache.dubbo.remoting.zookeeper.curator5.AbstractZookeeperTransporter;
import org.apache.dubbo.remoting.zookeeper.curator5.Curator5ZookeeperTransporter;

import java.util.List;
Expand Down

0 comments on commit 5ceb6e4

Please sign in to comment.