Class InstanceInfo


  • @Serializer("com.netflix.discovery.converters.EntityBodyConverter")
    public class InstanceInfo
    extends java.lang.Object
    The class that holds information required for registration with Eureka Server and to be discovered by other components.

    @Auto annotated fields are serialized as is; Other fields are serialized as specified by the @Serializer.

    • Constructor Detail

      • InstanceInfo

        public InstanceInfo​(java.lang.String instanceId,
                            java.lang.String appName,
                            java.lang.String appGroupName,
                            java.lang.String ipAddr,
                            java.lang.String sid,
                            InstanceInfo.PortWrapper port,
                            InstanceInfo.PortWrapper securePort,
                            java.lang.String homePageUrl,
                            java.lang.String statusPageUrl,
                            java.lang.String healthCheckUrl,
                            java.lang.String secureHealthCheckUrl,
                            java.lang.String vipAddress,
                            java.lang.String secureVipAddress,
                            int countryId,
                            DataCenterInfo dataCenterInfo,
                            java.lang.String hostName,
                            InstanceInfo.InstanceStatus status,
                            InstanceInfo.InstanceStatus overriddenStatus,
                            InstanceInfo.InstanceStatus overriddenStatusAlt,
                            LeaseInfo leaseInfo,
                            java.lang.Boolean isCoordinatingDiscoveryServer,
                            java.util.HashMap<java.lang.String,​java.lang.String> metadata,
                            java.lang.Long lastUpdatedTimestamp,
                            java.lang.Long lastDirtyTimestamp,
                            InstanceInfo.ActionType actionType,
                            java.lang.String asgName)
      • InstanceInfo

        public InstanceInfo​(InstanceInfo ii)
        shallow copy constructor.
        Parameters:
        ii - The object to copy
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getInstanceId

        public java.lang.String getInstanceId()
        Returns:
        the raw instanceId. For compatibility, prefer to use getId()
      • getAppName

        public java.lang.String getAppName()
        Return the name of the application registering with discovery.
        Returns:
        the string denoting the application name.
      • getAppGroupName

        public java.lang.String getAppGroupName()
      • getHostName

        public java.lang.String getHostName()
        Return the default network address to connect to this instance. Typically this would be the fully qualified public hostname. However the user can configure the EurekaInstanceConfig to change the default value used to populate this field using the EurekaInstanceConfig.getDefaultAddressResolutionOrder() property. If a use case need more specific hostnames or ips, please use data from getDataCenterInfo(). For legacy reasons, it is difficult to introduce a new address-type field that is agnostic to hostname/ip.
        Returns:
        the default address (by default the public hostname)
      • setSID

        @Deprecated
        public void setSID​(java.lang.String sid)
        Deprecated.
      • getSID

        @Deprecated
        public java.lang.String getSID()
        Deprecated.
      • getId

        public java.lang.String getId()
        Returns the unique id of the instance. (Note) now that id is set at creation time within the instanceProvider, why do the other checks? This is still necessary for backwards compatibility when upgrading in a deployment with multiple client versions (some with the change, some without).
        Returns:
        the unique id.
      • getIPAddr

        public java.lang.String getIPAddr()
        Returns the ip address of the instance.
        Returns:
        - the ip address, in AWS scenario it is a private IP.
      • getPort

        public int getPort()
        Returns the port number that is used for servicing requests.
        Returns:
        - the non-secure port number.
      • getStatus

        public InstanceInfo.InstanceStatus getStatus()
        Returns the status of the instance.
        Returns:
        the status indicating whether the instance can handle requests.
      • getOverriddenStatus

        public InstanceInfo.InstanceStatus getOverriddenStatus()
        Returns the overridden status if any of the instance.
        Returns:
        the status indicating whether an external process has changed the status.
      • getDataCenterInfo

        public DataCenterInfo getDataCenterInfo()
        Returns data center information identifying if it is AWS or not.
        Returns:
        the data center information.
      • getLeaseInfo

        public LeaseInfo getLeaseInfo()
        Returns the lease information regarding when it expires.
        Returns:
        the lease information of this instance.
      • setLeaseInfo

        public void setLeaseInfo​(LeaseInfo info)
        Sets the lease information regarding when it expires.
        Parameters:
        info - the lease information of this instance.
      • getMetadata

        public java.util.Map<java.lang.String,​java.lang.String> getMetadata()
        Returns all application specific metadata set on the instance.
        Returns:
        application specific metadata.
      • getCountryId

        @Deprecated
        public int getCountryId()
        Deprecated.
      • getSecurePort

        public int getSecurePort()
        Returns the secure port that is used for servicing requests.
        Returns:
        the secure port.
      • isPortEnabled

        public boolean isPortEnabled​(InstanceInfo.PortType type)
        Checks whether a port is enabled for traffic or not.
        Parameters:
        type - indicates whether it is secure or non-secure port.
        Returns:
        true if the port is enabled, false otherwise.
      • getLastUpdatedTimestamp

        public long getLastUpdatedTimestamp()
        Returns the time elapsed since epoch since the instance status has been last updated.
        Returns:
        the time elapsed since epoch since the instance has been last updated.
      • setLastUpdatedTimestamp

        public void setLastUpdatedTimestamp()
        Set the update time for this instance when the status was update.
      • getHomePageUrl

        public java.lang.String getHomePageUrl()
        Gets the home page URL set for this instance.
        Returns:
        home page URL
      • getStatusPageUrl

        public java.lang.String getStatusPageUrl()
        Gets the status page URL set for this instance.
        Returns:
        status page URL
      • getHealthCheckUrls

        public java.util.Set<java.lang.String> getHealthCheckUrls()
        Gets the absolute URLs for the health check page for both secure and non-secure protocols. If the port is not enabled then the URL is excluded.
        Returns:
        A Set containing the string representation of health check urls for secure and non secure protocols
      • getHealthCheckUrl

        public java.lang.String getHealthCheckUrl()
      • getSecureHealthCheckUrl

        public java.lang.String getSecureHealthCheckUrl()
      • getVIPAddress

        public java.lang.String getVIPAddress()
        Gets the Virtual Internet Protocol address for this instance. Defaults to hostname if not specified.
        Returns:
        - The Virtual Internet Protocol address
      • getSecureVipAddress

        public java.lang.String getSecureVipAddress()
        Get the Secure Virtual Internet Protocol address for this instance. Defaults to hostname if not specified.
        Returns:
        - The Secure Virtual Internet Protocol address.
      • getLastDirtyTimestamp

        public java.lang.Long getLastDirtyTimestamp()
        Gets the last time stamp when this instance was touched.
        Returns:
        last timestamp when this instance was touched.
      • setLastDirtyTimestamp

        public void setLastDirtyTimestamp​(java.lang.Long lastDirtyTimestamp)
        Set the time indicating that the instance was touched.
        Parameters:
        lastDirtyTimestamp - time when the instance was touched.
      • setStatus

        public InstanceInfo.InstanceStatus setStatus​(InstanceInfo.InstanceStatus expected,
                                                     InstanceInfo.InstanceStatus status)
        Set the status for this instance only when the current status matches the expected status.
        Parameters:
        expected - status for this instance.
        status - status to set for this instance.
        Returns:
        the prev status if a different status from the current was set, null otherwise
      • setStatusWithoutDirty

        public void setStatusWithoutDirty​(InstanceInfo.InstanceStatus status)
        Set the status for this instance without updating the dirty timestamp.
        Parameters:
        status - status for this instance.
      • setOverriddenStatus

        public void setOverriddenStatus​(InstanceInfo.InstanceStatus status)
        Sets the overridden status for this instance.Normally set by an external process to disable instance from taking traffic.
        Parameters:
        status - overridden status for this instance.
      • isDirty

        public boolean isDirty()
        Returns whether any state changed so that EurekaClient can check whether to retransmit info or not on the next heartbeat.
        Returns:
        true if the InstanceInfo is dirty, false otherwise.
      • isDirtyWithTime

        public java.lang.Long isDirtyWithTime()
        Returns:
        the lastDirtyTimestamp if is dirty, null otherwise.
      • setIsDirty

        @Deprecated
        public void setIsDirty​(boolean isDirty)
        Deprecated.
        use setIsDirty() and unsetIsDirty(long) to set and unset

        Sets the dirty flag so that the instance information can be carried to the discovery server on the next heartbeat.

        Parameters:
        isDirty - true if dirty, false otherwise.
      • setIsDirty

        public void setIsDirty()
        Sets the dirty flag so that the instance information can be carried to the discovery server on the next heartbeat.
      • setIsDirtyWithTime

        public long setIsDirtyWithTime()
        Set the dirty flag, and also return the timestamp of the isDirty event
        Returns:
        the timestamp when the isDirty flag is set
      • unsetIsDirty

        public void unsetIsDirty​(long unsetDirtyTimestamp)
        Unset the dirty flag iff the unsetDirtyTimestamp matches the lastDirtyTimestamp. No-op if lastDirtyTimestamp > unsetDirtyTimestamp
        Parameters:
        unsetDirtyTimestamp - the expected lastDirtyTimestamp to unset.
      • setIsCoordinatingDiscoveryServer

        public void setIsCoordinatingDiscoveryServer()
        Sets a flag if this instance is the same as the discovery server that is return the instances. This flag is used by the discovery clients to identity the discovery server which is coordinating/returning the information.
      • isCoordinatingDiscoveryServer

        public java.lang.Boolean isCoordinatingDiscoveryServer()
        Finds if this instance is the coordinating discovery server.
        Returns:
        - true, if this instance is the coordinating discovery server, false otherwise.
      • getActionType

        public InstanceInfo.ActionType getActionType()
        Returns the type of action done on the instance in the server.Primarily used for updating deltas in the EurekaClient instance.
        Returns:
        action type done on the instance.
      • setActionType

        public void setActionType​(InstanceInfo.ActionType actionType)
        Set the action type performed on this instance in the server.
        Parameters:
        actionType - action type done on the instance.
      • getASGName

        public java.lang.String getASGName()
        Get AWS autoscaling group name if any.
        Returns:
        autoscaling group name of this instance.
      • getVersion

        @Deprecated
        public java.lang.String getVersion()
        Deprecated.
        Returns the specification version of this application.
        Returns:
        the string indicating the version of the application.
      • getZone

        public static java.lang.String getZone​(java.lang.String[] availZones,
                                               InstanceInfo myInfo)
        Get the zone that a particular instance is in. Note that for AWS deployments, myInfo should contain AWS dataCenterInfo which should contain the AWS zone of the instance, and availZones is ignored.
        Parameters:
        availZones - the list of available zones for non-AWS deployments
        myInfo - - The InstanceInfo object of the instance.
        Returns:
        - The zone in which the particular instance belongs to.