From a7f4c78cc41a986ce2d8972f0c0214ef41427416 Mon Sep 17 00:00:00 2001 From: pf5ub3a78 <1162620239@qq.com> Date: Sun, 2 Nov 2025 21:25:03 +0800 Subject: [PATCH] SOA --- ServiceInstance.java | 83 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 ServiceInstance.java diff --git a/ServiceInstance.java b/ServiceInstance.java new file mode 100644 index 0000000..8bdca23 --- /dev/null +++ b/ServiceInstance.java @@ -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 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 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 + + "}"; + } +} \ No newline at end of file