當前位置: 首頁>>代碼示例>>Java>>正文


Java Handler.handle方法代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:DavidQuan,項目名稱:vertx-ssdb,代碼行數:24,代碼來源:CompositeClient.java

示例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"));
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:25,代碼來源:TestTcpClientConnection.java

示例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;
    }
}
 
開發者ID:DavidQuan,項目名稱:vertx-ssdb,代碼行數:23,代碼來源:CompositeClient.java

示例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));
  }
}
 
開發者ID:glytching,項目名稱:dragoman,代碼行數:19,代碼來源:ClasspathAwareHandlebarsTemplateEngine.java

示例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"));
  }
}
 
開發者ID:vert-x3,項目名稱:vertx-starter,代碼行數:8,代碼來源:DependencyService.java

示例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"));
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:16,代碼來源:TestTcpClientConnection.java

示例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());
      }
    }
  }
}
 
開發者ID:pflima92,項目名稱:vertx-jpa,代碼行數:38,代碼來源:EntityManagerProviderImpl.java

示例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("未設置授權後回調地址");
        }
    }
}
 
開發者ID:Leibnizhu,項目名稱:AlipayWechatPlatform,代碼行數:23,代碼來源:AlipayOauthSubRouter.java

示例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")));
        }
    });
}
 
開發者ID:Leibnizhu,項目名稱:AlipayWechatPlatform,代碼行數:45,代碼來源:WechatPayService.java

示例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());
			}
		});
	}
}
 
開發者ID:simonemasoni,項目名稱:vertx_spring,代碼行數:12,代碼來源:VertxSpringApplication.java

示例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;
}
 
開發者ID:noseka1,項目名稱:vertx-aws-lambda,代碼行數:9,代碼來源:LambdaServer.java

示例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"));
    }

}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:30,代碼來源:PortfolioServiceImpl.java

示例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));
    };
}
 
開發者ID:DavidQuan,項目名稱:vertx-ssdb,代碼行數:15,代碼來源:F.java

示例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;
}
 
開發者ID:troopson,項目名稱:etagate,代碼行數:16,代碼來源:GateUser.java


注:本文中的io.vertx.core.Handler.handle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。