List of usage examples for io.vertx.core Context owner
Vertx owner();
From source file:io.reactiverse.pgclient.impl.PgConnectionFactory.java
License:Apache License
public PgConnectionFactory(Context context, boolean registerCloseHook, PgConnectOptions options) { hook = this::close; this.registerCloseHook = registerCloseHook; ctx = context;/*w ww.j a v a2 s . com*/ if (registerCloseHook) { ctx.addCloseHook(hook); } NetClientOptions netClientOptions = new NetClientOptions(options); // Make sure ssl=false as we will use STARTLS netClientOptions.setSsl(false); this.sslMode = options.getSslMode(); this.hostnameVerificationAlgorithm = netClientOptions.getHostnameVerificationAlgorithm(); this.trustOptions = netClientOptions.getTrustOptions(); this.host = options.getHost(); this.port = options.getPort(); this.database = options.getDatabase(); this.username = options.getUser(); this.password = options.getPassword(); this.cachePreparedStatements = options.getCachePreparedStatements(); this.pipeliningLimit = options.getPipeliningLimit(); this.isUsingDomainSocket = options.isUsingDomainSocket(); this.client = context.owner().createNetClient(netClientOptions); }
From source file:io.servicecomb.foundation.vertx.client.tcp.AbstractTcpClientConnectionPool.java
License:Apache License
protected void startCheckTimeout(TcpClientConfig clientConfig, Context context) { context.owner().setPeriodic(clientConfig.getRequestTimeoutMillis(), this::onCheckTimeout); }
From source file:io.servicecomb.foundation.vertx.VertxUtils.java
License:Apache License
public static Vertx currentVertx() { Context context = Vertx.currentContext(); if (context == null) { throw new RuntimeException("get currentVertx error, currentContext is null."); }//w ww .ja v a 2 s . c o m return context.owner(); }
From source file:org.apache.servicecomb.faultinjection.FaultInjectionHandler.java
License:Apache License
@Override public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception { // prepare the key and lookup for request count. String key = invocation.getTransport().getName() + invocation.getMicroserviceQualifiedName(); AtomicLong reqCount = FaultInjectionUtil.getOperMetTotalReq(key); // increment the request count here after checking the delay/abort condition. long reqCountCurrent = reqCount.getAndIncrement(); FaultParam param = new FaultParam(reqCountCurrent); Context currentContext = Vertx.currentContext(); if (currentContext != null && currentContext.isEventLoopContext()) { param.setVertx(currentContext.owner()); }//from ww w . ja v a 2s. c o m FaultExecutor executor = new FaultExecutor(faultInjectionFeatureList, invocation, param); executor.execute(response -> { try { if (response.isFailed()) { asyncResp.complete(response); } else { invocation.next(asyncResp); } } catch (Exception e) { asyncResp.consumerFail(e); } }); }
From source file:org.apache.servicecomb.foundation.vertx.client.ClientPoolManager.java
License:Apache License
protected CLIENT_POOL findByContext(Context targetContext) { Context currentContext = targetContext != null ? targetContext : Vertx.currentContext(); if (currentContext != null && currentContext.owner() == vertx && currentContext.isEventLoopContext()) { // standard reactive mode CLIENT_POOL clientPool = currentContext.get(id); if (clientPool != null) { return clientPool; }/*from www . j a v a2 s . c om*/ // 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(currentContext); } // not in correct context: // 1.normal thread // 2.vertx worker thread // 3.other vertx thread // select a existing context int idx = reactiveNextIndex.getAndIncrement() % pools.size(); if (idx < 0) { idx = -idx; } return pools.get(idx); }
From source file:org.apache.servicecomb.foundation.vertx.client.http.HttpClientPoolFactory.java
License:Apache License
@Override public HttpClientWithContext createClientPool(Context context) { HttpClient httpClient = context.owner().createHttpClient(httpClientOptions); return new HttpClientWithContext(httpClient, context); }
From source file:org.apache.servicecomb.foundation.vertx.client.tcp.AbstractTcpClientConnectionPool.java
License:Apache License
protected void startCheckTimeout(Context context) { context.owner().setPeriodic(TimeUnit.SECONDS.toMillis(1), this::onCheckTimeout); }
From source file:org.apache.servicecomb.foundation.vertx.client.tcp.AbstractTcpClientPoolFactory.java
License:Apache License
@Override public CLIENT_POOL createClientPool(Context context) { Vertx vertx = context.owner(); NetClientWrapper netClientWrapper = new NetClientWrapper(vertx, normalClientConfig, sslClientConfig); return doCreateClientPool(context, netClientWrapper); }
From source file:org.eclipse.hono.client.impl.HonoClientUnitTestHelper.java
License:Open Source License
/** * Creates a mocked vert.x Context which immediately invokes any handler that is passed to its runOnContext method. * * @param vertx The vert.x instance that the mock of the context is created for. * @return The mocked context.//w ww .j a va 2 s . c om */ @SuppressWarnings("unchecked") public static Context mockContext(final Vertx vertx) { final Context context = mock(Context.class); when(context.owner()).thenReturn(vertx); doAnswer(invocation -> { final Handler<Void> handler = invocation.getArgument(0); handler.handle(null); return null; }).when(context).runOnContext(any(Handler.class)); return context; }
From source file:org.jberet.vertx.cluster.VertxPartitionHandlerFactory.java
License:Open Source License
public VertxPartitionHandlerFactory() { final Context context = Vertx.currentContext(); if (context != null) { vertx = context.owner(); if (!vertx.isClustered()) { throw VertxClusterMessages.MESSAGES.vertxNotClustered(vertx); }/* www.ja v a 2 s . c om*/ } else { final CountDownLatch countDownLatch = new CountDownLatch(1); Vertx.clusteredVertx(new VertxOptions(), res -> { if (res.succeeded()) { vertx = res.result(); countDownLatch.countDown(); } else { throw VertxClusterMessages.MESSAGES.failToInitVertxCluster(res.cause()); } }); try { if (!countDownLatch.await(clusterInitTimeout, TimeUnit.MINUTES)) { throw VertxClusterMessages.MESSAGES.failToInitVertxClusterTimeout(clusterInitTimeout, TimeUnit.MINUTES); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } VertxClusterLogger.LOGGER.createdClusteredVertx(vertx); } }