Skip to content

Commit

Permalink
Polish apache#6333 : [Refactor] Using mandatory implementation of Ser…
Browse files Browse the repository at this point in the history
…vice Instance registration instead of the event
  • Loading branch information
mercyblitz committed Jun 16, 2020
1 parent eba44fa commit c546f3c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.apache.dubbo.registry.client.ServiceDiscovery;
import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.client.ServiceInstanceCustomizer;
import org.apache.dubbo.registry.support.AbstractRegistryFactory;
import org.apache.dubbo.rpc.model.ApplicationModel;

Expand Down Expand Up @@ -1085,9 +1086,37 @@ private void registerServiceInstance() {

ServiceInstance serviceInstance = createServiceInstance(serviceName, host, port);

preRegisterServiceInstance(serviceInstance);

getServiceDiscoveries().forEach(serviceDiscovery -> serviceDiscovery.register(serviceInstance));
}

/**
* Pre-register {@link ServiceInstance the service instance}
*
* @param serviceInstance {@link ServiceInstance the service instance}
* @since 2.7.8
*/
private void preRegisterServiceInstance(ServiceInstance serviceInstance) {
customizeServiceInstance(serviceInstance);
}

/**
* Customize {@link ServiceInstance the service instance}
*
* @param serviceInstance {@link ServiceInstance the service instance}
* @since 2.7.8
*/
private void customizeServiceInstance(ServiceInstance serviceInstance) {
ExtensionLoader<ServiceInstanceCustomizer> loader =
ExtensionLoader.getExtensionLoader(ServiceInstanceCustomizer.class);
// FIXME, sort customizer before apply
loader.getSupportedExtensionInstances().forEach(customizer -> {
// customizes
customizer.customize(serviceInstance);
});
}

private URL selectMetadataServiceExportedURL() {

URL selectedURL = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
* Customize the {@link ServiceInstance} before registering to Registry.
*
* @since 2.7.5
* @deprecated 2.7.8 Current class will be removed since 3.0.0
*/
@Deprecated
public class CustomizableServiceInstanceListener implements EventListener<ServiceInstancePreRegisteredEvent> {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
service-instance=org.apache.dubbo.registry.client.event.listener.CustomizableServiceInstanceListener
# "service-instance" has been deprecated since 2.7.8
# service-instance=org.apache.dubbo.registry.client.event.listener.CustomizableServiceInstanceListener

registry-logging=org.apache.dubbo.registry.client.event.listener.LoggingEventListener

# "publishing-remote-metadata" in introduced since 2.7.8
publishing-remote-metadata=org.apache.dubbo.registry.client.event.listener.PublishingRemoteMetadataListener

0 comments on commit c546f3c

Please sign in to comment.