Class AbstractServiceDiscovery

java.lang.Object
org.apache.dubbo.registry.client.AbstractServiceDiscovery
All Implemented Interfaces:
Comparable<Prioritized>, Prioritized, ServiceDiscovery, RegistryService
Direct Known Subclasses:
NopServiceDiscovery, ReflectionBasedServiceDiscovery

public abstract class AbstractServiceDiscovery extends Object implements ServiceDiscovery
Each service discovery is bond to one application.
  • Constructor Details

    • AbstractServiceDiscovery

      public AbstractServiceDiscovery(ApplicationModel applicationModel, URL registryURL)
    • AbstractServiceDiscovery

      public AbstractServiceDiscovery(String serviceName, URL registryURL)
  • Method Details

    • register

      public void register() throws RuntimeException
      Specified by:
      register in interface ServiceDiscovery
      Throws:
      RuntimeException
    • update

      public void update() throws RuntimeException
      Update assumes that DefaultServiceInstance and its attributes will never get updated once created. Checking hasExportedServices() before registration guarantees that at least one service is ready for creating the instance.
      Specified by:
      update in interface ServiceDiscovery
      Throws:
      RuntimeException
    • unregister

      public void unregister() throws RuntimeException
      Specified by:
      unregister in interface ServiceDiscovery
      Throws:
      RuntimeException
    • getLocalInstance

      public final ServiceInstance getLocalInstance()
      Specified by:
      getLocalInstance in interface ServiceDiscovery
    • getLocalMetadata

      public MetadataInfo getLocalMetadata()
      Specified by:
      getLocalMetadata in interface ServiceDiscovery
    • getLocalMetadata

      public MetadataInfo getLocalMetadata(String revision)
      Specified by:
      getLocalMetadata in interface ServiceDiscovery
    • getRemoteMetadata

      public MetadataInfo getRemoteMetadata(String revision, List<ServiceInstance> instances)
      Specified by:
      getRemoteMetadata in interface ServiceDiscovery
    • getRemoteMetadata

      public MetadataInfo getRemoteMetadata(String revision)
      Specified by:
      getRemoteMetadata in interface ServiceDiscovery
    • destroy

      public final void destroy() throws Exception
      Description copied from interface: ServiceDiscovery
      Destroy the ServiceDiscovery
      Specified by:
      destroy in interface ServiceDiscovery
      Throws:
      Exception - If met with error
    • isDestroy

      public final boolean isDestroy()
      Specified by:
      isDestroy in interface ServiceDiscovery
    • register

      public void register(URL url)
      Description copied from interface: RegistryService
      Register data, such as : provider service, consumer address, route rule, override rule and other data.

      Registering is required to support the contract:
      1. When the URL sets the check=false parameter. When the registration fails, the exception is not thrown and retried in the background. Otherwise, the exception will be thrown.
      2. When URL sets the dynamic=false parameter, it needs to be stored persistently, otherwise, it should be deleted automatically when the registrant has an abnormal exit.
      3. When the URL sets category=routers, it means classified storage, the default category is providers, and the data can be notified by the classified section.
      4. When the registry is restarted, network jitter, data can not be lost, including automatically deleting data from the broken line.
      5. Allow URLs which have the same URL but different parameters to coexist,they can't cover each other.

      Specified by:
      register in interface RegistryService
      Parameters:
      url - Registration information , is not allowed to be empty, e.g: dubbo://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0invalid input: '&application'=kylin
    • unregister

      public void unregister(URL url)
      Description copied from interface: RegistryService
      Unregister

      Unregistering is required to support the contract:
      1. If it is the persistent stored data of dynamic=false, the registration data can not be found, then the IllegalStateException is thrown, otherwise it is ignored.
      2. Unregister according to the full url match.

      Specified by:
      unregister in interface RegistryService
      Parameters:
      url - Registration information , is not allowed to be empty, e.g: dubbo://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0invalid input: '&application'=kylin
    • subscribe

      public void subscribe(URL url, NotifyListener listener)
      Description copied from interface: RegistryService
      Subscribe to eligible registered data and automatically push when the registered data is changed.

      Subscribing need to support contracts:
      1. When the URL sets the check=false parameter. When the registration fails, the exception is not thrown and retried in the background.
      2. When URL sets category=routers, it only notifies the specified classification data. Multiple classifications are separated by commas, and allows asterisk to match, which indicates that all categorical data are subscribed.
      3. Allow interface, group, version, and classifier as a conditional query, e.g.: interface=org.apache.dubbo.foo.BarServiceinvalid input: '&version'=1.0.0
      4. And the query conditions allow the asterisk to be matched, subscribe to all versions of all the packets of all interfaces, e.g. :interface=*invalid input: '&group'=*invalid input: '&version'=*invalid input: '&classifier'=*
      5. When the registry is restarted and network jitter, it is necessary to automatically restore the subscription request.
      6. Allow URLs which have the same URL but different parameters to coexist,they can't cover each other.
      7. The subscription process must be blocked, when the first notice is finished and then returned.

      Specified by:
      subscribe in interface RegistryService
      Parameters:
      url - Subscription condition, not allowed to be empty, e.g. consumer://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0invalid input: '&application'=kylin
      listener - A listener of the change event, not allowed to be empty
    • unsubscribe

      public void unsubscribe(URL url, NotifyListener listener)
      Description copied from interface: RegistryService
      Unsubscribe

      Unsubscribing is required to support the contract:
      1. If you don't subscribe, ignore it directly.
      2. Unsubscribe by full URL match.

      Specified by:
      unsubscribe in interface RegistryService
      Parameters:
      url - Subscription condition, not allowed to be empty, e.g. consumer://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0invalid input: '&application'=kylin
      listener - A listener of the change event, not allowed to be empty
    • lookup

      public List<URL> lookup(URL url)
      Description copied from interface: RegistryService
      Query the registered data that matches the conditions. Corresponding to the push mode of the subscription, this is the pull mode and returns only one result.
      Specified by:
      lookup in interface RegistryService
      Parameters:
      url - Query condition, is not allowed to be empty, e.g. consumer://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0invalid input: '&application'=kylin
      Returns:
      The registered information list, which may be empty, the meaning is the same as the parameters of NotifyListener.notify(List<URL>).
      See Also:
    • getUrl

      public URL getUrl()
      Specified by:
      getUrl in interface ServiceDiscovery