Class AbstractInstanceRegistry

  • All Implemented Interfaces:
    com.netflix.discovery.shared.LookupService<java.lang.String>, LeaseManager<com.netflix.appinfo.InstanceInfo>, InstanceRegistry
    Direct Known Subclasses:
    PeerAwareInstanceRegistryImpl

    public abstract class AbstractInstanceRegistry
    extends java.lang.Object
    implements InstanceRegistry
    Handles all registry requests from eureka clients.

    Primary operations that are performed are the Registers, Renewals, Cancels, Expirations, and Status Changes. The registry also stores only the delta operations

    • Field Detail

      • regionNameVSRemoteRegistry

        protected java.util.Map<java.lang.String,​RemoteRegionRegistry> regionNameVSRemoteRegistry
      • overriddenInstanceStatusMap

        protected final java.util.concurrent.ConcurrentMap<java.lang.String,​com.netflix.appinfo.InstanceInfo.InstanceStatus> overriddenInstanceStatusMap
      • lock

        protected final java.lang.Object lock
      • allKnownRemoteRegions

        protected java.lang.String[] allKnownRemoteRegions
      • numberOfRenewsPerMinThreshold

        protected volatile int numberOfRenewsPerMinThreshold
      • expectedNumberOfClientsSendingRenews

        protected volatile int expectedNumberOfClientsSendingRenews
      • clientConfig

        protected final com.netflix.discovery.EurekaClientConfig clientConfig
    • Method Detail

      • initRemoteRegionRegistry

        protected void initRemoteRegionRegistry()
                                         throws java.net.MalformedURLException
        Throws:
        java.net.MalformedURLException
      • getLocalRegistrySize

        public long getLocalRegistrySize()
      • register

        public void register​(com.netflix.appinfo.InstanceInfo registrant,
                             int leaseDuration,
                             boolean isReplication)
        Registers a new instance with a given duration.
        Specified by:
        register in interface LeaseManager<com.netflix.appinfo.InstanceInfo>
        Parameters:
        registrant - - T to register
        isReplication - - whether this is a replicated entry from another eureka node.
        See Also:
        LeaseManager.register(java.lang.Object, int, boolean)
      • cancel

        public boolean cancel​(java.lang.String appName,
                              java.lang.String id,
                              boolean isReplication)
        Cancels the registration of an instance.

        This is normally invoked by a client when it shuts down informing the server to remove the instance from traffic.

        Specified by:
        cancel in interface LeaseManager<com.netflix.appinfo.InstanceInfo>
        Parameters:
        appName - the application name of the application.
        id - the unique identifier of the instance.
        isReplication - true if this is a replication event from other nodes, false otherwise.
        Returns:
        true if the instance was removed from the AbstractInstanceRegistry successfully, false otherwise.
      • internalCancel

        protected boolean internalCancel​(java.lang.String appName,
                                         java.lang.String id,
                                         boolean isReplication)
        cancel(String, String, boolean) method is overridden by PeerAwareInstanceRegistry, so each cancel request is replicated to the peers. This is however not desired for expires which would be counted in the remote peers as valid cancellations, so self preservation mode would not kick-in.
      • renew

        public boolean renew​(java.lang.String appName,
                             java.lang.String id,
                             boolean isReplication)
        Marks the given instance of the given app name as renewed, and also marks whether it originated from replication.
        Specified by:
        renew in interface LeaseManager<com.netflix.appinfo.InstanceInfo>
        id - - unique id within appName
        isReplication - - whether this is a replicated entry from another ds node
        Returns:
        whether the operation of successful
        See Also:
        LeaseManager.renew(java.lang.String, java.lang.String, boolean)
      • storeOverriddenStatusIfRequired

        @Deprecated
        public void storeOverriddenStatusIfRequired​(java.lang.String id,
                                                    com.netflix.appinfo.InstanceInfo.InstanceStatus overriddenStatus)
        Deprecated.
        this is expensive, try not to use. See if you can use storeOverriddenStatusIfRequired(String, String, InstanceStatus) instead. Stores overridden status if it is not already there. This happens during a reconciliation process during renewal requests.
        Specified by:
        storeOverriddenStatusIfRequired in interface InstanceRegistry
        Parameters:
        id - the unique identifier of the instance.
        overriddenStatus - Overridden status if any.
      • storeOverriddenStatusIfRequired

        public void storeOverriddenStatusIfRequired​(java.lang.String appName,
                                                    java.lang.String id,
                                                    com.netflix.appinfo.InstanceInfo.InstanceStatus overriddenStatus)
        Stores overridden status if it is not already there. This happens during a reconciliation process during renewal requests.
        Specified by:
        storeOverriddenStatusIfRequired in interface InstanceRegistry
        Parameters:
        appName - the application name of the instance.
        id - the unique identifier of the instance.
        overriddenStatus - overridden status if any.
      • statusUpdate

        public boolean statusUpdate​(java.lang.String appName,
                                    java.lang.String id,
                                    com.netflix.appinfo.InstanceInfo.InstanceStatus newStatus,
                                    java.lang.String lastDirtyTimestamp,
                                    boolean isReplication)
        Updates the status of an instance. Normally happens to put an instance between InstanceInfo.InstanceStatus.OUT_OF_SERVICE and InstanceInfo.InstanceStatus.UP to put the instance in and out of traffic.
        Specified by:
        statusUpdate in interface InstanceRegistry
        Parameters:
        appName - the application name of the instance.
        id - the unique identifier of the instance.
        newStatus - the new InstanceInfo.InstanceStatus.
        lastDirtyTimestamp - last timestamp when this instance information was updated.
        isReplication - true if this is a replication event from other nodes, false otherwise.
        Returns:
        true if the status was successfully updated, false otherwise.
      • deleteStatusOverride

        public boolean deleteStatusOverride​(java.lang.String appName,
                                            java.lang.String id,
                                            com.netflix.appinfo.InstanceInfo.InstanceStatus newStatus,
                                            java.lang.String lastDirtyTimestamp,
                                            boolean isReplication)
        Removes status override for a give instance.
        Specified by:
        deleteStatusOverride in interface InstanceRegistry
        Parameters:
        appName - the application name of the instance.
        id - the unique identifier of the instance.
        newStatus - the new InstanceInfo.InstanceStatus.
        lastDirtyTimestamp - last timestamp when this instance information was updated.
        isReplication - true if this is a replication event from other nodes, false otherwise.
        Returns:
        true if the status was successfully updated, false otherwise.
      • evict

        public void evict()
        Evicts everything in the instance registry that has expired, if expiry is enabled.
        Specified by:
        evict in interface LeaseManager<com.netflix.appinfo.InstanceInfo>
        See Also:
        LeaseManager.evict()
      • evict

        public void evict​(long additionalLeaseMs)
      • getApplication

        public com.netflix.discovery.shared.Application getApplication​(java.lang.String appName)
        Returns the given app that is in this instance only, falling back to other regions transparently only if specified in this client configuration.
        Specified by:
        getApplication in interface com.netflix.discovery.shared.LookupService<java.lang.String>
        Parameters:
        appName - the application name of the application
        Returns:
        the application
        See Also:
        LookupService.getApplication(java.lang.String)
      • getApplication

        public com.netflix.discovery.shared.Application getApplication​(java.lang.String appName,
                                                                       boolean includeRemoteRegion)
        Get application information.
        Specified by:
        getApplication in interface InstanceRegistry
        Parameters:
        appName - The name of the application
        includeRemoteRegion - true, if we need to include applications from remote regions as indicated by the region URL by this property EurekaServerConfig.getRemoteRegionUrls(), false otherwise
        Returns:
        the application
      • getApplications

        public com.netflix.discovery.shared.Applications getApplications()
        Get all applications in this instance registry, falling back to other regions if allowed in the Eureka config.
        Specified by:
        getApplications in interface com.netflix.discovery.shared.LookupService<java.lang.String>
        Returns:
        the list of all known applications
        See Also:
        LookupService.getApplications()
      • getApplicationsFromAllRemoteRegions

        public com.netflix.discovery.shared.Applications getApplicationsFromAllRemoteRegions()
        Returns applications including instances from all remote regions.
        Same as calling getApplicationsFromMultipleRegions(String[]) with a null argument.
      • getApplicationsFromMultipleRegions

        public com.netflix.discovery.shared.Applications getApplicationsFromMultipleRegions​(java.lang.String[] remoteRegions)
        This method will return applications with instances from all passed remote regions as well as the current region. Thus, this gives a union view of instances from multiple regions.
        The application instances for which this union will be done can be restricted to the names returned by EurekaServerConfig.getRemoteRegionAppWhitelist(String) for every region. In case, there is no whitelist defined for a region, this method will also look for a global whitelist by passing null to the method EurekaServerConfig.getRemoteRegionAppWhitelist(String)
        If you are not selectively requesting for a remote region, use getApplicationsFromAllRemoteRegions() or getApplicationsFromLocalRegionOnly()
        Parameters:
        remoteRegions - The remote regions for which the instances are to be queried. The instances may be limited by a whitelist as explained above. If null or empty no remote regions are included.
        Returns:
        The applications with instances from the passed remote regions as well as local region. The instances from remote regions can be only for certain whitelisted apps as explained above.
      • getApplications

        @Deprecated
        public com.netflix.discovery.shared.Applications getApplications​(boolean includeRemoteRegion)
        Deprecated.
        Use getApplicationsFromMultipleRegions(String[]) instead. This method has a flawed behavior of transparently falling back to a remote region if no instances for an app is available locally. The new behavior is to explicitly specify if you need a remote region.
        Get the registry information about all Applications.
        Parameters:
        includeRemoteRegion - true, if we need to include applications from remote regions as indicated by the region URL by this property EurekaServerConfig.getRemoteRegionUrls(), false otherwise
        Returns:
        applications
      • getApplicationDeltas

        @Deprecated
        public com.netflix.discovery.shared.Applications getApplicationDeltas()
        Deprecated.
        use getApplicationDeltasFromMultipleRegions(String[]) instead. This method has a flawed behavior of transparently falling back to a remote region if no instances for an app is available locally. The new behavior is to explicitly specify if you need a remote region.
        Get the registry information about the delta changes. The deltas are cached for a window specified by EurekaServerConfig.getRetentionTimeInMSInDeltaQueue(). Subsequent requests for delta information may return the same information and client must make sure this does not adversely affect them.
        Returns:
        all application deltas.
      • getApplicationDeltasFromMultipleRegions

        public com.netflix.discovery.shared.Applications getApplicationDeltasFromMultipleRegions​(java.lang.String[] remoteRegions)
        Gets the application delta also including instances from the passed remote regions, with the instances from the local region.
        The remote regions from where the instances will be chosen can further be restricted if this application does not appear in the whitelist specified for the region as returned by EurekaServerConfig.getRemoteRegionAppWhitelist(String) for a region. In case, there is no whitelist defined for a region, this method will also look for a global whitelist by passing null to the method EurekaServerConfig.getRemoteRegionAppWhitelist(String)
        Parameters:
        remoteRegions - The remote regions for which the instances are to be queried. The instances may be limited by a whitelist as explained above. If null all remote regions are included. If empty list then no remote region is included.
        Returns:
        The delta with instances from the passed remote regions as well as local region. The instances from remote regions can be further be restricted as explained above. null if the application does not exist locally or in remote regions.
      • getInstanceByAppAndId

        public com.netflix.appinfo.InstanceInfo getInstanceByAppAndId​(java.lang.String appName,
                                                                      java.lang.String id)
        Gets the InstanceInfo information.
        Specified by:
        getInstanceByAppAndId in interface InstanceRegistry
        Parameters:
        appName - the application name for which the information is requested.
        id - the unique identifier of the instance.
        Returns:
        the information about the instance.
      • getInstanceByAppAndId

        public com.netflix.appinfo.InstanceInfo getInstanceByAppAndId​(java.lang.String appName,
                                                                      java.lang.String id,
                                                                      boolean includeRemoteRegions)
        Gets the InstanceInfo information.
        Specified by:
        getInstanceByAppAndId in interface InstanceRegistry
        Parameters:
        appName - the application name for which the information is requested.
        id - the unique identifier of the instance.
        includeRemoteRegions - true, if we need to include applications from remote regions as indicated by the region URL by this property EurekaServerConfig.getRemoteRegionUrls(), false otherwise
        Returns:
        the information about the instance.
      • getInstancesById

        @Deprecated
        public java.util.List<com.netflix.appinfo.InstanceInfo> getInstancesById​(java.lang.String id)
        Deprecated.
        Try getInstanceByAppAndId(String, String) instead. Get all instances by ID, including automatically asking other regions if the ID is unknown.
        Specified by:
        getInstancesById in interface com.netflix.discovery.shared.LookupService<java.lang.String>
        See Also:
        LookupService.getInstancesById(String)
      • getInstancesById

        @Deprecated
        public java.util.List<com.netflix.appinfo.InstanceInfo> getInstancesById​(java.lang.String id,
                                                                                 boolean includeRemoteRegions)
        Deprecated.
        Try getInstanceByAppAndId(String, String, boolean) instead. Get the list of instances by its unique id.
        Parameters:
        id - the unique id of the instance
        includeRemoteRegions - true, if we need to include applications from remote regions as indicated by the region URL by this property EurekaServerConfig.getRemoteRegionUrls(), false otherwise
        Returns:
        list of InstanceInfo objects.
      • getNumOfRenewsInLastMin

        @Monitor(name="numOfRenewsInLastMin",
                 description="Number of total heartbeats received in the last minute",
                 type=GAUGE)
        public long getNumOfRenewsInLastMin()
        Servo route; do not call.
        Specified by:
        getNumOfRenewsInLastMin in interface InstanceRegistry
        Returns:
        servo data
      • getNumOfRenewsPerMinThreshold

        @Monitor(name="numOfRenewsPerMinThreshold",
                 type=GAUGE)
        public int getNumOfRenewsPerMinThreshold()
        Gets the threshold for the renewals per minute.
        Specified by:
        getNumOfRenewsPerMinThreshold in interface InstanceRegistry
        Returns:
        the integer representing the threshold for the renewals per minute.
      • getLastNRegisteredInstances

        public java.util.List<com.netflix.discovery.shared.Pair<java.lang.Long,​java.lang.String>> getLastNRegisteredInstances()
        Get the N instances that are most recently registered.
        Specified by:
        getLastNRegisteredInstances in interface InstanceRegistry
        Returns:
      • getLastNCanceledInstances

        public java.util.List<com.netflix.discovery.shared.Pair<java.lang.Long,​java.lang.String>> getLastNCanceledInstances()
        Get the N instances that have most recently canceled.
        Specified by:
        getLastNCanceledInstances in interface InstanceRegistry
        Returns:
      • updateRenewsPerMinThreshold

        protected void updateRenewsPerMinThreshold()
      • postInit

        protected void postInit()
      • shutdown

        public void shutdown()
        Perform all cleanup and shutdown operations.
        Specified by:
        shutdown in interface InstanceRegistry
      • getNumberofElementsininstanceCache

        @Monitor(name="numOfElementsinInstanceCache",
                 description="Number of overrides in the instance Cache",
                 type=GAUGE)
        public long getNumberofElementsininstanceCache()
      • getInstanceInfoOverrideRule

        protected abstract InstanceStatusOverrideRule getInstanceInfoOverrideRule()
        Returns:
        The rule that will process the instance status override.
      • getOverriddenInstanceStatus

        protected com.netflix.appinfo.InstanceInfo.InstanceStatus getOverriddenInstanceStatus​(com.netflix.appinfo.InstanceInfo r,
                                                                                              Lease<com.netflix.appinfo.InstanceInfo> existingLease,
                                                                                              boolean isReplication)