Package com.netflix.discovery.shared
Class Applications
- java.lang.Object
-
- com.netflix.discovery.shared.Applications
-
@Serializer("com.netflix.discovery.converters.EntityBodyConverter") public class Applications extends java.lang.Object
The class that wraps all the registry information returned by eureka server.Note that the registry information is fetched from eureka server as specified in
EurekaClientConfig.getRegistryFetchIntervalSeconds(). Once the information is fetched it is shuffled and also filtered for instances withInstanceInfo.InstanceStatus.UPstatus as specified by the configurationEurekaClientConfig.shouldFilterOnlyUpInstances().
-
-
Constructor Summary
Constructors Constructor Description Applications()Create a new, empty Eureka application list.Applications(java.lang.String appsHashCode, java.lang.Long versionDelta, java.util.List<Application> registeredApplications)Note that appsHashCode and versionDelta key names are formatted in a custom/configurable way.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddApplication(Application app)Add the application to the list.java.lang.StringgetAppsHashCode()Used by the eureka server.java.util.List<InstanceInfo>getInstancesBySecureVirtualHostName(java.lang.String secureVirtualHostName)Gets the list of secure instances associated to a virtual host name.java.util.List<InstanceInfo>getInstancesByVirtualHostName(java.lang.String virtualHostName)Gets the list of instances associated to a virtual host name.java.util.concurrent.atomic.AtomicLonggetNextIndex(java.lang.String virtualHostname, boolean secure)Gets the next round-robin index for the given virtual host name.java.lang.StringgetReconcileHashCode()Gets the hash code for this applications instance.static java.lang.StringgetReconcileHashCode(java.util.Map<java.lang.String,java.util.concurrent.atomic.AtomicInteger> instanceCountMap)Gets the reconciliation hashcode.java.util.List<Application>getRegisteredApplications()Gets the list of all registered applications from eureka.ApplicationgetRegisteredApplications(java.lang.String appName)Gets the registered application for the given application name.java.lang.LonggetVersion()Deprecated.voidpopulateInstanceCountMap(java.util.Map<java.lang.String,java.util.concurrent.atomic.AtomicInteger> instanceCountMap)Populates the provided instance count map.voidremoveApplication(Application app)Remove the application from the list.voidsetAppsHashCode(java.lang.String hashCode)Used by the eureka server.voidsetVersion(java.lang.Long version)Deprecated.voidshuffleAndIndexInstances(java.util.Map<java.lang.String,Applications> remoteRegionsRegistry, EurekaClientConfig clientConfig, InstanceRegionChecker instanceRegionChecker)Shuffles a whole region so that the instances will not always be returned in the same order.voidshuffleInstances(boolean filterUpInstances)Shuffles the provided instances so that they will not always be returned in the same order.intsize()
-
-
-
Constructor Detail
-
Applications
public Applications()
Create a new, empty Eureka application list.
-
Applications
public Applications(java.lang.String appsHashCode, java.lang.Long versionDelta, java.util.List<Application> registeredApplications)Note that appsHashCode and versionDelta key names are formatted in a custom/configurable way.
-
-
Method Detail
-
addApplication
public void addApplication(Application app)
Add the application to the list.- Parameters:
app- the application to be added.
-
getRegisteredApplications
public java.util.List<Application> getRegisteredApplications()
Gets the list of all registered applications from eureka.- Returns:
- list containing all applications registered with eureka.
-
getRegisteredApplications
public Application getRegisteredApplications(java.lang.String appName)
Gets the registered application for the given application name.- Parameters:
appName- the application name for which the result need to be fetched.- Returns:
- the registered application for the given application name.
-
getInstancesByVirtualHostName
public java.util.List<InstanceInfo> getInstancesByVirtualHostName(java.lang.String virtualHostName)
Gets the list of instances associated to a virtual host name.- Parameters:
virtualHostName- the virtual hostname for which the instances need to be returned.- Returns:
- list of instances.
-
getInstancesBySecureVirtualHostName
public java.util.List<InstanceInfo> getInstancesBySecureVirtualHostName(java.lang.String secureVirtualHostName)
Gets the list of secure instances associated to a virtual host name.- Parameters:
secureVirtualHostName- the virtual hostname for which the secure instances need to be returned.- Returns:
- list of instances.
-
size
public int size()
- Returns:
- a weakly consistent size of the number of instances in all the applications
-
setVersion
@Deprecated public void setVersion(java.lang.Long version)
Deprecated.
-
getVersion
@Deprecated public java.lang.Long getVersion()
Deprecated.
-
setAppsHashCode
public void setAppsHashCode(java.lang.String hashCode)
Used by the eureka server. Not for external use.- Parameters:
hashCode- the hash code to assign for this app collection
-
getAppsHashCode
public java.lang.String getAppsHashCode()
Used by the eureka server. Not for external use.- Returns:
- the string indicating the hashcode based on the applications stored.
-
getReconcileHashCode
public java.lang.String getReconcileHashCode()
Gets the hash code for this applications instance. Used for comparison of instances between eureka server and eureka client.- Returns:
- the internal hash code representation indicating the information about the instances.
-
populateInstanceCountMap
public void populateInstanceCountMap(java.util.Map<java.lang.String,java.util.concurrent.atomic.AtomicInteger> instanceCountMap)
Populates the provided instance count map. The instance count map is used as part of the general app list synchronization mechanism.- Parameters:
instanceCountMap- the map to populate
-
getReconcileHashCode
public static java.lang.String getReconcileHashCode(java.util.Map<java.lang.String,java.util.concurrent.atomic.AtomicInteger> instanceCountMap)
Gets the reconciliation hashcode. The hashcode is used to determine whether the applications list has changed since the last time it was acquired.- Parameters:
instanceCountMap- the instance count map to use for generating the hash- Returns:
- the hash code for this instance
-
shuffleInstances
public void shuffleInstances(boolean filterUpInstances)
Shuffles the provided instances so that they will not always be returned in the same order.- Parameters:
filterUpInstances- whether to return only UP instances
-
shuffleAndIndexInstances
public void shuffleAndIndexInstances(java.util.Map<java.lang.String,Applications> remoteRegionsRegistry, EurekaClientConfig clientConfig, InstanceRegionChecker instanceRegionChecker)
Shuffles a whole region so that the instances will not always be returned in the same order.- Parameters:
remoteRegionsRegistry- the map of remote region names to their registriesclientConfig- theEurekaClientConfig, whose settings will be used to determine whether to filter to only UP instancesinstanceRegionChecker- the instance region checker
-
getNextIndex
public java.util.concurrent.atomic.AtomicLong getNextIndex(java.lang.String virtualHostname, boolean secure)Gets the next round-robin index for the given virtual host name. This index is reset after every registry fetch cycle.- Parameters:
virtualHostname- the virtual host name.secure- indicates whether it is a secure request or a non-secure request.- Returns:
- AtomicLong value representing the next round-robin index.
-
removeApplication
public void removeApplication(Application app)
Remove the application from the list.- Parameters:
app- the application
-
-