com.netflix.eureka
Class InstanceRegistry

java.lang.Object
  extended by com.netflix.eureka.InstanceRegistry
All Implemented Interfaces:
com.netflix.discovery.shared.LookupService<java.lang.String>, LeaseManager<com.netflix.appinfo.InstanceInfo>
Direct Known Subclasses:
PeerAwareInstanceRegistry

public abstract class InstanceRegistry
extends java.lang.Object
implements LeaseManager<com.netflix.appinfo.InstanceInfo>, com.netflix.discovery.shared.LookupService<java.lang.String>

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
protected  java.lang.String[] allKnownRemoteRegions
           
static java.lang.String[] EMPTY_STR_ARRAY
           
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
           
 
Constructor Summary
protected InstanceRegistry()
           
 
Method Summary
 boolean cancel(java.lang.String appName, java.lang.String id, boolean isReplication)
          Cancels the registration of an instance.
 void evict()
          Evict Ts with expired Lease(s).
 com.netflix.discovery.shared.Application getApplication(java.lang.String appName)
           
 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 explictly 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()
           
 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 explictly 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)
           
 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()
           
 java.util.List<com.netflix.discovery.shared.Pair<java.lang.Long,java.lang.String>> getLastNRegisteredInstances()
           
 long getNumberofElementsininstanceCache()
           
 long getNumOfRenewsInLastMin()
           
protected  void initRemoteRegionRegistry()
           
abstract  boolean isLeaseExpirationEnabled()
           
protected  void postInit()
           
 void register(com.netflix.appinfo.InstanceInfo r, int leaseDuration, boolean isReplication)
          Assign a new Lease to the passed in T
 boolean renew(java.lang.String appName, java.lang.String id, boolean isReplication)
          Renew the Lease associated w/ the passed in appName and id
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.netflix.discovery.shared.LookupService
getNextServerFromEureka
 

Field Detail

EMPTY_STR_ARRAY

public static final java.lang.String[] EMPTY_STR_ARRAY

overriddenInstanceStatusMap

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

regionNameVSRemoteRegistry

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

allKnownRemoteRegions

protected java.lang.String[] allKnownRemoteRegions

lock

protected java.lang.Object lock

numberOfRenewsPerMinThreshold

protected volatile int numberOfRenewsPerMinThreshold

expectedNumberOfRenewsPerMin

protected volatile int expectedNumberOfRenewsPerMin

EUREKA_SERVER_CONFIG

protected static final EurekaServerConfig EUREKA_SERVER_CONFIG
Constructor Detail

InstanceRegistry

protected InstanceRegistry()
Method Detail

register

public void register(com.netflix.appinfo.InstanceInfo r,
                     int leaseDuration,
                     boolean isReplication)
Description copied from interface: LeaseManager
Assign a new Lease to the passed in T

Specified by:
register in interface LeaseManager<com.netflix.appinfo.InstanceInfo>
Parameters:
r - - T to register
isReplication - - whether this is a replicated entry from another eureka node.

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 InstanceRegistry successfully, false otherwise.

renew

public boolean renew(java.lang.String appName,
                     java.lang.String id,
                     boolean isReplication)
Description copied from interface: LeaseManager
Renew the Lease associated w/ the passed in appName and id

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

storeOverriddenStatusIfRequired

public void storeOverriddenStatusIfRequired(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.

Parameters:
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.

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()
Description copied from interface: LeaseManager
Evict Ts with expired Lease(s).

Specified by:
evict in interface LeaseManager<com.netflix.appinfo.InstanceInfo>

getApplication

public com.netflix.discovery.shared.Application getApplication(java.lang.String appName)
Specified by:
getApplication in interface com.netflix.discovery.shared.LookupService<java.lang.String>

getApplication

public com.netflix.discovery.shared.Application getApplication(java.lang.String appName,
                                                               boolean includeRemoteRegion)
Get application information.

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:

getApplications

public com.netflix.discovery.shared.Applications getApplications()
Specified by:
getApplications in interface com.netflix.discovery.shared.LookupService<java.lang.String>

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.


getApplicationsFromLocalRegionOnly

public com.netflix.discovery.shared.Applications getApplicationsFromLocalRegionOnly()
Returns applications including instances from local region only.
Same as calling getApplicationsFromMultipleRegions(String[]) with an empty array.


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 explictly 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:
all 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 explictly 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.

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.

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

public java.util.List<com.netflix.appinfo.InstanceInfo> getInstancesById(java.lang.String id)
Specified by:
getInstancesById in interface com.netflix.discovery.shared.LookupService<java.lang.String>

getInstancesById

public java.util.List<com.netflix.appinfo.InstanceInfo> getInstancesById(java.lang.String id,
                                                                         boolean includeRemoteRegions)
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.

isLeaseExpirationEnabled

public abstract boolean isLeaseExpirationEnabled()

getNumOfRenewsInLastMin

@Monitor(name="numOfRenewsInLastMin",
         description="Number of total heartbeats received in the last minute",
         type=GAUGE)
public long getNumOfRenewsInLastMin()

getLastNRegisteredInstances

public java.util.List<com.netflix.discovery.shared.Pair<java.lang.Long,java.lang.String>> getLastNRegisteredInstances()

getLastNCanceledInstances

public java.util.List<com.netflix.discovery.shared.Pair<java.lang.Long,java.lang.String>> getLastNCanceledInstances()

postInit

protected void postInit()

getNumberofElementsininstanceCache

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

initRemoteRegionRegistry

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