Package com.netflix.eureka.registry
Class AbstractInstanceRegistry
- java.lang.Object
-
- com.netflix.eureka.registry.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 Summary
Fields Modifier and Type Field Description protected java.lang.String[]allKnownRemoteRegionsprotected com.netflix.discovery.EurekaClientConfigclientConfigprotected intexpectedNumberOfClientsSendingRenewsprotected java.lang.Objectlockprotected intnumberOfRenewsPerMinThresholdprotected java.util.concurrent.ConcurrentMap<java.lang.String,com.netflix.appinfo.InstanceInfo.InstanceStatus>overriddenInstanceStatusMapprotected java.util.Map<java.lang.String,RemoteRegionRegistry>regionNameVSRemoteRegistryprotected ResponseCacheresponseCacheprotected ServerCodecsserverCodecsprotected EurekaServerConfigserverConfig
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractInstanceRegistry(EurekaServerConfig serverConfig, com.netflix.discovery.EurekaClientConfig clientConfig, ServerCodecs serverCodecs, EurekaServerHttpClientFactory eurekaServerHttpClientFactory)Create a new, empty instance registry.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancancel(java.lang.String appName, java.lang.String id, boolean isReplication)Cancels the registration of an instance.voidclearRegistry()Completely clear the registry.booleandeleteStatusOverride(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.voidevict()Evicts everything in the instance registry that has expired, if expiry is enabled.voidevict(long additionalLeaseMs)com.netflix.discovery.shared.ApplicationgetApplication(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.com.netflix.discovery.shared.ApplicationgetApplication(java.lang.String appName, boolean includeRemoteRegion)Get application information.com.netflix.discovery.shared.ApplicationsgetApplicationDeltas()Deprecated.usegetApplicationDeltasFromMultipleRegions(String[])instead.com.netflix.discovery.shared.ApplicationsgetApplicationDeltasFromMultipleRegions(java.lang.String[] remoteRegions)Gets the application delta also including instances from the passed remote regions, with the instances from the local region.com.netflix.discovery.shared.ApplicationsgetApplications()Get all applications in this instance registry, falling back to other regions if allowed in the Eureka config.com.netflix.discovery.shared.ApplicationsgetApplications(boolean includeRemoteRegion)Deprecated.UsegetApplicationsFromMultipleRegions(String[])instead.com.netflix.discovery.shared.ApplicationsgetApplicationsFromAllRemoteRegions()Returns applications including instances from all remote regions.com.netflix.discovery.shared.ApplicationsgetApplicationsFromLocalRegionOnly()Returns applications including instances from local region only.com.netflix.discovery.shared.ApplicationsgetApplicationsFromMultipleRegions(java.lang.String[] remoteRegions)This method will return applications with instances from all passed remote regions as well as the current region.com.netflix.appinfo.InstanceInfogetInstanceByAppAndId(java.lang.String appName, java.lang.String id)Gets theInstanceInfoinformation.com.netflix.appinfo.InstanceInfogetInstanceByAppAndId(java.lang.String appName, java.lang.String id, boolean includeRemoteRegions)Gets theInstanceInfoinformation.protected abstract InstanceStatusOverrideRulegetInstanceInfoOverrideRule()java.util.List<com.netflix.appinfo.InstanceInfo>getInstancesById(java.lang.String id)Deprecated.TrygetInstanceByAppAndId(String, String)instead.java.util.List<com.netflix.appinfo.InstanceInfo>getInstancesById(java.lang.String id, boolean includeRemoteRegions)Deprecated.TrygetInstanceByAppAndId(String, String, boolean)instead.java.util.List<com.netflix.discovery.shared.Pair<java.lang.Long,java.lang.String>>getLastNCanceledInstances()Get the N instances that have most recently canceled.java.util.List<com.netflix.discovery.shared.Pair<java.lang.Long,java.lang.String>>getLastNRegisteredInstances()Get the N instances that are most recently registered.longgetLocalRegistrySize()longgetNumberofElementsininstanceCache()longgetNumOfRenewsInLastMin()Servo route; do not call.intgetNumOfRenewsPerMinThreshold()Gets the threshold for the renewals per minute.protected com.netflix.appinfo.InstanceInfo.InstanceStatusgetOverriddenInstanceStatus(com.netflix.appinfo.InstanceInfo r, Lease<com.netflix.appinfo.InstanceInfo> existingLease, boolean isReplication)ResponseCachegetResponseCache()voidinitializedResponseCache()protected voidinitRemoteRegionRegistry()protected booleaninternalCancel(java.lang.String appName, java.lang.String id, boolean isReplication)cancel(String, String, boolean)method is overridden byPeerAwareInstanceRegistry, so each cancel request is replicated to the peers.java.util.Map<java.lang.String,com.netflix.appinfo.InstanceInfo.InstanceStatus>overriddenInstanceStatusesSnapshot()protected voidpostInit()voidregister(com.netflix.appinfo.InstanceInfo registrant, int leaseDuration, boolean isReplication)Registers a new instance with a given duration.booleanrenew(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.voidshutdown()Perform all cleanup and shutdown operations.booleanstatusUpdate(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.voidstoreOverriddenStatusIfRequired(java.lang.String id, com.netflix.appinfo.InstanceInfo.InstanceStatus overriddenStatus)Deprecated.this is expensive, try not to use.voidstoreOverriddenStatusIfRequired(java.lang.String appName, java.lang.String id, com.netflix.appinfo.InstanceInfo.InstanceStatus overriddenStatus)Stores overridden status if it is not already there.protected voidupdateRenewsPerMinThreshold()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.netflix.eureka.registry.InstanceRegistry
getSortedApplications, isBelowRenewThresold, isLeaseExpirationEnabled, isSelfPreservationModeEnabled, openForTraffic
-
-
-
-
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
-
serverConfig
protected final EurekaServerConfig serverConfig
-
clientConfig
protected final com.netflix.discovery.EurekaClientConfig clientConfig
-
serverCodecs
protected final ServerCodecs serverCodecs
-
responseCache
protected volatile ResponseCache responseCache
-
-
Constructor Detail
-
AbstractInstanceRegistry
protected AbstractInstanceRegistry(EurekaServerConfig serverConfig, com.netflix.discovery.EurekaClientConfig clientConfig, ServerCodecs serverCodecs, EurekaServerHttpClientFactory eurekaServerHttpClientFactory)
Create a new, empty instance registry.
-
-
Method Detail
-
initializedResponseCache
public void initializedResponseCache()
- Specified by:
initializedResponseCachein interfaceInstanceRegistry
-
initRemoteRegionRegistry
protected void initRemoteRegionRegistry() throws java.net.MalformedURLException- Throws:
java.net.MalformedURLException
-
getResponseCache
public ResponseCache getResponseCache()
- Specified by:
getResponseCachein interfaceInstanceRegistry
-
getLocalRegistrySize
public long getLocalRegistrySize()
-
clearRegistry
public void clearRegistry()
Completely clear the registry.- Specified by:
clearRegistryin interfaceInstanceRegistry
-
overriddenInstanceStatusesSnapshot
public java.util.Map<java.lang.String,com.netflix.appinfo.InstanceInfo.InstanceStatus> overriddenInstanceStatusesSnapshot()
- Specified by:
overriddenInstanceStatusesSnapshotin interfaceInstanceRegistry
-
register
public void register(com.netflix.appinfo.InstanceInfo registrant, int leaseDuration, boolean isReplication)Registers a new instance with a given duration.- Specified by:
registerin interfaceLeaseManager<com.netflix.appinfo.InstanceInfo>- Parameters:
registrant- - T to registerisReplication- - 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:
cancelin interfaceLeaseManager<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
AbstractInstanceRegistrysuccessfully, false otherwise.
-
internalCancel
protected boolean internalCancel(java.lang.String appName, java.lang.String id, boolean isReplication)cancel(String, String, boolean)method is overridden byPeerAwareInstanceRegistry, 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:
renewin interfaceLeaseManager<com.netflix.appinfo.InstanceInfo>id- - unique id within appNameisReplication- - 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 usestoreOverriddenStatusIfRequired(String, String, InstanceStatus)instead. Stores overridden status if it is not already there. This happens during a reconciliation process during renewal requests.- Specified by:
storeOverriddenStatusIfRequiredin interfaceInstanceRegistry- 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:
storeOverriddenStatusIfRequiredin interfaceInstanceRegistry- 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 betweenInstanceInfo.InstanceStatus.OUT_OF_SERVICEandInstanceInfo.InstanceStatus.UPto put the instance in and out of traffic.- Specified by:
statusUpdatein interfaceInstanceRegistry- Parameters:
appName- the application name of the instance.id- the unique identifier of the instance.newStatus- the newInstanceInfo.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:
deleteStatusOverridein interfaceInstanceRegistry- Parameters:
appName- the application name of the instance.id- the unique identifier of the instance.newStatus- the newInstanceInfo.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:
evictin interfaceLeaseManager<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:
getApplicationin interfacecom.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:
getApplicationin interfaceInstanceRegistry- Parameters:
appName- The name of the applicationincludeRemoteRegion- true, if we need to include applications from remote regions as indicated by the regionURLby this propertyEurekaServerConfig.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:
getApplicationsin interfacecom.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 callinggetApplicationsFromMultipleRegions(String[])with anullargument.
-
getApplicationsFromLocalRegionOnly
public com.netflix.discovery.shared.Applications getApplicationsFromLocalRegionOnly()
Returns applications including instances from local region only.
Same as callinggetApplicationsFromMultipleRegions(String[])with an empty array.- Specified by:
getApplicationsFromLocalRegionOnlyin interfaceInstanceRegistry
-
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 byEurekaServerConfig.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 passingnullto the methodEurekaServerConfig.getRemoteRegionAppWhitelist(String)
If you are not selectively requesting for a remote region, usegetApplicationsFromAllRemoteRegions()orgetApplicationsFromLocalRegionOnly()- Parameters:
remoteRegions- The remote regions for which the instances are to be queried. The instances may be limited by a whitelist as explained above. Ifnullor 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.UsegetApplicationsFromMultipleRegions(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 allApplications.- Parameters:
includeRemoteRegion- true, if we need to include applications from remote regions as indicated by the regionURLby this propertyEurekaServerConfig.getRemoteRegionUrls(), false otherwise- Returns:
- applications
-
getApplicationDeltas
@Deprecated public com.netflix.discovery.shared.Applications getApplicationDeltas()
Deprecated.usegetApplicationDeltasFromMultipleRegions(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 byEurekaServerConfig.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 byEurekaServerConfig.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 passingnullto the methodEurekaServerConfig.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. Ifnullall 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.
nullif 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 theInstanceInfoinformation.- Specified by:
getInstanceByAppAndIdin interfaceInstanceRegistry- 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 theInstanceInfoinformation.- Specified by:
getInstanceByAppAndIdin interfaceInstanceRegistry- 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 regionURLby this propertyEurekaServerConfig.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.TrygetInstanceByAppAndId(String, String)instead. Get all instances by ID, including automatically asking other regions if the ID is unknown.- Specified by:
getInstancesByIdin interfacecom.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.TrygetInstanceByAppAndId(String, String, boolean)instead. Get the list of instances by its unique id.- Parameters:
id- the unique id of the instanceincludeRemoteRegions- true, if we need to include applications from remote regions as indicated by the regionURLby this propertyEurekaServerConfig.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:
getNumOfRenewsInLastMinin interfaceInstanceRegistry- Returns:
- servo data
-
getNumOfRenewsPerMinThreshold
@Monitor(name="numOfRenewsPerMinThreshold", type=GAUGE) public int getNumOfRenewsPerMinThreshold()Gets the threshold for the renewals per minute.- Specified by:
getNumOfRenewsPerMinThresholdin interfaceInstanceRegistry- 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:
getLastNRegisteredInstancesin interfaceInstanceRegistry- 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:
getLastNCanceledInstancesin interfaceInstanceRegistry- Returns:
-
updateRenewsPerMinThreshold
protected void updateRenewsPerMinThreshold()
-
postInit
protected void postInit()
-
shutdown
public void shutdown()
Perform all cleanup and shutdown operations.- Specified by:
shutdownin interfaceInstanceRegistry
-
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)
-
-