Skip to content

Commit

Permalink
refactor: registerRequestHandler don't need requestClass.
Browse files Browse the repository at this point in the history
  • Loading branch information
CherishCai committed Jul 19, 2022
1 parent a713758 commit f03fba6
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static OpcRpcClient getOpcRpcClient(Properties properties) {

PayloadClassHelper.register(ClientTestClientRequest.class, ClientTestServerResponse.class);
PayloadClassHelper.register(ServerTestServerRequest.class, ServerTestClientResponse.class);
rpcClient.registerServerRequestHandler(ServerTestServerRequest.class, new ServerTestRequestHandler());
rpcClient.registerServerRequestHandler(new ServerTestRequestHandler());

//noinspection AlibabaAvoidManuallyCreateThread
new Thread(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static OpcRpcServer getOpcRpcServer(Properties properties2) {
final OpcRpcServer rpcServer = OpcRpcFactory.createOpcServer(properties2);

PayloadClassHelper.register(ClientTestClientRequest.class, ClientTestServerResponse.class);
rpcServer.registerClientRequestHandler(ClientTestClientRequest.class, new ClientTestRequestHandler());
rpcServer.registerClientRequestHandler(new ClientTestRequestHandler());
PayloadClassHelper.register(ServerTestServerRequest.class, ServerTestClientResponse.class);

return rpcServer;
Expand Down
4 changes: 1 addition & 3 deletions rpc-api/src/main/java/io/opc/rpc/api/OpcRpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ public interface OpcRpcClient extends AutoCloseable {
/**
* register a ServerRequestHandler who handle ServerRequest.
*
* @param requestClass requestClass
* @param requestHandler RequestHandler
*/
void registerServerRequestHandler(Class<? extends ServerRequest> requestClass,
RequestHandler<? extends ServerRequest, ? extends ClientResponse> requestHandler);
void registerServerRequestHandler(RequestHandler<? extends ServerRequest, ? extends ClientResponse> requestHandler);

/**
* async send Request. async listening a Response with RequestCallback.
Expand Down
4 changes: 1 addition & 3 deletions rpc-api/src/main/java/io/opc/rpc/api/OpcRpcServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ public interface OpcRpcServer extends AutoCloseable {
/**
* register a ClientRequestHandler who handle ClientRequest.
*
* @param requestClass requestClass
* @param requestHandler RequestHandler
*/
void registerClientRequestHandler(Class<? extends ClientRequest> requestClass,
RequestHandler<? extends ClientRequest, ? extends ServerResponse> requestHandler);
void registerClientRequestHandler(RequestHandler<? extends ClientRequest, ? extends ServerResponse> requestHandler);

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import io.opc.rpc.core.handle.BaseRequestHandler;
import io.opc.rpc.core.handle.ClientDetectionRequestHandler;
import io.opc.rpc.core.handle.RequestHandlerSupport;
import io.opc.rpc.core.request.ClientDetectionServerRequest;
import io.opc.rpc.core.request.ConnectionInitClientRequest;
import io.opc.rpc.core.request.ConnectionResetServerRequest;
import io.opc.rpc.core.request.ConnectionSetupClientRequest;
Expand Down Expand Up @@ -159,7 +158,7 @@ public void init(@Nonnull Properties properties) {
}, this.keepActive * 2, 1000L, TimeUnit.MILLISECONDS);

// register ClientDetectionRequestHandler for ClientDetectionServerRequest, tobe a good practice of RequestHandler
this.registerServerRequestHandler(ClientDetectionServerRequest.class, new ClientDetectionRequestHandler());
this.registerServerRequestHandler(new ClientDetectionRequestHandler());

// subclass init
this.doInit(properties);
Expand Down Expand Up @@ -292,8 +291,7 @@ private void shutdownChanel(ManagedChannel channel) {
protected abstract void doInit(Properties properties);

@Override
public void registerServerRequestHandler(Class<? extends ServerRequest> requestClass,
RequestHandler<? extends ServerRequest, ? extends ClientResponse> requestHandler) {
public void registerServerRequestHandler(RequestHandler<? extends ServerRequest, ? extends ClientResponse> requestHandler) {

//noinspection StatementWithEmptyBody
if (requestHandler instanceof BaseRequestHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ protected void notifyAllConnectionResetServer() {
}

@Override
public void registerClientRequestHandler(Class<? extends ClientRequest> requestClass,
RequestHandler<? extends ClientRequest, ? extends ServerResponse> requestHandler) {
public void registerClientRequestHandler(RequestHandler<? extends ClientRequest, ? extends ServerResponse> requestHandler) {
//noinspection StatementWithEmptyBody
if (requestHandler instanceof BaseRequestHandler) {
// noop, because already be registered on construct
Expand Down

0 comments on commit f03fba6

Please sign in to comment.