diff --git a/core/src/main/java/org/apache/seata/core/rpc/RemotingServer.java b/core/src/main/java/org/apache/seata/core/rpc/RemotingServer.java index c3141603a07..f38e301b852 100644 --- a/core/src/main/java/org/apache/seata/core/rpc/RemotingServer.java +++ b/core/src/main/java/org/apache/seata/core/rpc/RemotingServer.java @@ -21,6 +21,7 @@ import org.apache.seata.core.rpc.processor.RemotingProcessor; import org.apache.seata.core.protocol.MessageType; +import java.io.IOException; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeoutException; @@ -41,7 +42,7 @@ public interface RemotingServer { * @return client result message * @throws TimeoutException TimeoutException */ - Object sendSyncRequest(String resourceId, String clientId, Object msg, boolean tryOtherApp) throws TimeoutException; + Object sendSyncRequest(String resourceId, String clientId, Object msg, boolean tryOtherApp) throws TimeoutException, IOException; /** * server send sync request. @@ -51,7 +52,7 @@ public interface RemotingServer { * @return client result message * @throws TimeoutException TimeoutException */ - Object sendSyncRequest(Channel channel, Object msg) throws TimeoutException; + Object sendSyncRequest(Channel channel, Object msg) throws TimeoutException, IOException; /** * server send async request. @@ -59,7 +60,7 @@ public interface RemotingServer { * @param channel client channel * @param msg transaction message {@code org.apache.seata.core.protocol} */ - void sendAsyncRequest(Channel channel, Object msg); + void sendAsyncRequest(Channel channel, Object msg) throws IOException; /** * server send async response. diff --git a/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java b/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java index 67df2ea8494..fc6a7f21dd3 100644 --- a/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java +++ b/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java @@ -16,6 +16,7 @@ */ package org.apache.seata.core.rpc.netty; +import java.io.IOException; import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeoutException; @@ -68,28 +69,28 @@ public AbstractNettyRemotingServer(ThreadPoolExecutor messageExecutor, NettyServ @Override public Object sendSyncRequest(String resourceId, String clientId, Object msg, boolean tryOtherApp) - throws TimeoutException { + throws TimeoutException, IOException { Channel channel = ChannelManager.getChannel(resourceId, clientId, tryOtherApp); if (channel == null) { - throw new RuntimeException("rm client is not connected. dbkey:" + resourceId + ",clientId:" + clientId); + throw new IOException("rm client is not connected. dbkey:" + resourceId + ",clientId:" + clientId); } RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC); return super.sendSync(channel, rpcMessage, NettyServerConfig.getRpcRequestTimeout()); } @Override - public Object sendSyncRequest(Channel channel, Object msg) throws TimeoutException { + public Object sendSyncRequest(Channel channel, Object msg) throws TimeoutException, IOException { if (channel == null) { - throw new RuntimeException("client is not connected"); + throw new IOException("client is not connected"); } RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC); return super.sendSync(channel, rpcMessage, NettyServerConfig.getRpcRequestTimeout()); } @Override - public void sendAsyncRequest(Channel channel, Object msg) { + public void sendAsyncRequest(Channel channel, Object msg) throws IOException { if (channel == null) { - throw new RuntimeException("client is not connected"); + throw new IOException("client is not connected"); } RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY); super.sendAsync(channel, rpcMessage); diff --git a/mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java b/mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java index 8a347246f33..be48ab4c63b 100644 --- a/mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java +++ b/mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java @@ -16,6 +16,7 @@ */ package org.apache.seata.mockserver.call; +import java.io.IOException; import java.util.concurrent.TimeoutException; import io.netty.channel.Channel; @@ -49,7 +50,7 @@ public static BranchStatus branchCommit(RemotingServer remotingServer, MockBranc BranchCommitResponse response = (BranchCommitResponse)remotingServer.sendSyncRequest( branchSession.getResourceId(), branchSession.getClientId(), request, false); return response.getBranchStatus(); - } catch (TimeoutException e) { + } catch (TimeoutException | IOException e) { throw new RuntimeException(e); } } @@ -68,7 +69,7 @@ public static BranchStatus branchRollback(RemotingServer remotingServer, MockBra BranchRollbackResponse response = (BranchRollbackResponse)remotingServer.sendSyncRequest( branchSession.getResourceId(), branchSession.getClientId(), request, false); return response.getBranchStatus(); - } catch (TimeoutException e) { + } catch (TimeoutException | IOException e) { throw new RuntimeException(e); } }