本文整理汇总了Java中io.vertx.core.Handler.handle方法的典型用法代码示例。如果您正苦于以下问题:Java Handler.handle方法的具体用法?Java Handler.handle怎么用?Java Handler.handle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.Handler
的用法示例。
在下文中一共展示了Handler.handle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendCommands
import io.vertx.core.Handler; //导入方法依赖的package包/类
void sendCommands(Handler<AsyncResult<Void>> handler)
{
switch (status) {
case Normal:
connecter.tryGetConnection(F.ofSucceededVoid(handler, conn -> {
conn.execute(batches, handler);
batches = null;
}));
break;
case Once:
connecter.tryGetConnection(F.ofSucceededVoid(handler, conn -> {
conn.execute(batches, F.ofSucceeded(handler, () -> {
status = Status.Unusable;
vertx.runOnContext(event -> close(F.noneHandle()));
}, queue -> queue));
batches = null;
}));
break;
case Unusable:
handler.handle(F.failedFuture(new SSDBClosedException()));
break;
}
}
示例2: send_disconnectedToTryLogin
import io.vertx.core.Handler; //导入方法依赖的package包/类
@Test
public void send_disconnectedToTryLogin(@Mocked AbstractTcpClientPackage tcpClientPackage,
@Mocked TcpOutputStream tcpOutputStream) {
long msgId = 1;
new Expectations(tcpClientConnection) {
{
tcpClientPackage.getMsgId();
result = msgId;
}
};
new MockUp<Context>(context) {
@Mock
void runOnContext(Handler<Void> action) {
Deencapsulation.setField(tcpClientConnection, "status", Status.TRY_LOGIN);
action.handle(null);
}
};
tcpClientConnection.send(tcpClientPackage, ar -> {
});
Assert.assertSame(tcpClientPackage, packageQueue.poll());
Assert.assertNull(packageQueue.poll());
Assert.assertEquals(Status.TRY_LOGIN, Deencapsulation.getField(tcpClientConnection, "status"));
}
示例3: sendCommand
import io.vertx.core.Handler; //导入方法依赖的package包/类
void sendCommand(Handler<AsyncResult<Queue<byte[]>>> handler, String key, Object... params)
{
if (batches != null) {
batches.add(new BatchCommand(key, params, handler));
return;
}
switch (status) {
case Normal:
connecter.tryGetConnection(F.ofSucceededVoid(handler, conn -> conn.execute(key, params, handler)));
break;
case Once:
connecter.tryGetConnection(F.ofSucceededVoid(handler, conn -> conn.execute(key, params, F.ofSucceeded(handler, () -> {
status = Status.Unusable;
vertx.runOnContext(event -> close(F.noneHandle()));
}, queue -> queue))));
break;
case Unusable:
handler.handle(F.failedFuture(new SSDBClosedException()));
break;
}
}
示例4: render
import io.vertx.core.Handler; //导入方法依赖的package包/类
@Override
public void render(
RoutingContext context, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
try {
Template template = cache.get(templateFileName);
if (template == null) {
synchronized (this) {
loader.setVertx(context.vertx());
template = handlebars.compile(templateFileName);
cache.put(templateFileName, template);
}
}
Context engineContext = Context.newBuilder(context.data()).resolver(getResolvers()).build();
handler.handle(Future.succeededFuture(Buffer.buffer(template.apply(engineContext))));
} catch (Exception ex) {
handler.handle(Future.failedFuture(ex));
}
}
示例5: findAll
import io.vertx.core.Handler; //导入方法依赖的package包/类
public void findAll(Handler<AsyncResult<JsonArray>> reply) {
if (dependencies != null) {
reply.handle(Future.succeededFuture(dependencies));
} else {
reply.handle(Future.failedFuture("Impossible to retrieve dependencies"));
}
}
示例6: 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"));
}
示例7: close
import io.vertx.core.Handler; //导入方法依赖的package包/类
void close(Handler<AsyncResult<Void>> completionHandler) {
synchronized (vertx) {
if (--refCount == 0) {
Future<Void> f1 = Future.future();
Future<Void> f2 = Future.future();
if (completionHandler != null) {
CompositeFuture.all(f1, f2).<Void>map(f -> null).setHandler(completionHandler);
}
if (emf != null) {
vertx.executeBlocking(future -> {
emf.close();
future.complete();
}, f2.completer());
} else {
f2.complete();
}
try {
if (exec != null) {
exec.shutdown();
}
if (map != null) {
map.remove(name);
if (map.isEmpty()) {
map.close();
}
}
f1.complete();
} catch (Throwable t) {
f1.fail(t);
}
} else {
if (completionHandler != null) {
completionHandler.handle(Future.succeededFuture());
}
}
}
}
示例8: testRegisterSchemaErrorResponse
import io.vertx.core.Handler; //导入方法依赖的package包/类
@Test
public void testRegisterSchemaErrorResponse() {
new MockUp<ServiceRegistryClientImpl>() {
@Mock
Handler<RestResponse> syncHandlerEx(CountDownLatch countDownLatch, Holder<ResponseWrapper> holder) {
return restResponse -> {
HttpClientResponse response = Mockito.mock(HttpClientResponse.class);
Mockito.when(response.statusCode()).thenReturn(400);
Mockito.when(response.statusMessage()).thenReturn("client error");
Buffer bodyBuffer = Buffer.buffer();
bodyBuffer.appendString("too big");
ResponseWrapper responseWrapper = new ResponseWrapper();
responseWrapper.response = response;
responseWrapper.bodyBuffer = bodyBuffer;
holder.value = responseWrapper;
};
}
};
new MockUp<RestUtils>() {
@Mock
void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
responseHandler.handle(null);
}
};
new RegisterSchemaTester() {
void doRun(java.util.List<LoggingEvent> events) {
oClient.registerSchema("msid", "schemaId", "content");
Assert.assertEquals(
"Register schema msid/schemaId failed, statusCode: 400, statusMessage: client error, description: too big.",
events.get(0).getMessage());
}
}.run();
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:37,代码来源:TestServiceRegistryClientImpl.java
示例9: oauthSuccessProcess
import io.vertx.core.Handler; //导入方法依赖的package包/类
/**
* 解析授权前访问的地址,解析所需的json并编码,最后重定向
*
* @param req HTTP请求对象
* @param resp HTTP响应对象
* @param res ALipay接口返回的响应
* @param callback 解析地址后的处理方法
* @author Leibniz.Hu
*/
private void oauthSuccessProcess(HttpServerRequest req, HttpServerResponse resp, AlipayResponse res, Handler<String> callback) {
if (res != null) {
String visitUrl = req.getParam("visitUrl");//getRedirectAddress(request, REMOVE_PARAMS);
if (visitUrl.length() > 0) {
visitUrl = TuringBase64Util.decode(visitUrl).replaceAll("[\\s*\t\n\r]", "");
callback.handle(visitUrl);
resp.setStatusCode(302).putHeader("Location", visitUrl + (visitUrl.contains("?") ? "&rs=" : "?rs=") + TuringBase64Util.encode(getClearJson(res).toString())).end();
} else {
log.error("没有找到授权后回调地址" + req.absoluteURI());
resp.end("未设置授权后回调地址");
}
}
}
示例10: wechatOrder
import io.vertx.core.Handler; //导入方法依赖的package包/类
/**
* 调用微信统一下单接口
*
* @param product 产品名(会显示在微信支付推送的消息里面)
* @param price 价格(单位:分)
* @param openId 购买者的OpenID
* @param orderId 本地订单ID
* @param acc 商城对应企业用户
* @param request HTTP请求对象
* @param forApiProcess 微信统一下单接口返回的数据的处理
* @param forResponse 接口用于响应的Json,可能是 "WECHAT_VERSION_LOW"、"ORDER_FAIL"、成功的返回成功的JSON
* @author Leibniz
*/
public void wechatOrder(String product, int price, String openId, String orderId, JsonObject acc, HttpServerRequest request, Handler<JsonObject> forResponse, Handler<Map<String, String>> forApiProcess) {
if (!testSupportPay(request)) {
forResponse.handle(WECHAT_VERSION_ERROR);
return;
}
//调用统一下单接口
unifyPay(orderId, product, price, request.remoteAddress(), openId, null, wxPayNotifyUrl, acc, payParam -> {
log.info("统一下单数据: " + payParam);
//解析统一下单接口返回的xml数据
Map<String, String> parsePayParam = XmlUtils.xmltoMap(payParam);
//如果下单成功,则进行微信支付的js接口签名验证,并将签名的数据返回;否则返回下单失败
if (parsePayParam == null) {
forResponse.handle(ORDER_ERROR.put("errMsg", "XML_PARSE_ERROR"));
return;
}
if ("SUCCESS".equals(parsePayParam.get("return_code"))) {
//支付下单信息入库/其他处理
forApiProcess.handle(parsePayParam);
//微信支付js接口签名验证
Map<String, Object> jsApiMap = new WechatPay(parsePayParam.get("prepay_id"), acc).getMap();
JsonObject payJsonData = new JsonObject(jsApiMap).put("status", "SUCCESS");
forResponse.handle(payJsonData);
} else {
log.error("统一订单失败:" + payParam);
forResponse.handle(ORDER_ERROR.put("errMsg", parsePayParam.get("return_msg")));
}
});
}
示例11: doWithConfiguration
import io.vertx.core.Handler; //导入方法依赖的package包/类
private void doWithConfiguration(Handler<JsonObject> handler) {
if (config != null) {
handler.handle(config);
} else {
loadConfiguration(CONFIG_FILE_DEFAULT_PATH, vertx, ar -> {
if (ar.succeeded()) {
handler.handle(ar.result());
}
});
}
}
示例12: listen
import io.vertx.core.Handler; //导入方法依赖的package包/类
@Override
public HttpServer listen(int port, String host, Handler<AsyncResult<HttpServer>> listenHandler) {
localPort = port;
localHost = host;
listenHandler.handle(Future.succeededFuture(this));
processRequest();
return this;
}
示例13: sell
import io.vertx.core.Handler; //导入方法依赖的package包/类
@Override
public void sell(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) {
if (amount <= 0) {
resultHandler.handle(Future.failedFuture("Cannot sell " + quote.getString("name") + " - the amount must be " +
"greater than 0"));
return;
}
double price = amount * quote.getDouble("bid");
String name = quote.getString("name");
int current = portfolio.getAmount(name);
// 1) do we have enough stocks
if (current >= amount) {
// Yes, sell it
int newAmount = current - amount;
if (newAmount == 0) {
portfolio.getShares().remove(name);
} else {
portfolio.getShares().put(name, newAmount);
}
portfolio.setCash(portfolio.getCash() + price);
sendActionOnTheEventBus("SELL", amount, quote, newAmount);
resultHandler.handle(Future.succeededFuture(portfolio));
} else {
resultHandler.handle(Future.failedFuture("Cannot sell " + amount + " of " + name + " - " + "not enough stocks " +
"in portfolio"));
}
}
示例14: ofSucceeded
import io.vertx.core.Handler; //导入方法依赖的package包/类
public static <A, B> Handler<AsyncResult<A>> ofSucceeded(Handler<AsyncResult<B>> handler, VoidConsumer alwaysDo, Function<A, B> consumer)
{
return e -> {
if (alwaysDo != null) {
alwaysDo.accept();
}
if (e.failed()) {
handler.handle(failedFuture(e.cause()));
return;
}
B v = consumer.apply(e.result());
handler.handle(v == null ? succeededFuture() : succeededFuture(v));
};
}
示例15: isAuthorised
import io.vertx.core.Handler; //导入方法依赖的package包/类
public User isAuthorised(GateAuthProvider authProvider,String authority, Handler<AsyncResult<Boolean>> resultHandler) {
if (cachedPermissions.contains(authority)) {
resultHandler.handle(Future.succeededFuture(true));
} else {
doIsPermitted(authProvider,authority, res -> {
if (res.succeeded()) {
if (res.result()) {
cachedPermissions.add(authority);
}
}
resultHandler.handle(res);
});
}
return this;
}