Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust the scope of the spi extension #8600

Merged
merged 3 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.integration;

public interface Constants {

String MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY = "multipleConfigCenterServiceDiscoveryRegistry";

String SINGLE_CONFIG_CENTER_EXPORT_PROVIDER = "singleConfigCenterExportProvider";
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static org.apache.dubbo.integration.Constants.MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY;

/**
* The testcases are only for checking the process of exporting provider using service-discovery-registry protocol.
*/
Expand All @@ -52,11 +56,6 @@ public class MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest imple
*/
public static String PROVIDER_APPLICATION_NAME = "multiple-registry-center-provider-for-service-discovery-registry-protocol";

/**
* The name for getting the specified instance, which is loaded using SPI.
*/
private static String SPI_NAME = "multipleConfigCenterServiceDiscoveryRegistry";

/**
* Define the protocol's name.
*/
Expand Down Expand Up @@ -104,12 +103,16 @@ public void setUp() throws Exception {
serviceConfig.setRef(new MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl());
serviceConfig.setAsync(false);

// initailize bootstrap
// initialize bootstrap
for (RegistryCenter.Instance instance : registryCenter.getRegistryCenterInstance()) {
DubboBootstrap.getInstance().registry(new RegistryConfig(String.format("%s://%s:%s",
RegistryConfig registryConfig = new RegistryConfig(String.format("%s://%s:%s",
instance.getType(),
instance.getHostname(),
instance.getPort())));
instance.getPort()));
Map<String, String> parameters = new HashMap<>();
parameters.put("registry.listeners", MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY);
registryConfig.updateParameters(parameters);
DubboBootstrap.getInstance().registry(registryConfig);
ports.add(instance.getPort());
}
DubboBootstrap.getInstance()
Expand All @@ -118,7 +121,7 @@ public void setUp() throws Exception {
.service(serviceConfig);
// ---------------initialize--------------- //
registryServiceListener = (MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener) ExtensionLoader
.getExtensionLoader(RegistryServiceListener.class).getExtension(SPI_NAME);
.getExtensionLoader(RegistryServiceListener.class).getExtension(MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY);
// RegistryServiceListener is not null
Assertions.assertNotNull(registryServiceListener);
registryServiceListener.getStorage().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry;
import org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataService;

@Activate
import static org.apache.dubbo.integration.Constants.MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY;


@Activate(value = MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY)
public class MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener implements RegistryServiceListener {

private ServiceDiscoveryRegistryStorage storage = new ServiceDiscoveryRegistryStorage();

/**
* Create an {@link ServiceDiscoveryRegistryInfoWrapper} instance.
*/
private ServiceDiscoveryRegistryInfoWrapper createServiceDiscoveryRegistryInfoWrapper(ServiceDiscoveryRegistry serviceDiscoveryRegistry){
private ServiceDiscoveryRegistryInfoWrapper createServiceDiscoveryRegistryInfoWrapper(ServiceDiscoveryRegistry serviceDiscoveryRegistry) {
String host = serviceDiscoveryRegistry.getUrl().getHost();
int port = serviceDiscoveryRegistry.getUrl().getPort();
ServiceDiscoveryRegistryInfoWrapper serviceDiscoveryRegistryInfoWrapper = new ServiceDiscoveryRegistryInfoWrapper();
Expand All @@ -55,41 +58,41 @@ private boolean isCheckedApplication(Registry registry){

public void onRegister(URL url, Registry registry) {
if (registry instanceof ServiceDiscoveryRegistry && isCheckedApplication(registry)) {
ServiceDiscoveryRegistry serviceDiscoveryRegistry = (ServiceDiscoveryRegistry)registry;
ServiceDiscoveryRegistry serviceDiscoveryRegistry = (ServiceDiscoveryRegistry) registry;
String host = serviceDiscoveryRegistry.getUrl().getHost();
int port = serviceDiscoveryRegistry.getUrl().getPort();
if (!storage.contains(host,port)){
storage.put(host,port,createServiceDiscoveryRegistryInfoWrapper(serviceDiscoveryRegistry));
if (!storage.contains(host, port)) {
storage.put(host, port, createServiceDiscoveryRegistryInfoWrapper(serviceDiscoveryRegistry));
}
storage.get(host,port).setRegistered(true);
storage.get(host, port).setRegistered(true);
}
}

public void onUnregister(URL url, Registry registry) {
if (registry instanceof ServiceDiscoveryRegistry && isCheckedApplication(registry)) {
String host = registry.getUrl().getHost();
int port = registry.getUrl().getPort();
storage.get(host,port).setRegistered(false);
storage.get(host, port).setRegistered(false);
}
}

public void onSubscribe(URL url, Registry registry) {
if (registry instanceof ServiceDiscoveryRegistry && isCheckedApplication(registry)) {
ServiceDiscoveryRegistry serviceDiscoveryRegistry = (ServiceDiscoveryRegistry)registry;
ServiceDiscoveryRegistry serviceDiscoveryRegistry = (ServiceDiscoveryRegistry) registry;
String host = serviceDiscoveryRegistry.getUrl().getHost();
int port = serviceDiscoveryRegistry.getUrl().getPort();
if (!storage.contains(host,port)){
storage.put(host,port,createServiceDiscoveryRegistryInfoWrapper(serviceDiscoveryRegistry));
if (!storage.contains(host, port)) {
storage.put(host, port, createServiceDiscoveryRegistryInfoWrapper(serviceDiscoveryRegistry));
}
storage.get(host,port).setSubscribed(true);
storage.get(host, port).setSubscribed(true);
}
}

public void onUnsubscribe(URL url, Registry registry) {
if (registry instanceof ServiceDiscoveryRegistry && isCheckedApplication(registry)) {
String host = registry.getUrl().getHost();
int port = registry.getUrl().getPort();
storage.get(host,port).setSubscribed(false);
storage.get(host, port).setSubscribed(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static org.apache.dubbo.integration.Constants.SINGLE_CONFIG_CENTER_EXPORT_PROVIDER;
import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL;

/**
Expand All @@ -57,11 +60,6 @@ public class SingleRegistryCenterExportProviderIntegrationTest implements Integr
*/
private static String PROVIDER_APPLICATION_NAME = "single-registry-center-for-export-provider";

/**
* The name for getting the specified instance, which is loaded using SPI.
*/
private static String SPI_NAME = "singleConfigCenterExportProvider";

/**
* Define the protocol's name.
*/
Expand Down Expand Up @@ -113,16 +111,20 @@ public void setUp() throws Exception {
serviceConfig.setRef(new SingleRegistryCenterExportProviderServiceImpl());
serviceConfig.setAsync(false);

// initailize bootstrap
// initialize bootstrap
DubboBootstrap.getInstance()
.application(new ApplicationConfig(PROVIDER_APPLICATION_NAME))
.protocol(new ProtocolConfig(PROTOCOL_NAME, PROTOCOL_PORT))
.service(serviceConfig);
RegistryCenter.Instance instance = registryCenter.getRegistryCenterInstance().get(0);

RegistryConfig registryConfig = new RegistryConfig(String.format("%s://%s:%s",
instance.getType(),
instance.getHostname(),
instance.getPort()));
Map<String, String> parameters = new HashMap<>();
parameters.put("registry.protocol.listener", "singleConfigCenterExportProvider");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

registryConfig.updateParameters(parameters);
DubboBootstrap.getInstance().registry(registryConfig);
}

Expand All @@ -138,16 +140,16 @@ public void setUp() throws Exception {
private void beforeExport() {
registryProtocolListener = (SingleRegistryCenterExportProviderRegistryProtocolListener) ExtensionLoader
.getExtensionLoader(RegistryProtocolListener.class)
.getExtension(SPI_NAME);
.getExtension(SINGLE_CONFIG_CENTER_EXPORT_PROVIDER);
exporterListener = (SingleRegistryCenterExportProviderExporterListener) ExtensionLoader
.getExtensionLoader(ExporterListener.class)
.getExtension(SPI_NAME);
.getExtension(SINGLE_CONFIG_CENTER_EXPORT_PROVIDER);
filter = (SingleRegistryCenterExportProviderFilter) ExtensionLoader
.getExtensionLoader(Filter.class)
.getExtension(SPI_NAME);
.getExtension(SINGLE_CONFIG_CENTER_EXPORT_PROVIDER);
serviceListener = (SingleRegistryCenterExportProviderServiceListener) ExtensionLoader
.getExtensionLoader(ServiceListener.class)
.getExtension(SPI_NAME);
.getExtension(SINGLE_CONFIG_CENTER_EXPORT_PROVIDER);
// ---------------checkpoints--------------- //
// ServiceConfig isn't exported
Assertions.assertFalse(serviceConfig.isExported());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.cluster.ClusterInvoker;

import static org.apache.dubbo.integration.Constants.SINGLE_CONFIG_CENTER_EXPORT_PROVIDER;

/**
* The {@link RegistryProtocolListener} for {@link SingleRegistryCenterExportProviderService}
*/
@Activate(order = 100)
@Activate(order = 100, value = SINGLE_CONFIG_CENTER_EXPORT_PROVIDER)
public class SingleRegistryCenterExportProviderRegistryProtocolListener implements RegistryProtocolListener {

private boolean exported = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
#
# 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.
#

mockstatuschecker=org.apache.dubbo.config.mock.MockStatusChecker
mockstatuschecker=org.apache.dubbo.config.mock.MockStatusChecker
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
#
# 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.
#

mockthreadpool=org.apache.dubbo.config.mock.MockThreadPool
mockthreadpool=org.apache.dubbo.config.mock.MockThreadPool
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
#
# 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.
#

multipleConfigCenterServiceDiscoveryRegistry=org.apache.dubbo.integration.multiple.servicediscoveryregistry.MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener
Original file line number Diff line number Diff line change
@@ -1,19 +1,2 @@
#
# 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.
#

singleConfigCenterExportProvider=org.apache.dubbo.integration.single.exportprovider.SingleRegistryCenterExportProviderRegistryProtocolListener
multipleConfigCenterExportProvider=org.apache.dubbo.integration.multiple.exportprovider.MultipleRegistryCenterExportProviderRegistryProtocolListener
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
#
# 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.
#

mockdispatcher=org.apache.dubbo.config.mock.MockDispatcher
mockdispatcher=org.apache.dubbo.config.mock.MockDispatcher
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
#
# 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.
#

mocktransporter=org.apache.dubbo.config.mock.MockTransporter
mocktransporter=org.apache.dubbo.config.mock.MockTransporter
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
#
# 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.
#

mockexchanger=org.apache.dubbo.config.mock.MockExchanger
mockexchanger=org.apache.dubbo.config.mock.MockExchanger
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
#
# 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.
#
mocktelnethandler=org.apache.dubbo.config.mock.MockTelnetHandler

Loading