Search in sources :

Example 16 with RemotingSendRequestException

use of org.apache.rocketmq.remoting.exception.RemotingSendRequestException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class NettyRemotingAbstract method invokeSyncImpl.

// 同步调用实现
public RemotingCommand invokeSyncImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis) throws InterruptedException, RemotingSendRequestException, RemotingTimeoutException {
    final int opaque = request.getOpaque();
    try {
        final ResponseFuture responseFuture = new ResponseFuture(opaque, timeoutMillis, null, null);
        this.responseTable.put(opaque, responseFuture);
        final SocketAddress addr = channel.remoteAddress();
        channel.writeAndFlush(request).addListener(new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture f) throws Exception {
                if (f.isSuccess()) {
                    responseFuture.setSendRequestOK(true);
                    return;
                } else {
                    responseFuture.setSendRequestOK(false);
                }
                responseTable.remove(opaque);
                responseFuture.setCause(f.cause());
                responseFuture.putResponse(null);
                PLOG.warn("send a request command to channel <" + addr + "> failed.");
            }
        });
        RemotingCommand responseCommand = responseFuture.waitResponse(timeoutMillis);
        if (null == responseCommand) {
            if (responseFuture.isSendRequestOK()) {
                throw new RemotingTimeoutException(RemotingHelper.parseSocketAddressAddr(addr), timeoutMillis, responseFuture.getCause());
            } else {
                throw new RemotingSendRequestException(RemotingHelper.parseSocketAddressAddr(addr), responseFuture.getCause());
            }
        }
        return responseCommand;
    } finally {
        this.responseTable.remove(opaque);
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) SocketAddress(java.net.SocketAddress) ChannelFutureListener(io.netty.channel.ChannelFutureListener) RemotingTooMuchRequestException(org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException)

Aggregations

RemotingSendRequestException (org.apache.rocketmq.remoting.exception.RemotingSendRequestException)16 RemotingTimeoutException (org.apache.rocketmq.remoting.exception.RemotingTimeoutException)12 ChannelFuture (io.netty.channel.ChannelFuture)6 ChannelFutureListener (io.netty.channel.ChannelFutureListener)6 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)6 RemotingConnectException (org.apache.rocketmq.remoting.exception.RemotingConnectException)6 RemotingTooMuchRequestException (org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException)6 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)6 SocketAddress (java.net.SocketAddress)4 Map (java.util.Map)4 Set (java.util.Set)4 TreeSet (java.util.TreeSet)4 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)4 ClusterInfo (org.apache.rocketmq.common.protocol.body.ClusterInfo)4 KVTable (org.apache.rocketmq.common.protocol.body.KVTable)4 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)4 SemaphoreReleaseOnlyOnce (org.apache.rocketmq.remoting.common.SemaphoreReleaseOnlyOnce)4 SubCommandException (org.apache.rocketmq.tools.command.SubCommandException)4 Test (org.junit.Test)4 IOException (java.io.IOException)2