public abstract class InstanceRegistry extends java.lang.Object implements LeaseManager<com.netflix.appinfo.InstanceInfo>, com.netflix.discovery.shared.LookupService<java.lang.String>
Primary operations that are performed are the Registers, Renewals, Cancels, Expirations, and Status Changes. The registry also stores only the delta operations
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String[] |
allKnownRemoteRegions |
protected static EurekaServerConfig |
EUREKA_SERVER_CONFIG |
protected int |
expectedNumberOfRenewsPerMin |
protected java.lang.Object |
lock |
protected int |
numberOfRenewsPerMinThreshold |
protected java.util.concurrent.ConcurrentMap<java.lang.String,com.netflix.appinfo.InstanceInfo.InstanceStatus> |
overriddenInstanceStatusMap |
protected java.util.Map<java.lang.String,RemoteRegionRegistry> |
regionNameVSRemoteRegistry |
| Modifier | Constructor and Description |
|---|---|
protected |
InstanceRegistry()
Create a new, empty instance registry.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
cancel(java.lang.String appName,
java.lang.String id,
boolean isReplication)
Cancels the registration of an instance.
|
void |
clearRegistry()
Completely clear the registry.
|
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.
|
void |
evict()
Evicts everything in the instance registry that has expired, if expiry is enabled.
|
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.
|
com.netflix.discovery.shared.Application |
getApplication(java.lang.String appName,
boolean includeRemoteRegion)
Get application information.
|
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. |
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.
|
com.netflix.discovery.shared.Applications |
getApplications()
Get all applications in this instance registry, falling back to other regions if allowed in the Eureka config.
|
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. |
com.netflix.discovery.shared.Applications |
getApplicationsFromAllRemoteRegions()
Returns applications including instances from all remote regions.
|
com.netflix.discovery.shared.Applications |
getApplicationsFromLocalRegionOnly()
Returns applications including instances from local region only.
|
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.
|
com.netflix.appinfo.InstanceInfo |
getInstanceByAppAndId(java.lang.String appName,
java.lang.String id)
Gets the
InstanceInfo information. |
com.netflix.appinfo.InstanceInfo |
getInstanceByAppAndId(java.lang.String appName,
java.lang.String id,
boolean includeRemoteRegions)
Gets the
InstanceInfo information. |
java.util.List<com.netflix.appinfo.InstanceInfo> |
getInstancesById(java.lang.String id)
Get all instances by ID, including automatically asking other regions if the ID is unknown.
|
java.util.List<com.netflix.appinfo.InstanceInfo> |
getInstancesById(java.lang.String id,
boolean includeRemoteRegions)
Get the list of instances by its unique id.
|
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.
|
long |
getNumberofElementsininstanceCache() |
long |
getNumOfRenewsInLastMin()
Servo route; do not call.
|
protected void |
initRemoteRegionRegistry() |
abstract boolean |
isLeaseExpirationEnabled()
Checks whether lease expiration is enabled.
|
protected void |
postInit() |
void |
register(com.netflix.appinfo.InstanceInfo r,
int leaseDuration,
boolean isReplication)
Registers a new instance with a given duration.
|
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.
|
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.
|
void |
storeOverriddenStatusIfRequired(java.lang.String id,
com.netflix.appinfo.InstanceInfo.InstanceStatus overriddenStatus)
Stores overridden status if it is not already there.
|
protected java.util.concurrent.ConcurrentMap<java.lang.String,com.netflix.appinfo.InstanceInfo.InstanceStatus> overriddenInstanceStatusMap
protected java.util.Map<java.lang.String,RemoteRegionRegistry> regionNameVSRemoteRegistry
protected java.lang.String[] allKnownRemoteRegions
protected final java.lang.Object lock
protected volatile int numberOfRenewsPerMinThreshold
protected volatile int expectedNumberOfRenewsPerMin
protected static final EurekaServerConfig EUREKA_SERVER_CONFIG
protected InstanceRegistry()
public void clearRegistry()
public void register(com.netflix.appinfo.InstanceInfo r,
int leaseDuration,
boolean isReplication)
register in interface LeaseManager<com.netflix.appinfo.InstanceInfo>r - - T to registerisReplication - - whether this is a replicated entry from another eureka node.LeaseManager.register(java.lang.Object,
int, boolean)public boolean cancel(java.lang.String appName,
java.lang.String id,
boolean isReplication)
This is normally invoked by a client when it shuts down informing the server to remove the instance from traffic.
cancel in interface LeaseManager<com.netflix.appinfo.InstanceInfo>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.InstanceRegistry successfully, false otherwise.public boolean renew(java.lang.String appName,
java.lang.String id,
boolean isReplication)
renew in interface LeaseManager<com.netflix.appinfo.InstanceInfo>id - - unique id within appNameisReplication - - whether this is a replicated entry from another ds nodeLeaseManager.renew(java.lang.String,
java.lang.String, boolean)public void storeOverriddenStatusIfRequired(java.lang.String id,
com.netflix.appinfo.InstanceInfo.InstanceStatus overriddenStatus)
id - the unique identifier of the instance.overriddenStatus - Overridden status if any.public boolean statusUpdate(java.lang.String appName,
java.lang.String id,
com.netflix.appinfo.InstanceInfo.InstanceStatus newStatus,
java.lang.String lastDirtyTimestamp,
boolean isReplication)
InstanceInfo.InstanceStatus.OUT_OF_SERVICE and
InstanceInfo.InstanceStatus.UP to put the instance in and out of traffic.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.public boolean deleteStatusOverride(java.lang.String appName,
java.lang.String id,
com.netflix.appinfo.InstanceInfo.InstanceStatus newStatus,
java.lang.String lastDirtyTimestamp,
boolean isReplication)
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.public void evict()
evict in interface LeaseManager<com.netflix.appinfo.InstanceInfo>LeaseManager.evict()public com.netflix.discovery.shared.Application getApplication(java.lang.String appName)
getApplication in interface com.netflix.discovery.shared.LookupService<java.lang.String>appName - - the application name of the applicationLookupService.getApplication(java.lang.String )public com.netflix.discovery.shared.Application getApplication(java.lang.String appName,
boolean includeRemoteRegion)
appName - - The name of the applicationincludeRemoteRegion - - true, if we need to include applications from remote regions
as indicated by the region URL by this property
EurekaServerConfig.getRemoteRegionUrls(), false
otherwisepublic com.netflix.discovery.shared.Applications getApplications()
getApplications in interface com.netflix.discovery.shared.LookupService<java.lang.String>LookupService.getApplications()public com.netflix.discovery.shared.Applications getApplicationsFromAllRemoteRegions()
getApplicationsFromMultipleRegions(String[]) with a null argument.public com.netflix.discovery.shared.Applications getApplicationsFromLocalRegionOnly()
getApplicationsFromMultipleRegions(String[]) with an empty array.public com.netflix.discovery.shared.Applications getApplicationsFromMultipleRegions(java.lang.String[] remoteRegions)
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) getApplicationsFromAllRemoteRegions()
or getApplicationsFromLocalRegionOnly()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.@Deprecated public com.netflix.discovery.shared.Applications getApplications(boolean includeRemoteRegion)
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.Applications.includeRemoteRegion - - true, if we need to include applications from remote regions
as indicated by the region URL by this property
EurekaServerConfig.getRemoteRegionUrls(), false
otherwise@Deprecated public com.netflix.discovery.shared.Applications getApplicationDeltas()
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.EurekaServerConfig.getRetentionTimeInMSInDeltaQueue(). Subsequent
requests for delta information may return the same information and client
must make sure this does not adversely affect them.public com.netflix.discovery.shared.Applications getApplicationDeltasFromMultipleRegions(java.lang.String[] remoteRegions)
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) 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.null if the application does
not exist locally or in remote regions.public com.netflix.appinfo.InstanceInfo getInstanceByAppAndId(java.lang.String appName,
java.lang.String id)
InstanceInfo information.appName - the application name for which the information is requested.id - the unique identifier of the instance.public com.netflix.appinfo.InstanceInfo getInstanceByAppAndId(java.lang.String appName,
java.lang.String id,
boolean includeRemoteRegions)
InstanceInfo information.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
otherwisepublic java.util.List<com.netflix.appinfo.InstanceInfo> getInstancesById(java.lang.String id)
getInstancesById in interface com.netflix.discovery.shared.LookupService<java.lang.String>LookupService.getInstancesById(String)public java.util.List<com.netflix.appinfo.InstanceInfo> getInstancesById(java.lang.String id,
boolean includeRemoteRegions)
id - - the unique id of the instanceincludeRemoteRegions - - true, if we need to include applications from remote regions
as indicated by the region URL by this property
EurekaServerConfig.getRemoteRegionUrls(), false
otherwisepublic abstract boolean isLeaseExpirationEnabled()
@Monitor(name="numOfRenewsInLastMin",
description="Number of total heartbeats received in the last minute",
type=GAUGE)
public long getNumOfRenewsInLastMin()
public java.util.List<com.netflix.discovery.shared.Pair<java.lang.Long,java.lang.String>> getLastNRegisteredInstances()
public java.util.List<com.netflix.discovery.shared.Pair<java.lang.Long,java.lang.String>> getLastNCanceledInstances()
protected void postInit()
@Monitor(name="numOfElementsinInstanceCache",
description="Number of elements in the instance Cache",
type=GAUGE)
public long getNumberofElementsininstanceCache()
protected void initRemoteRegionRegistry()
throws java.net.MalformedURLException
java.net.MalformedURLException