本文整理匯總了Java中io.vertx.core.Vertx.currentContext方法的典型用法代碼示例。如果您正苦於以下問題:Java Vertx.currentContext方法的具體用法?Java Vertx.currentContext怎麽用?Java Vertx.currentContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.vertx.core.Vertx
的用法示例。
在下文中一共展示了Vertx.currentContext方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findByContext
import io.vertx.core.Vertx; //導入方法依賴的package包/類
protected CLIENT_POOL findByContext() {
Context currentContext = Vertx.currentContext();
if (currentContext != null
&& currentContext.owner() == vertx
&& currentContext.isEventLoopContext()) {
// standard reactive mode
CLIENT_POOL clientPool = currentContext.get(id);
if (clientPool != null) {
return clientPool;
}
// this will make "client.thread-count" bigger than which in microservice.yaml
// maybe it's better to remove "client.thread-count", just use "rest/highway.thread-count"
return createClientPool();
}
// not in correct context:
// 1.normal thread
// 2.vertx worker thread
// 3.other vertx thread
// select a existing context
return nextPool();
}
示例2: schedule
import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Override
protected void schedule(CommandBase<?> cmd) {
Context current = Vertx.currentContext();
if (current == context) {
pool.acquire(new CommandWaiter() {
@Override
protected void onSuccess(Connection conn) {
// Work around stack over flow
context.runOnContext(v -> {
conn.schedule(cmd);
conn.close(this);
});
}
@Override
protected void onFailure(Throwable cause) {
cmd.fail(cause);
}
});
} else {
context.runOnContext(v -> schedule(cmd));
}
}
示例3: createClientPool
import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Override
public CLIENT_POOL createClientPool() {
Context context = Vertx.currentContext();
Vertx vertx = context.owner();
NetClientWrapper netClientWrapper = new NetClientWrapper(vertx, normalClientConfig, sslClientConfig);
return doCreateClientPool(context, netClientWrapper);
}
示例4: TcpRequest
import io.vertx.core.Vertx; //導入方法依賴的package包/類
public TcpRequest(long msTimeout, TcpResponseCallback responseCallback) {
callContext = Vertx.currentContext();
threadId = Thread.currentThread().getId();
this.begin = System.currentTimeMillis();
this.msTimeout = msTimeout;
this.responseCallback = responseCallback;
}
示例5: createClientPool
import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Override
public HttpClientWithContext createClientPool() {
Context context = Vertx.currentContext();
HttpClient httpClient = context.owner().createHttpClient(httpClientOptions);
return new HttpClientWithContext(httpClient, context);
}
示例6: currentVertx
import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static Vertx currentVertx() {
Context context = Vertx.currentContext();
if (context == null) {
throw new RuntimeException("get currentVertx error, currentContext is null.");
}
return context.owner();
}
示例7: runInContext
import io.vertx.core.Vertx; //導入方法依賴的package包/類
public static <T> void runInContext(Context context, AsyncResultCallback<T> callback, T result, Throwable e) {
if (context == Vertx.currentContext()) {
complete(callback, result, e);
} else {
context.runOnContext(v -> complete(callback, result, e));
}
}
示例8: PgPoolImpl
import io.vertx.core.Vertx; //導入方法依賴的package包/類
public PgPoolImpl(Vertx vertx, boolean closeVertx, PgPoolOptions options) {
int maxSize = options.getMaxSize();
if (maxSize < 1) {
throw new IllegalArgumentException("Pool max size must be > 0");
}
this.context = vertx.getOrCreateContext();
this.factory = new PgConnectionFactory(context, Vertx.currentContext() != null, options);
this.pool = new ConnectionPool(factory::connect, maxSize);
this.closeVertx = closeVertx;
}
示例9: getConnection
import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Override
public void getConnection(Handler<AsyncResult<PgConnection>> handler) {
Context current = Vertx.currentContext();
if (current == context) {
pool.acquire(new ConnectionWaiter(handler));
} else {
context.runOnContext(v -> getConnection(handler));
}
}
示例10: verticleDeployed
import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Override
public void verticleDeployed(Verticle verticle) {
Context context = Vertx.currentContext();
dispatch("verticleDeployed", listener -> listener.verticleDeployed(verticle, context));
}
示例11: verticleUndeployed
import io.vertx.core.Vertx; //導入方法依賴的package包/類
@Override
public void verticleUndeployed(Verticle verticle) {
Context context = Vertx.currentContext();
dispatch("verticleUndeployed", listener -> listener.verticleUndeployed(verticle, context));
}
示例12: setupCloseHook
import io.vertx.core.Vertx; //導入方法依賴的package包/類
private void setupCloseHook() {
Context ctx = Vertx.currentContext();
if (ctx != null && ctx.owner() == vertx) {
ctx.addCloseHook(holder::close);
}
}