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 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.List<RemoteRegionRegistry> remoteRegionRegistryList
           
 
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()
          Get the registry information about the delta changes.
 com.netflix.discovery.shared.Applications getApplications()
           
 com.netflix.discovery.shared.Applications getApplications(boolean includeRemoteRegion)
          Get the registry information about all Applications.
 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

overriddenInstanceStatusMap

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

remoteRegionRegistryList

protected java.util.List<RemoteRegionRegistry> remoteRegionRegistryList

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>

getApplications

public com.netflix.discovery.shared.Applications getApplications(boolean includeRemoteRegion)
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

public com.netflix.discovery.shared.Applications getApplicationDeltas()
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.

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.
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 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 instnace
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:
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()