Introduction to Eureka's important objects

Posted by mwaw on Sun, 20 Oct 2019 19:02:40 +0200

Before analyzing the source code of communication between EurekaClient and EurekaServer, we need to be familiar with several entity classes.

InstanceInfo

This class represents the EurekaClient instance, which will be carried by the client when it requests to register with the server. This instance contains some basic information of the current client:

    private volatile String instanceId;

    private volatile String appName;
    @Auto
    private volatile String appGroupName;

    private volatile String ipAddr;

    private static final String SID_DEFAULT = "na";
    @Deprecated
    private volatile String sid = SID_DEFAULT;

    private volatile int port = DEFAULT_PORT;
    private volatile int securePort = DEFAULT_SECURE_PORT;

    @Auto
    private volatile String homePageUrl;
    @Auto
    private volatile String statusPageUrl;
    @Auto
    private volatile String healthCheckUrl;
    @Auto
    private volatile String secureHealthCheckUrl;
    @Auto
    private volatile String vipAddress;
    @Auto
    private volatile String secureVipAddress;
    @XStreamOmitField
    private String statusPageRelativeUrl;
    @XStreamOmitField
    private String statusPageExplicitUrl;
    @XStreamOmitField
    private String healthCheckRelativeUrl;
    @XStreamOmitField
    private String healthCheckSecureExplicitUrl;
    @XStreamOmitField
    private String vipAddressUnresolved;
    @XStreamOmitField
    private String secureVipAddressUnresolved;
    @XStreamOmitField
    private String healthCheckExplicitUrl;
    @Deprecated
    private volatile int countryId = DEFAULT_COUNTRY_ID; // Defaults to US
    private volatile boolean isSecurePortEnabled = false;
    private volatile boolean isUnsecurePortEnabled = true;
    private volatile DataCenterInfo dataCenterInfo;
    private volatile String hostName;
    private volatile InstanceStatus status = InstanceStatus.UP;
    private volatile InstanceStatus overriddenStatus = InstanceStatus.UNKNOWN;
    @XStreamOmitField
    private volatile boolean isInstanceInfoDirty = false;
    private volatile LeaseInfo leaseInfo;
    @Auto
    private volatile Boolean isCoordinatingDiscoveryServer = Boolean.FALSE;
    @XStreamAlias("metadata")
    private volatile Map<String, String> metadata;
    @Auto
    private volatile Long lastUpdatedTimestamp;
    @Auto
    private volatile Long lastDirtyTimestamp;
    @Auto
    private volatile ActionType actionType;
    @Auto
    private volatile String asgName;
    private String version = VERSION_UNKNOWN;
InstanceStatus

This enumeration contains the possible states of the client

        UP, 
        DOWN, 
        STARTING, 
        OUT_OF_SERVICE, 
        UNKNOWN;
Lease

This class is used by the server to save the lease information of the client. The InstanceInfo object is held in the holder.

// Lease expiration time
 public static final int DEFAULT_DURATION_IN_SECS = 90;
//Client instance
private T holder;
//Service offline time
private long evictionTimestamp;
//Registration start time
private long registrationTimestamp;
//Deregistration time
private long serviceUpTimestamp;
// Last updated
private volatile long lastUpdateTimestamp;
//Lease duration
private long duration;
PeerEurekaNode

This object represents the cluster node information

 /**
     * Service address
     */
    private final String serviceUrl;
    /**
     * Eureka-Server To configure
     */
    private final EurekaServerConfig config;
    /**
     * Batch task synchronization maximum delay
     */
    private final long maxProcessingDelayMs;
    /**
     * Application instance registry
     */
    private final PeerAwareInstanceRegistry registry;
    /**
     * Target host
     */
    private final String targetHost;
    /**
     * Cluster EurekaHttpClient
     */
    private final HttpReplicationClient replicationClient;

    /**
     * Batch task distributor
     */
    private final TaskDispatcher<String, ReplicationTask> batchingDispatcher;
    /**
     * Single task distributor
     */
    private final TaskDispatcher<String, ReplicationTask> nonBatchingDispatcher;
EurekaHttpClient

This is the communication interface between Eureka client and server.

public interface EurekaHttpClient {

    EurekaHttpResponse<Void> register(InstanceInfo info);

    EurekaHttpResponse<Void> cancel(String appName, String id);

    EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info, InstanceStatus overriddenStatus);

    EurekaHttpResponse<Void> statusUpdate(String appName, String id, InstanceStatus newStatus, InstanceInfo info);

    EurekaHttpResponse<Void> deleteStatusOverride(String appName, String id, InstanceInfo info);

    EurekaHttpResponse<Applications> getApplications(String... regions);

    EurekaHttpResponse<Applications> getDelta(String... regions);

    EurekaHttpResponse<Applications> getVip(String vipAddress, String... regions);

    EurekaHttpResponse<Applications> getSecureVip(String secureVipAddress, String... regions);

    EurekaHttpResponse<Application> getApplication(String appName);

    EurekaHttpResponse<InstanceInfo> getInstance(String appName, String id);

    EurekaHttpResponse<InstanceInfo> getInstance(String id);

    void shutdown();
}

This article is based on the platform of blog one article multiple sending OpenWrite Release!

Topics: Java