use of com.yanghui.elephant.remoting.exception.RemotingSendRequestException in project elephant by yanghuijava.
the class NettyRemotingAbstract method invokeSyncImpl.
public RemotingCommand invokeSyncImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException {
final int unique = request.getUnique();
try {
final SocketAddress addr = channel.remoteAddress();
final ResponseFuture responseFuture = new ResponseFuture(unique, timeoutMillis);
this.responseTable.put(unique, responseFuture);
channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
responseFuture.setSendRequestOK(true);
return;
}
responseFuture.setSendRequestOK(false);
responseTable.remove(unique);
responseFuture.setCause(future.cause());
responseFuture.putResponse(null);
log.warn("send a request command to channel <" + addr + "> failed.");
}
});
RemotingCommand respose = responseFuture.waitRespose(timeoutMillis);
if (null == respose) {
if (responseFuture.isSendRequestOK()) {
throw new RemotingTimeoutException(RemotingHelper.parseSocketAddressAddr(addr), timeoutMillis, responseFuture.getCause());
} else {
throw new RemotingSendRequestException(RemotingHelper.parseSocketAddressAddr(addr), responseFuture.getCause());
}
}
return respose;
} finally {
this.responseTable.remove(unique);
}
}
Aggregations