List of usage examples for io.vertx.core Future succeededFuture
static <T> Future<T> succeededFuture()
From source file:io.github.bckfnn.ftp.FtpClient.java
License:Apache License
public void mkd(String dir, Handler<AsyncResult<Void>> handler) { write("MKD " + dir, resp(handler, when("257", pasv -> { handler.handle(Future.succeededFuture()); })));/*w w w. ja va 2 s . c o m*/ }
From source file:io.github.bckfnn.ftp.FtpClient.java
License:Apache License
public void quit(Handler<AsyncResult<Void>> handler) { write("QUIT", resp(handler, when("200", pasv -> { handler.handle(Future.succeededFuture()); })));/*w w w .ja va2 s. co m*/ }
From source file:io.gravitee.am.gateway.handler.vertx.auth.handler.impl.ClientCredentialsAuthHandlerImpl.java
License:Apache License
@Override public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) { parseAuthorization(context, parseAuthorization -> { if (parseAuthorization.failed()) { handler.handle(Future.failedFuture(parseAuthorization.cause())); return; }/*from w ww . j ava 2s . c om*/ JsonObject clientCredentials = parseAuthorization.result(); authProvider.authenticate(clientCredentials, authHandler -> { if (authHandler.failed()) { handler.handle(Future.failedFuture(authHandler.cause())); return; } context.setUser(authHandler.result()); // continue handler.handle(Future.succeededFuture()); }); }); }
From source file:io.gravitee.am.gateway.handler.vertx.auth.handler.impl.OAuth2ClientAuthHandlerImpl.java
License:Apache License
@Override public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) { parseAuthorization(context, parseAuthorization -> { if (parseAuthorization.failed()) { handler.handle(Future.failedFuture(parseAuthorization.cause())); return; }/*from ww w . j a va 2s . c o m*/ JsonObject credentials = parseAuthorization.result(); authProvider.authenticate(credentials, authHandler -> { if (authHandler.failed()) { handler.handle(Future.failedFuture(authHandler.cause())); return; } context.setUser(authHandler.result()); // continue handler.handle(Future.succeededFuture()); }); }); }
From source file:io.nonobot.core.chat.impl.ChatRouterImpl.java
License:Apache License
private void handle(io.vertx.core.eventbus.Message<JsonObject> message) { JsonObject body = message.body();//from w w w . jav a2 s . c o m boolean respond = body.getBoolean("respond"); String content = body.getString("content"); String replyAddress = body.getString("replyAddress"); String chatId = body.getString("chatId"); for (MessageHandlerImpl handler : messageHandlers) { if (handler.respond == respond) { Matcher matcher = handler.pattern.matcher(content); if (matcher.matches()) { handler.handler.handle(new Message() { boolean replied; @Override public String chatId() { return chatId; } @Override public String body() { return content; } @Override public String matchedGroup(int index) { if (index > 0 && index <= matcher.groupCount()) { return matcher.group(index); } else { return null; } } @Override public void reply(String msg) { reply(msg, null); } @Override public void reply(String msg, Handler<AsyncResult<Void>> ackHandler) { reply(msg, DeliveryOptions.DEFAULT_TIMEOUT, ackHandler); } @Override public void reply(String msg, long ackTimeout, Handler<AsyncResult<Void>> ackHandler) { if (!replied) { replied = true; if (ackHandler != null) { vertx.eventBus().send(replyAddress, msg, new DeliveryOptions().setSendTimeout(ackTimeout), ack -> { if (ack.succeeded()) { ackHandler.handle(Future.succeededFuture()); } else { ackHandler.handle(Future.failedFuture(ack.cause())); } }); } else { vertx.eventBus().send(replyAddress, msg); } } else if (ackHandler != null) { ackHandler.handle(Future.failedFuture("Already replied")); } } }); return; } } } message.reply(null); }
From source file:io.nonobot.core.impl.BotImpl.java
License:Apache License
public static Bot createShared(Vertx vertx, BotOptions options, Handler<AsyncResult<Void>> completionHandler) { BotImpl bot = bots.computeIfAbsent(new Key(vertx, options.getName()), key -> new BotImpl(vertx, options.getName())); HttpServer server;/* w w w . j a v a 2 s . c o m*/ if (options.getHttpServerOptions() != null) { server = vertx.createHttpServer(options.getHttpServerOptions()); server.requestHandler(bot.webRouter::accept); server.listen(ar -> { if (ar.succeeded()) { completionHandler.handle(Future.succeededFuture()); } else { completionHandler.handle(Future.failedFuture(ar.cause())); } }); } else { server = null; completionHandler.handle(Future.succeededFuture()); } return new Bot() { @Override public Vertx vertx() { return bot.vertx(); } @Override public ChatRouter chatRouter() { return bot.chatRouter(); } @Override public Router webRouter() { return bot.webRouter(); } @Override public String name() { return bot.name(); } @Override public void close() { boolean open = bot.closed; bot.close(); if (open && server != null) { server.close(); } } }; }
From source file:io.reactiverse.pgclient.impl.PgConnectionFactory.java
License:Apache License
private void close(Handler<AsyncResult<Void>> completionHandler) { client.close(); completionHandler.handle(Future.succeededFuture()); }
From source file:io.reactiverse.pgclient.impl.PgCursorImpl.java
License:Apache License
@Override public synchronized void close(Handler<AsyncResult<Void>> completionHandler) { if (!closed) { closed = true;/*from ww w . j av a 2 s. c om*/ if (portal == null) { completionHandler.handle(Future.succeededFuture()); } else { String p = portal; portal = null; result = null; ps.closePortal(p, completionHandler); } } }
From source file:io.reactiverse.pgclient.impl.SocketConnection.java
License:Apache License
void upgradeToSSLConnection(Handler<AsyncResult<Void>> completionHandler) { ChannelPipeline pipeline = socket.channelHandlerContext().pipeline(); Future<Void> upgradeFuture = Future.future(); upgradeFuture.setHandler(ar -> {/*from w ww .j a v a2 s.c o m*/ if (ar.succeeded()) { completionHandler.handle(Future.succeededFuture()); } else { Throwable cause = ar.cause(); if (cause instanceof DecoderException) { DecoderException err = (DecoderException) cause; cause = err.getCause(); } completionHandler.handle(Future.failedFuture(cause)); } }); pipeline.addBefore("handler", "initiate-ssl-handler", new InitiateSslHandler(this, upgradeFuture)); }
From source file:io.reactiverse.pgclient.impl.SocketConnection.java
License:Apache License
void sendCancelRequestMessage(int processId, int secretKey, Handler<AsyncResult<Void>> handler) { Buffer buffer = Buffer.buffer(16); buffer.appendInt(16);/*from w w w .j a va 2 s. co m*/ // cancel request code buffer.appendInt(80877102); buffer.appendInt(processId); buffer.appendInt(secretKey); socket.write(buffer, ar -> { if (ar.succeeded()) { // directly close this connection if (status == Status.CONNECTED) { status = Status.CLOSING; socket.close(); } handler.handle(Future.succeededFuture()); } else { handler.handle(Future.failedFuture(ar.cause())); } }); }