public abstract class AbstractInstanceRegistry extends java.lang.Object implements InstanceRegistry
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 com.netflix.discovery.EurekaClientConfig |
clientConfig |
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 |
protected ResponseCache |
responseCache |
protected ServerCodecs |
serverCodecs |
protected EurekaServerConfig |
serverConfig |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractInstanceRegistry(EurekaServerConfig serverConfig,
com.netflix.discovery.EurekaClientConfig clientConfig,
ServerCodecs serverCodecs)
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.
|
void |
evict(long additionalLeaseMs) |
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)
Deprecated.
Try
getInstanceByAppAndId(String, String) instead.
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)
Deprecated.
Try
getInstanceByAppAndId(String, String, boolean) instead.
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 |
getLocalRegistrySize() |
long |
getNumberofElementsininstanceCache() |
long |
getNumOfRenewsInLastMin()
Servo route; do not call.
|
int |
getNumOfRenewsPerMinThreshold()
Gets the threshold for the renewals per minute.
|
protected abstract com.netflix.appinfo.InstanceInfo.InstanceStatus |
getOverriddenInstanceStatus(com.netflix.appinfo.InstanceInfo r,
Lease<com.netflix.appinfo.InstanceInfo> existingLease,
boolean isReplication) |
ResponseCache |
getResponseCache() |
void |
initializedResponseCache() |
protected void |
initRemoteRegionRegistry() |
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. |
java.util.Map<java.lang.String,com.netflix.appinfo.InstanceInfo.InstanceStatus> |
overriddenInstanceStatusesSnapshot() |
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.
|
void |
shutdown()
Perform all cleanup and shutdown operations.
|
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)
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. |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetSortedApplications, isBelowRenewThresold, isLeaseExpirationEnabled, isSelfPreservationModeEnabled, openForTrafficprotected java.util.Map<java.lang.String,RemoteRegionRegistry> regionNameVSRemoteRegistry
protected final java.util.concurrent.ConcurrentMap<java.lang.String,com.netflix.appinfo.InstanceInfo.InstanceStatus> overriddenInstanceStatusMap
protected final java.lang.Object lock
protected java.lang.String[] allKnownRemoteRegions
protected volatile int numberOfRenewsPerMinThreshold
protected volatile int expectedNumberOfRenewsPerMin
protected final EurekaServerConfig serverConfig
protected final com.netflix.discovery.EurekaClientConfig clientConfig
protected final ServerCodecs serverCodecs
protected volatile ResponseCache responseCache
protected AbstractInstanceRegistry(EurekaServerConfig serverConfig, com.netflix.discovery.EurekaClientConfig clientConfig, ServerCodecs serverCodecs)
public void initializedResponseCache()
initializedResponseCache in interface InstanceRegistryprotected void initRemoteRegionRegistry()
throws java.net.MalformedURLException
java.net.MalformedURLExceptionpublic ResponseCache getResponseCache()
getResponseCache in interface InstanceRegistrypublic long getLocalRegistrySize()
public void clearRegistry()
clearRegistry in interface InstanceRegistrypublic java.util.Map<java.lang.String,com.netflix.appinfo.InstanceInfo.InstanceStatus> overriddenInstanceStatusesSnapshot()
overriddenInstanceStatusesSnapshot in interface InstanceRegistrypublic 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.AbstractInstanceRegistry successfully, false otherwise.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.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)@Deprecated
public void storeOverriddenStatusIfRequired(java.lang.String id,
com.netflix.appinfo.InstanceInfo.InstanceStatus overriddenStatus)
#storeOverriddenStatusIfRequired(String, String, InstanceStatus) instead.
Stores overridden status if it is not already there. This happens during
a reconciliation process during renewal requests.storeOverriddenStatusIfRequired in interface InstanceRegistryid - the unique identifier of the instance.overriddenStatus - Overridden status if any.public void storeOverriddenStatusIfRequired(java.lang.String appName,
java.lang.String id,
com.netflix.appinfo.InstanceInfo.InstanceStatus overriddenStatus)
storeOverriddenStatusIfRequired in interface InstanceRegistryappName - the application name of the instance.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.statusUpdate in interface InstanceRegistryappName - 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)
deleteStatusOverride in interface InstanceRegistryappName - 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 void evict(long additionalLeaseMs)
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)
getApplication in interface InstanceRegistryappName - 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.getApplicationsFromLocalRegionOnly in interface InstanceRegistrypublic 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.getInstanceByAppAndId in interface InstanceRegistryappName - 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.getInstanceByAppAndId in interface InstanceRegistryappName - 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@Deprecated public java.util.List<com.netflix.appinfo.InstanceInfo> getInstancesById(java.lang.String id)
getInstanceByAppAndId(String, String) instead.
Get all instances by ID, including automatically asking other regions if the ID is unknown.getInstancesById in interface com.netflix.discovery.shared.LookupService<java.lang.String>LookupService.getInstancesById(String)@Deprecated
public java.util.List<com.netflix.appinfo.InstanceInfo> getInstancesById(java.lang.String id,
boolean includeRemoteRegions)
getInstanceByAppAndId(String, String, boolean) instead.
Get the list of instances by its unique id.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 otherwise@Monitor(name="numOfRenewsInLastMin",
description="Number of total heartbeats received in the last minute",
type=GAUGE)
public long getNumOfRenewsInLastMin()
getNumOfRenewsInLastMin in interface InstanceRegistry@Monitor(name="numOfRenewsPerMinThreshold",
type=GAUGE)
public int getNumOfRenewsPerMinThreshold()
getNumOfRenewsPerMinThreshold in interface InstanceRegistrypublic java.util.List<com.netflix.discovery.shared.Pair<java.lang.Long,java.lang.String>> getLastNRegisteredInstances()
getLastNRegisteredInstances in interface InstanceRegistrypublic java.util.List<com.netflix.discovery.shared.Pair<java.lang.Long,java.lang.String>> getLastNCanceledInstances()
getLastNCanceledInstances in interface InstanceRegistryprotected void postInit()
public void shutdown()
shutdown in interface InstanceRegistry@Monitor(name="numOfElementsinInstanceCache",
description="Number of overrides in the instance Cache",
type=GAUGE)
public long getNumberofElementsininstanceCache()
protected abstract com.netflix.appinfo.InstanceInfo.InstanceStatus getOverriddenInstanceStatus(com.netflix.appinfo.InstanceInfo r,
Lease<com.netflix.appinfo.InstanceInfo> existingLease,
boolean isReplication)