List of usage examples for io.vertx.core.eventbus ReplyFailure NO_HANDLERS
ReplyFailure NO_HANDLERS
To view the source code for io.vertx.core.eventbus ReplyFailure NO_HANDLERS.
Click Source Link
From source file:net.kuujo.copycat.vertx.VertxEventBusProtocolClient.java
License:Apache License
@Override public CompletableFuture<ByteBuffer> write(ByteBuffer request) { final CompletableFuture<ByteBuffer> future = new CompletableFuture<>(); context.runOnContext(v -> {// www. java 2s.co m DeliveryOptions options = new DeliveryOptions().setSendTimeout(5000); byte[] bytes = new byte[request.remaining()]; request.get(bytes); vertx.eventBus().send(address, bytes, options, (Handler<AsyncResult<Message<byte[]>>>) result -> { if (result.succeeded()) { future.complete(ByteBuffer.wrap(result.result().body())); } else { ReplyException exception = (ReplyException) result.cause(); if (exception.failureType() == ReplyFailure.NO_HANDLERS || exception.failureType() == ReplyFailure.TIMEOUT) { future.completeExceptionally(new ProtocolException(exception)); } else { future.completeExceptionally(new CopycatException(exception.getMessage())); } } }); }); return future; }
From source file:net.kuujo.copycat.vertx.VertxEventBusProtocolServer.java
License:Apache License
@Override public void handle(Message<byte[]> message) { if (handler != null) { handler.apply(ByteBuffer.wrap(message.body())).whenComplete((reply, error) -> { context.runOnContext(v -> { if (error != null) { message.fail(0, error.getMessage()); } else { byte[] bytes = new byte[reply.remaining()]; reply.get(bytes);/*from w w w. ja v a 2s . co m*/ message.reply(bytes); } }); }); } else { message.fail(ReplyFailure.NO_HANDLERS.toInt(), "No message handler registered"); } }