pf5ub3a78 1 month ago
parent a0446637ef
commit a7f4c78cc4

@ -0,0 +1,83 @@
package com.soa.microservice.core;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
*
*
*/
public class ServiceInstance {
private String instanceId;
private String serviceName;
private String host;
private int port;
private boolean healthy;
private long lastHeartbeat;
private Map<String, String> metadata = new ConcurrentHashMap<>();
public ServiceInstance(String instanceId, String serviceName, String host, int port) {
this.instanceId = instanceId;
this.serviceName = serviceName;
this.host = host;
this.port = port;
this.healthy = true;
this.lastHeartbeat = System.currentTimeMillis();
}
// Getters and setters
public String getInstanceId() {
return instanceId;
}
public String getServiceName() {
return serviceName;
}
public String getHost() {
return host;
}
public int getPort() {
return port;
}
public boolean isHealthy() {
return healthy;
}
public void setHealthy(boolean healthy) {
this.healthy = healthy;
}
public long getLastHeartbeat() {
return lastHeartbeat;
}
public void updateHeartbeat() {
this.lastHeartbeat = System.currentTimeMillis();
}
public Map<String, String> getMetadata() {
return metadata;
}
public void addMetadata(String key, String value) {
this.metadata.put(key, value);
}
public String getMetadata(String key) {
return this.metadata.get(key);
}
@Override
public String toString() {
return "ServiceInstance{" +
"instanceId='" + instanceId + '\'' +
", serviceName='" + serviceName + '\'' +
", host='" + host + '\'' +
", port=" + port +
", healthy=" + healthy +
"}";
}
}
Loading…
Cancel
Save