+ * This is not a strict and stateless Connection interface, it contains the necessary
+ * operations that should be done in the connection. It is more like integrating the
+ * connection and the connection channel together, so creating {@link ClientConnection} is
+ * very resource intensive, for which caching is recommended
*
* @since 2.0.0
*/
-public interface ClientConnection extends Connection {
+public interface ClientConnection extends Closeable {
/**
* Establish a connection and process
*
* @param request Request information
*/
- Response connect(Request request);
+
* Represents a network request connection and provides IO layer support
* This is not a strict and stateless Connection interface, it contains the necessary
* operations that should be done in the connection. It is more like integrating the
- * connection and the connection channel together, so creating {@link Connection} is
+ * connection and the connection channel together, so creating {@link ServerConnection} is
* very resource intensive, for which caching is recommended
*
* @since 2.0.0
*/
-public interface Connection extends Closeable {
+public interface ServerConnection extends Closeable {
+
+ /**
+ * Bind ports and process them
+ */
+ void bind(ServerPort port);
/**
* Gets the state of the connection, which is interpreted differently by different programs
- * Client: Active connection indicates that a connection is being maintained with the server.
- * Inactive connection indicates that no connection is being established with the server
* Server: The active connection indicates that the server has been started, is receiving ports,
* and can obtain requests at any time. The inactive connection indicates that the server has been
* shut down and the ports have been released
diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/SimpleClientConnection.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/SimpleClientConnection.java
new file mode 100644
index 00000000..dc7d9e77
--- /dev/null
+++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/SimpleClientConnection.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.hippo4j.rpc.connection;
+
+import cn.hippo4j.rpc.exception.ConnectionException;
+import cn.hippo4j.rpc.exception.TimeOutException;
+import cn.hippo4j.rpc.model.Request;
+import cn.hippo4j.rpc.model.Response;
+import cn.hippo4j.rpc.support.ResultHolder;
+import io.netty.channel.Channel;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.pool.ChannelPoolHandler;
+import lombok.extern.slf4j.Slf4j;
+
+import java.net.InetSocketAddress;
+import java.util.concurrent.locks.LockSupport;
+
+/**
+ * Client implemented using netty
+ *
+ * @since 2.0.0
+ */
+@Slf4j
+public class SimpleClientConnection implements ClientConnection {
+
+ InetSocketAddress address;
+ /**
+ * Obtain the connection timeout period. The default value is 30s
+ */
+ long timeout = 30000L;
+ EventLoopGroup worker = new NioEventLoopGroup();
+ SimpleConnectPool connectionPool;
+ static final String TIME_OUT_MSG = "Timeout waiting for server-side response";
+
+ public SimpleClientConnection(InetSocketAddress address,
+ ChannelPoolHandler handler) {
+ this.address = address;
+ this.connectionPool = ConnectPoolHolder.getPool(address, timeout, worker, handler);
+ }
+
+ @Override
+ public
*
*
- *
- *
- * @param s key
- * @return t element
- */
- public static Class> get(String s) {
- return SERVER_REGISTER.get(s);
- }
-
- /**
- * add the element to Registry Table
- * if the key already exists, failure, and return before the value of the key.
- * if success return the element
- *
- * @param s key
- * @param cls element
- * @return final mapped value
- */
- public static Class> set(String s, Class> cls) {
- return SERVER_REGISTER.putIfAbsent(s, cls);
- }
-
- /**
- * add the element to Registry Table
- * if the key already exists, failure, replace it
- *
- * @param s key
- * @param cls element
- */
- public static Class> put(String s, Class> cls) {
- return SERVER_REGISTER.put(s, cls);
- }
-
- /**
- * clear
- */
- public static void clear() {
- SERVER_REGISTER.clear();
- }
-}
diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/DefaultInstance.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/DefaultInstance.java
deleted file mode 100644
index 0a45d78f..00000000
--- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/DefaultInstance.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package cn.hippo4j.rpc.discovery;
-
-import cn.hippo4j.common.toolkit.ReflectUtil;
-
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-/**
- * You simply create an instance of a class based on its name and specific type.
- * Load through the ServiceLoader first. If the load fails, load directly through the instantiation.
- * If it is an interface, throw an exception. This is not elegant implementation
- *
- * @since 2.0.0
- */
-public class DefaultInstance implements Instance {
-
- @Override
- public Object getInstance(Class> cls) {
- ServiceLoader> load = ServiceLoader.load(cls);
- Iterator> iterator = load.iterator();
- if (iterator.hasNext()) {
- return iterator.next();
- }
- return ReflectUtil.createInstance(cls);
- }
-
- @Override
- public Object getInstance(String name) {
- try {
- Class> cls = Class.forName(name);
- return getInstance(cls);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/exception/HandlerNotFoundException.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/exception/HandlerNotFoundException.java
new file mode 100644
index 00000000..5bc480e8
--- /dev/null
+++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/exception/HandlerNotFoundException.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.hippo4j.rpc.exception;
+
+/**
+ * HandlerNotFoundException occurs when no executable handler can be found
+ *
+ * @since 2.0.0
+ */
+public class HandlerNotFoundException extends RuntimeException {
+
+ private static final long serialVersionUID = 8247610319171014183L;
+
+ public HandlerNotFoundException() {
+ super();
+ }
+
+ public HandlerNotFoundException(String message) {
+ super(message);
+ }
+
+ public HandlerNotFoundException(Throwable e) {
+ super(e.getMessage(), e);
+ }
+
+ public HandlerNotFoundException(String message, Throwable throwable) {
+ super(message, throwable);
+ }
+
+ public HandlerNotFoundException(String message, Throwable throwable, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, throwable, enableSuppression, writableStackTrace);
+ }
+
+}
\ No newline at end of file
diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/Instance.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/exception/OperationException.java
similarity index 53%
rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/Instance.java
rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/exception/OperationException.java
index 8d1c92c3..8512777b 100644
--- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/Instance.java
+++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/exception/OperationException.java
@@ -15,30 +15,35 @@
* limitations under the License.
*/
-package cn.hippo4j.rpc.discovery;
+package cn.hippo4j.rpc.exception;
/**
- * Instance interface to get an instance
+ * a generic operational exception
*
* @since 2.0.0
*/
-public interface Instance {
-
- /**
- * get a instance
- *
- * @param cls Class object
- * @return Information about instances created or found
- */
- Object getInstance(Class> cls);
-
- /**
- * Gets an instance of a class with a recognizable identity,
- * which can be the fully qualified name of class. It can also be a unique name in a container
- *
- * @param name Identifying name
- * @return Information about instances created or found
- */
- Object getInstance(String name);
+public class OperationException extends RuntimeException {
+
+ private static final long serialVersionUID = 8247610319171014183L;
+
+ public OperationException() {
+ super();
+ }
+
+ public OperationException(String message) {
+ super(message);
+ }
+
+ public OperationException(Throwable e) {
+ super(e.getMessage(), e);
+ }
+
+ public OperationException(String message, Throwable throwable) {
+ super(message, throwable);
+ }
+
+ public OperationException(String message, Throwable throwable, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, throwable, enableSuppression, writableStackTrace);
+ }
}
diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/AbstractNettyHandlerManager.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/AbstractHandlerManager.java
similarity index 79%
rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/AbstractNettyHandlerManager.java
rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/AbstractHandlerManager.java
index 85f7289d..1b50900a 100644
--- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/AbstractNettyHandlerManager.java
+++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/AbstractHandlerManager.java
@@ -17,7 +17,6 @@
package cn.hippo4j.rpc.handler;
-import cn.hippo4j.common.toolkit.Assert;
import io.netty.channel.ChannelHandler;
import java.util.Arrays;
@@ -33,7 +32,7 @@ import java.util.stream.Collectors;
*
* @since 2.0.0
*/
-public abstract class AbstractNettyHandlerManager implements HandlerManager
+ * Even if the parameters passed by the user will not be recognized, it will even become an error
+ *
+ * @since 2.0.0
+ */
+@RequiredArgsConstructor
+@ChannelHandler.Sharable
+public class ServerBareTakeHandler
+ * Parse the parameters in the request to execute the corresponding method.
+ * This is a relatively flexible processor at present, but there are still great defects.
+ *
For example:
+ *
+ *
+ *
+ * @since 2.0.0
+ */
+@ChannelHandler.Sharable
+@RequiredArgsConstructor
+public class ServerBiTakeHandler
+ * Parse the parameters in the request to execute the corresponding method.
+ * This is a relatively flexible processor at present, but there are still great defects.
+ *
For example:
+ *
+ *
+ *
+ * @since 2.0.0
+ */
+@ChannelHandler.Sharable
+@RequiredArgsConstructor
+public class ServerTakeHandler
@@ -38,17 +33,11 @@ import java.util.List;
* The composite pattern is adopted, which means that it is itself a server-side implementation, so it is stateless.
*
* @see RPCServer
- * @see NettyServerConnection
- * @see NettyClientSupport
+ * @see ServerConnection
+ * @see ClientSupport
* @since 2.0.0
*/
-public class NettyServerSupport implements Server {
-
- /**
- * The interface that the server side can call,
- * All the methods in the interface are brokered during initialization
- */
- protected List