本文整理汇总了Java中io.vertx.core.Handler类的典型用法代码示例。如果您正苦于以下问题:Java Handler类的具体用法?Java Handler怎么用?Java Handler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Handler类属于io.vertx.core包,在下文中一共展示了Handler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: modify
import io.vertx.core.Handler; //导入依赖的package包/类
@Override
public FdfsClient modify(ReadStream<Buffer> stream, long size, FdfsFileId fileId, long offset,
Handler<AsyncResult<Void>> handler) {
getTracker().setHandler(tracker -> {
if (tracker.succeeded()) {
tracker.result().getStoreStorage(fileId.group(), storage -> {
if (storage.succeeded()) {
storage.result().modify(stream, size, fileId, offset, modify -> {
handler.handle(modify);
});
} else {
handler.handle(Future.failedFuture(storage.cause()));
}
});
} else {
handler.handle(Future.failedFuture(tracker.cause()));
}
});
return this;
}
示例2: getBooks
import io.vertx.core.Handler; //导入依赖的package包/类
@Override
public BookDatabaseService getBooks(Book book, Handler<AsyncResult<JsonArray>> resultHandler) {
DynamicQuery dynamicQuery = generateDynamicQuery(SQL_FIND_ALL_BOOKS, book);
String preparedQuery = dynamicQuery.getPreparedQuery();
Tuple params = dynamicQuery.getParams();
pgConnectionPool.rxPreparedQuery(preparedQuery, params)
.map(PgResult::getDelegate)
.subscribe(
pgResult -> {
JsonArray jsonArray = transformPgResultToJson(pgResult);
resultHandler.handle(Future.succeededFuture(jsonArray));
},
throwable -> {
LOGGER.error("Failed to get the filtered books by the following conditions"
+ params.toString(), throwable);
resultHandler.handle(Future.failedFuture(throwable));
});
return this;
}
示例3: pageUpdateHandler
import io.vertx.core.Handler; //导入依赖的package包/类
private void pageUpdateHandler(RoutingContext context) {
String title = context.request().getParam("title");
Handler<AsyncResult<Void>> handler = reply -> {
if (reply.succeeded()) {
context.response().setStatusCode(303);
context.response().putHeader("Location", "/wiki/" + title);
context.response().end();
} else {
context.fail(reply.cause());
}
};
String markdown = context.request().getParam("markdown");
if ("yes".equals(context.request().getParam("newPage"))) {
dbService.createPage(title, markdown, handler);
} else {
dbService.savePage(Integer.valueOf(context.request().getParam("id")), markdown, handler);
}
}
示例4: handler
import io.vertx.core.Handler; //导入依赖的package包/类
private Handler<Message<JsonObject>> handler(ServiceHandler serviceHandler) {
return msg -> {
vertx.executeBlocking(ar -> {
try {
ar.complete(serviceHandler.invokeService(msg.body()));
} catch (Exception e) {
ar.fail(e);
}
}, res -> {
if (res.succeeded()) {
msg.reply(res.result());
} else {
int failureCode = 500;
String message = res.cause().getMessage();
msg.fail(failureCode, message);
}
});
};
}
示例5: processMethods
import io.vertx.core.Handler; //导入依赖的package包/类
/**
* 分发请求并处理
* 下面具体的方法如方法名所示,与DAO层方法命名一致,在此不表
*
* @author Leibniz.Hu
*/
@Override
protected <T> void processMethods(Handler<T> replyMsg, JsonArray params, EventBusNamespace method) {
switch (method) {
case COMMAND_INSERT_ORDER:
insertOrder(replyMsg, params);
break;
case COMMAND_GET_ORDER_BY_ALIPAY_ORDER_ID:
getOrderByAlipayOrderId(replyMsg, params);
break;
case COMMAND_GET_ORDER_BY_WECHAT_ORDER_ID:
getOrderByWechatOrderId(replyMsg, params);
break;
case COMMAND_UPDATE_PAID_ORDER:
updateAfterPaid(replyMsg, params);
break;
default:
log.error("未能处理的请求方法:{}", method);
}
}
示例6: fetchAllPages
import io.vertx.core.Handler; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchAllPages(Handler<AsyncResult<JsonArray>> resultHandler) {
dbClient.query(sqlQueries.get(SqlQuery.ALL_PAGES), res -> {
if (res.succeeded()) {
JsonArray pages = new JsonArray(res.result()
.getResults()
.stream()
.map(json -> json.getString(0))
.sorted()
.collect(Collectors.toList()));
resultHandler.handle(Future.succeededFuture(pages));
} else {
LOGGER.error("Database query error", res.cause());
resultHandler.handle(Future.failedFuture(res.cause()));
}
});
return this;
}
示例7: fetchPage
import io.vertx.core.Handler; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchPage(String name, Handler<AsyncResult<JsonObject>> resultHandler) {
dbClient.queryWithParams(sqlQueries.get(SqlQuery.GET_PAGE), new JsonArray().add(name), fetch -> {
if (fetch.succeeded()) {
JsonObject response = new JsonObject();
ResultSet resultSet = fetch.result();
if (resultSet.getNumRows() == 0) {
response.put("found", false);
} else {
response.put("found", true);
JsonArray row = resultSet.getResults().get(0);
response.put("id", row.getInteger(0));
response.put("rawContent", row.getString(1));
}
resultHandler.handle(Future.succeededFuture(response));
} else {
LOGGER.error("Database query error", fetch.cause());
resultHandler.handle(Future.failedFuture(fetch.cause()));
}
});
return this;
}
示例8: connect_success
import io.vertx.core.Handler; //导入依赖的package包/类
@Test
public void connect_success(@Mocked NetSocketImpl netSocket) {
FutureFactoryImpl futureFactory = new FutureFactoryImpl();
new MockUp<NetClientWrapper>(netClientWrapper) {
@Mock
void connect(boolean ssl, int port, String host, Handler<AsyncResult<NetSocket>> connectHandler) {
connectHandler.handle(futureFactory.succeededFuture(netSocket));
}
};
tcpClientConnection.connect();
Assert.assertSame(netSocket, tcpClientConnection.getNetSocket());
Assert.assertEquals(Status.WORKING, Deencapsulation.getField(tcpClientConnection, "status"));
}
示例9: WikiDatabaseServiceImpl
import io.vertx.core.Handler; //导入依赖的package包/类
WikiDatabaseServiceImpl(io.vertx.ext.jdbc.JDBCClient dbClient, HashMap<SqlQuery, String> sqlQueries, Handler<AsyncResult<WikiDatabaseService>> readyHandler) {
this.dbClient = new JDBCClient(dbClient);
this.sqlQueries = sqlQueries;
getConnection()
.flatMap(conn -> conn.rxExecute(sqlQueries.get(SqlQuery.CREATE_PAGES_TABLE)))
.map(v -> this)
.subscribe(RxHelper.toSubscriber(readyHandler));
}
示例10: countAsync
import io.vertx.core.Handler; //导入依赖的package包/类
/**
* Count all records of the underlying table asynchronously.
* @param resultHandler the resultHandler which succeeds when the blocking method of this type succeeds or fails
* with an <code>DataAccessException</code> if the blocking method of this type throws an exception
* @see #count()
*/
default void countAsync(Handler<AsyncResult<Long>> resultHandler){
VertxDAOHelper.countAsync(this, (query,mapper)->{
client().fetchOne(query,mapper, h -> {
if (h.succeeded()) {
resultHandler.handle(Future.succeededFuture((Long) h.result().get()));
} else {
resultHandler.handle(Future.failedFuture(h.cause()));
}
});
return null;
});
}
示例11: ofSucceededVoid
import io.vertx.core.Handler; //导入依赖的package包/类
public static <A, B> Handler<AsyncResult<A>> ofSucceededVoid(Handler<AsyncResult<B>> handler, VoidConsumer alwaysDo, Consumer<A> consumer)
{
return e -> {
if (alwaysDo != null) {
alwaysDo.accept();
}
if (e.failed()) {
handler.handle(failedFuture(e.cause()));
return;
}
consumer.accept(e.result());
};
}
示例12: connect
import io.vertx.core.Handler; //导入依赖的package包/类
@Override
public BinlogClientImpl connect(Handler<AsyncResult<Void>> startHandler) {
if (connected) {
throw new IllegalStateException("Client already connected.");
}
connected = true;
vertx.<Void>executeBlocking((f) -> {
try {
client.connect(connectTimeout);
Runtime.getRuntime().addShutdownHook(shutdownHook);
f.complete();
} catch (Exception e) {
f.fail(e);
}
}, true, (ar) -> {
if (ar.succeeded()) {
if (logger.isDebugEnabled()) {
logger.debug("Binlog listener " +
"[" + host + ":" + port + "]" +
" started ");
}
} else {
connected = false;
if (exceptionHandler != null) {
exceptionHandler.handle(ar.cause());
}
}
startHandler.handle(ar);
});
return this;
}
示例13: compareBodyHandler
import io.vertx.core.Handler; //导入依赖的package包/类
private Handler<HttpClientResponse> compareBodyHandler(String message, TestContext context, Async f) {
return r -> {
context.assertEquals(200, r.statusCode(), "Failed to call consumes test '" + message + "'");
r.exceptionHandler(context::fail).bodyHandler(body -> {
context.assertEquals(message, body.toString());
f.complete();
});
};
}
示例14: request
import io.vertx.core.Handler; //导入依赖的package包/类
private @NotNull HttpClientRequest request(@NotNull Handler<Buffer> handler, @NotNull Async latch) {
return vertx.createHttpClient()
.get(PORT, "localhost", "/metrics")
.handler(response -> {
context.assertEquals(HttpResponseStatus.OK.code(), response.statusCode());
response.bodyHandler(body -> {
handler.handle(body);
latch.complete();
});
});
}
示例15: fetchAllPages
import io.vertx.core.Handler; //导入依赖的package包/类
@Override
// tag::rx-data-flow[]
public WikiDatabaseService fetchAllPages(Handler<AsyncResult<JsonArray>> resultHandler) {
dbClient.rxQuery(sqlQueries.get(SqlQuery.ALL_PAGES))
.flatMapObservable(res -> { // <1>
List<JsonArray> results = res.getResults();
return Observable.from(results); // <2>
})
.map(json -> json.getString(0)) // <3>
.sorted() // <4>
.collect(JsonArray::new, JsonArray::add) // <5>
.subscribe(RxHelper.toSubscriber(resultHandler));
return this;
}