Search in sources :

Example 1 with RaftNettyServerReplyProto

use of org.apache.ratis.proto.netty.NettyProtos.RaftNettyServerReplyProto in project incubator-ratis by apache.

the class NettyRpcProxy method send.

public RaftNettyServerReplyProto send(RaftRpcRequestProto request, RaftNettyServerRequestProto proto) throws IOException {
    final CompletableFuture<RaftNettyServerReplyProto> reply = new CompletableFuture<>();
    final ChannelFuture channelFuture = connection.offer(proto, reply);
    try {
        channelFuture.sync();
        TimeDuration newDuration = requestTimeoutDuration.add(request.getTimeoutMs(), TimeUnit.MILLISECONDS);
        return reply.get(newDuration.getDuration(), newDuration.getUnit());
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw IOUtils.toInterruptedIOException(ProtoUtils.toString(request) + " sending from " + peer + " is interrupted.", e);
    } catch (ExecutionException e) {
        throw IOUtils.toIOException(e);
    } catch (TimeoutException e) {
        throw new TimeoutIOException(e.getMessage(), e);
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RaftNettyServerReplyProto(org.apache.ratis.proto.netty.NettyProtos.RaftNettyServerReplyProto) TimeDuration(org.apache.ratis.util.TimeDuration) ExecutionException(java.util.concurrent.ExecutionException) TimeoutIOException(org.apache.ratis.protocol.exceptions.TimeoutIOException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 RaftNettyServerReplyProto (org.apache.ratis.proto.netty.NettyProtos.RaftNettyServerReplyProto)1 TimeoutIOException (org.apache.ratis.protocol.exceptions.TimeoutIOException)1 TimeDuration (org.apache.ratis.util.TimeDuration)1