From 0509b334ae5f1be1726d15d7d3ec5e81d0e3d1d1 Mon Sep 17 00:00:00 2001 From: tanghanzheng Date: Fri, 14 Jul 2023 15:21:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/server/ConnectionServer.java | 44 +----------- .../core/server/ConnectionServerImpl.java | 4 +- .../core/server/ConnectionServerManager.java | 71 ++++++++++++++++++- .../ConnectionServerManagerFactory.java | 5 ++ .../server/SimpleConnectionServerManager.java | 4 +- .../SimpleConnectionServerManagerFactory.java | 5 ++ 6 files changed, 87 insertions(+), 46 deletions(-) diff --git a/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServer.java b/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServer.java index 289dfa0f7..345f5cfae 100644 --- a/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServer.java +++ b/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServer.java @@ -4,9 +4,9 @@ import java.util.Map; /** - * 连接服务 + * 连接服务。 *

- * 表示服务实例信息 + * A server can be connect. */ public interface ConnectionServer { @@ -17,59 +17,19 @@ static String url(ConnectionServer server) { return server.getHost() + ":" + server.getPort(); } - /** - * 获得服务实例 id - * - * @return 服务实例 id - */ String getInstanceId(); - /** - * 获得服务 id - * - * @return 服务 id - */ String getServiceId(); - /** - * 获得 host - * - * @return host - */ String getHost(); - /** - * 获得 port - * - * @return port - */ int getPort(); - /** - * 获得元数据 - * - * @return 元数据 - */ Map getMetadata(); - /** - * 获得 {@link URI} - * - * @return {@link URI} - */ URI getUri(); - /** - * 获得 Scheme - * - * @return Scheme - */ String getScheme(); - /** - * 是否安全的 - * - * @return 是否安全的 - */ boolean isSecure(); } diff --git a/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServerImpl.java b/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServerImpl.java index ad37eb30d..43de341b0 100644 --- a/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServerImpl.java +++ b/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServerImpl.java @@ -6,7 +6,9 @@ import java.util.Map; /** - * {@link ConnectionServer} 的默认实现 + * {@link ConnectionServer} 的默认实现。 + *

+ * Default impl of {@link ConnectionServer}. */ @Data public class ConnectionServerImpl implements ConnectionServer { diff --git a/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServerManager.java b/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServerManager.java index 971279c14..a9fd5c57b 100644 --- a/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServerManager.java +++ b/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServerManager.java @@ -7,54 +7,121 @@ import java.util.List; /** - * {@link ConnectionServer} 提供者 + * 连接服务管理器。 + *

+ * Management of connectable server. */ public interface ConnectionServerManager { + /** + * 添加服务。 + *

+ * Add a server. + */ default void add(ConnectionServer server, ConnectionLoadBalanceConcept concept) { throw new UnsupportedOperationException(); } + /** + * 添加服务。 + *

+ * Add a server. + */ default void add(ConnectionServer server) { add(server, null); } + /** + * 移除服务。 + *

+ * Remove a server. + */ default void remove(ConnectionServer server, ConnectionLoadBalanceConcept concept) { throw new UnsupportedOperationException(); } + /** + * 移除服务。 + *

+ * Remove a server. + */ default void remove(ConnectionServer server) { remove(server, null); } + /** + * 清空服务。 + *

+ * Clear servers. + */ default void clear(ConnectionLoadBalanceConcept concept) { throw new UnsupportedOperationException(); } + /** + * 清空服务。 + *

+ * Clear servers. + */ default void clear() { clear(null); } + /** + * 比较两个服务是否相等。 + *

+ * Compare whether two services are equal. + */ default boolean isEqual(ConnectionServer server1, ConnectionServer server2, ConnectionLoadBalanceConcept concept) { return server1.getHost().equals(server2.getHost()) && server1.getPort() == server2.getPort(); } + /** + * 比较两个服务是否相等。 + *

+ * Compare whether two services are equal. + */ default boolean isEqual(ConnectionServer server1, ConnectionServer server2) { return isEqual(server1, server2, null); } + /** + * 获得本地服务。 + *

+ * Get local server. + */ ConnectionServer getLocal(ConnectionLoadBalanceConcept concept); + /** + * 获得本地服务。 + *

+ * Get local server. + */ default ConnectionServer getLocal() { return getLocal(null); } + /** + * 获得需要连接的服务。 + *

+ * Get servers need connect. + */ List getConnectionServers(ConnectionLoadBalanceConcept concept); + /** + * 获得需要连接的服务。 + *

+ * Get servers need connect. + */ default List getConnectionServers() { return getConnectionServers(null); } + /** + * 连接服务管理器代理。 + *

+ * Delegate of server manager. + */ @Getter @RequiredArgsConstructor class Delegate implements ConnectionServerManager { @@ -64,7 +131,7 @@ class Delegate implements ConnectionServerManager { private final ConnectionServerManager delegate; public static ConnectionServerManager delegate(ConnectionLoadBalanceConcept concept, - ConnectionServerManager delegate) { + ConnectionServerManager delegate) { return new Delegate(concept, delegate); } diff --git a/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServerManagerFactory.java b/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServerManagerFactory.java index d9bd30cf8..097b84bb5 100644 --- a/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServerManagerFactory.java +++ b/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/ConnectionServerManagerFactory.java @@ -2,6 +2,11 @@ import com.github.linyuzai.connection.loadbalance.core.scope.ScopedFactory; +/** + * 连接管理器工厂。 + *

+ * Factory of server manager. + */ public interface ConnectionServerManagerFactory extends ScopedFactory { } diff --git a/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/SimpleConnectionServerManager.java b/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/SimpleConnectionServerManager.java index 8a180c426..a7246069c 100644 --- a/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/SimpleConnectionServerManager.java +++ b/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/SimpleConnectionServerManager.java @@ -7,7 +7,9 @@ import java.util.concurrent.CopyOnWriteArrayList; /** - * {@link ConnectionServer} 提供者默认实现 + * 连接服务管理器简单实现。 + *

+ * Simple impl of server manager. */ public class SimpleConnectionServerManager implements ConnectionServerManager { diff --git a/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/SimpleConnectionServerManagerFactory.java b/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/SimpleConnectionServerManagerFactory.java index 1deb6c412..2dfb34a76 100644 --- a/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/SimpleConnectionServerManagerFactory.java +++ b/concept-connection-loadbalance/concept-connection-loadbalance-core/src/main/java/com/github/linyuzai/connection/loadbalance/core/server/SimpleConnectionServerManagerFactory.java @@ -1,5 +1,10 @@ package com.github.linyuzai.connection.loadbalance.core.server; +/** + * {@link SimpleConnectionServerManager} 工厂。 + *

+ * Factory of {@link SimpleConnectionServerManager}. + */ public class SimpleConnectionServerManagerFactory implements ConnectionServerManagerFactory { @Override