io.vertx.core.impl.ContextInternal Java Examples
The following examples show how to use
io.vertx.core.impl.ContextInternal.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InferenceVerticle.java From konduit-serving with Apache License 2.0 | 6 votes |
protected void saveInspectionDataIfRequired(long pid) { try { File processConfigFile = new File(DirectoryFetcher.getServersDataDir(), pid + ".data"); String inferenceConfigurationJson = ((ContextInternal) context).getDeployment() .deploymentOptions().getConfig().encodePrettily(); if(processConfigFile.exists()) { if(!FileUtils.readFileToString(processConfigFile, StandardCharsets.UTF_8).contains(inferenceConfigurationJson)) { FileUtils.writeStringToFile(processConfigFile, inferenceConfigurationJson, StandardCharsets.UTF_8); } } else { FileUtils.writeStringToFile(processConfigFile, inferenceConfigurationJson, StandardCharsets.UTF_8); log.info("Writing inspection data at '{}' with configuration: \n{}", processConfigFile.getAbsolutePath(), inferenceConfiguration.toJson()); } processConfigFile.deleteOnExit(); } catch (IOException exception) { log.error("Unable to save konduit server inspection information", exception); } }
Example #2
Source File: PoolBase.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Override public Future<SqlConnection> getConnection() { ContextInternal current = vertx.getOrCreateContext(); Object metric; if (metrics != null) { metric = metrics.enqueueRequest(); } else { metric = null; } Promise<Connection> promise = current.promise(); acquire(promise); if (metrics != null) { promise.future().onComplete(ar -> { metrics.dequeueRequest(metric); }); } return promise.future().map(conn -> { SqlConnectionImpl wrapper = wrap(current, conn); conn.init(wrapper); return wrapper; }); }
Example #3
Source File: DB2ConnectionFactory.java From vertx-sql-client with Apache License 2.0 | 6 votes |
public DB2ConnectionFactory(ContextInternal context, DB2ConnectOptions options) { NetClientOptions netClientOptions = new NetClientOptions(options); this.context = context; this.host = options.getHost(); this.port = options.getPort(); this.username = options.getUser(); this.password = options.getPassword(); this.database = options.getDatabase(); this.connectionAttributes = options.getProperties() == null ? null : Collections.unmodifiableMap(options.getProperties()); this.cachePreparedStatements = options.getCachePreparedStatements(); this.preparedStatementCacheSize = options.getPreparedStatementCacheMaxSize(); this.preparedStatementCacheSqlFilter = options.getPreparedStatementCacheSqlFilter(); this.pipeliningLimit = options.getPipeliningLimit(); this.netClient = context.owner().createNetClient(netClientOptions); }
Example #4
Source File: QueryExecutor.java From vertx-sql-client with Apache License 2.0 | 6 votes |
void executeExtendedQuery(CommandScheduler scheduler, String sql, boolean autoCommit, Tuple arguments, Promise<L> promise) { ContextInternal context = (ContextInternal) promise.future().context(); Object payload; if (tracer != null) { payload = tracer.sendRequest(context, sql, arguments); } else { payload = null; } Object metric; if (metrics != null) { metric = metrics.requestBegin(sql, sql); metrics.requestEnd(metric); } else { metric = null; } QueryResultBuilder handler = this.createHandler(promise, payload, metric); ExtendedQueryCommand cmd = createExtendedQueryCommand(sql, autoCommit, arguments, handler); scheduler.schedule(cmd, handler); }
Example #5
Source File: KafkaAdminClientImpl.java From vertx-kafka-client with Apache License 2.0 | 6 votes |
@Override public Future<Void> createTopics(List<NewTopic> topics) { ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext(); Promise<Void> promise = ctx.promise(); CreateTopicsResult createTopicsResult = this.adminClient.createTopics(Helper.toNewTopicList(topics)); createTopicsResult.all().whenComplete((v, ex) -> { if (ex == null) { promise.complete(); } else { promise.fail(ex); } }); return promise.future(); }
Example #6
Source File: KafkaAdminClientImpl.java From vertx-kafka-client with Apache License 2.0 | 6 votes |
@Override public Future<Void> deleteTopics(List<String> topicNames) { ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext(); Promise<Void> promise = ctx.promise(); DeleteTopicsResult deleteTopicsResult = this.adminClient.deleteTopics(topicNames); deleteTopicsResult.all().whenComplete((v, ex) -> { if (ex == null) { promise.complete(); } else { promise.fail(ex); } }); return promise.future(); }
Example #7
Source File: PgConnectionFactory.java From vertx-sql-client with Apache License 2.0 | 6 votes |
PgConnectionFactory(VertxInternal vertx, ContextInternal context, PgConnectOptions options) { NetClientOptions netClientOptions = new NetClientOptions(options); // Make sure ssl=false as we will use STARTLS netClientOptions.setSsl(false); this.context = context; this.sslMode = options.getSslMode(); this.socketAddress = options.getSocketAddress(); this.hostnameVerificationAlgorithm = netClientOptions.getHostnameVerificationAlgorithm(); this.trustOptions = netClientOptions.getTrustOptions(); this.database = options.getDatabase(); this.username = options.getUser(); this.password = options.getPassword(); this.properties = new HashMap<>(options.getProperties()); this.cachePreparedStatements = options.getCachePreparedStatements(); this.pipeliningLimit = options.getPipeliningLimit(); this.preparedStatementCacheSize = options.getPreparedStatementCacheMaxSize(); this.preparedStatementCacheSqlFilter = options.getPreparedStatementCacheSqlFilter(); this.client = vertx.createNetClient(netClientOptions); }
Example #8
Source File: RabbitMQClientImpl.java From vertx-rabbitmq-client with Apache License 2.0 | 6 votes |
private Future<Void> start(ContextInternal ctx, int attempts) { return ctx.<Void>executeBlocking(future -> { try { connect(); future.complete(); } catch (IOException | TimeoutException e) { log.error("Could not connect to rabbitmq", e); future.fail(e); } }).recover(err -> { if (attempts >= retries) { log.info("Max number of connect attempts (" + retries + ") reached. Will not attempt to connect again"); return ctx.failedFuture(err); } else { long delay = config.getConnectionRetryDelay(); log.info("Attempting to reconnect to rabbitmq..."); Promise<Void> promise = ctx.promise(); vertx.setTimer(delay, id -> { log.debug("Reconnect attempt # " + attempts); start(ctx, attempts + 1).onComplete(promise); }); return promise.future(); } }); }
Example #9
Source File: JDBCSQLRowStream.java From vertx-jdbc-client with Apache License 2.0 | 6 votes |
JDBCSQLRowStream(ContextInternal ctx, Statement st, ResultSet rs, int fetchSize) throws SQLException { this.ctx = ctx; this.st = st; this.fetchSize = fetchSize; this.rs = rs; this.pending = new InboundBuffer<JsonArray>(ctx, fetchSize) .drainHandler(v -> readBatch()) .emptyHandler(v -> checkEndHandler()); metaData = rs.getMetaData(); cols = metaData.getColumnCount(); stClosed.set(false); rsClosed.set(false); // the first rs is populated in the constructor more.set(true); }
Example #10
Source File: TestHttpClientPoolFactory.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void createClientPool(@Mocked VertxInternal vertx, @Mocked ContextInternal context, @Mocked HttpClient httpClient) { new Expectations(VertxImpl.class) { { context.owner(); result = vertx; vertx.createHttpClient(httpClientOptions); result = httpClient; } }; HttpClientWithContext pool = factory.createClientPool(context); Assert.assertSame(context, pool.context()); Assert.assertSame(httpClient, pool.getHttpClient()); }
Example #11
Source File: InferenceVerticle.java From konduit-serving with Apache License 2.0 | 6 votes |
private void saveInspectionDataIfRequired(int pid) { try { File processConfigFile = new File(DirectoryFetcher.getServersDataDir(), pid + ".data"); String inferenceConfigurationJson = ((ContextInternal) context).getDeployment() .deploymentOptions().getConfig().encodePrettily(); if(processConfigFile.exists()) { if(!FileUtils.readFileToString(processConfigFile, StandardCharsets.UTF_8).contains(inferenceConfigurationJson)) { FileUtils.writeStringToFile(processConfigFile, inferenceConfigurationJson, StandardCharsets.UTF_8); } } else { FileUtils.writeStringToFile(processConfigFile, inferenceConfigurationJson, StandardCharsets.UTF_8); log.info("Writing inspection data at '{}' with configuration: \n{}", processConfigFile.getAbsolutePath(), inferenceConfiguration.toJson()); } processConfigFile.deleteOnExit(); } catch (IOException exception) { log.error("Unable to save konduit server inspection information", exception); } }
Example #12
Source File: PoolBase.java From vertx-sql-client with Apache License 2.0 | 5 votes |
public PoolBase(ContextInternal context, ConnectionFactory factory, QueryTracer tracer, ClientMetrics metrics, PoolOptions poolOptions) { super(tracer, metrics); this.vertx = context.owner(); this.factory = factory; this.pool = new ConnectionPool(factory, context, poolOptions.getMaxSize(), poolOptions.getMaxWaitQueueSize()); this.closeFuture = new CloseFuture(this); }
Example #13
Source File: MySQLConnectionImpl.java From vertx-sql-client with Apache License 2.0 | 5 votes |
private static void connect(MySQLConnectionFactory client, ContextInternal ctx, QueryTracer tracer, ClientMetrics metrics, Promise<MySQLConnection> promise) { client.connect() .map(conn -> { MySQLConnectionImpl mySQLConnection = new MySQLConnectionImpl(client, ctx, conn, tracer, metrics); conn.init(mySQLConnection); return (MySQLConnection) mySQLConnection; }).onComplete(promise); }
Example #14
Source File: MySQLConnectionImpl.java From vertx-sql-client with Apache License 2.0 | 5 votes |
public static Future<MySQLConnection> connect(Vertx vertx, MySQLConnectOptions options) { ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext(); MySQLConnectionFactory client; try { client = new MySQLConnectionFactory(ctx, options); } catch (Exception e) { return ctx.failedFuture(e); } QueryTracer tracer = ctx.tracer() == null ? null : new QueryTracer(ctx.tracer(), options); Promise<MySQLConnection> promise = ctx.promise(); ctx.dispatch(null, v -> connect(client, ctx, tracer, null, promise)); return promise.future(); }
Example #15
Source File: HazelcastAsyncMap.java From vertx-hazelcast with Apache License 2.0 | 5 votes |
@Override public Future<Void> put(K k, V v) { K kk = convertParam(k); V vv = convertParam(v); ContextInternal context = vertx.getOrCreateContext(); return Future.fromCompletionStage(map.setAsync(kk, HazelcastServerID.convertServerID(vv)), context); }
Example #16
Source File: SubsOpSerializer.java From vertx-infinispan with Apache License 2.0 | 5 votes |
public static SubsOpSerializer get(ContextInternal context) { ConcurrentMap<Object, Object> contextData = context.contextData(); SubsOpSerializer instance = (SubsOpSerializer) contextData.get(SubsOpSerializer.class); if (instance == null) { SubsOpSerializer candidate = new SubsOpSerializer(context); SubsOpSerializer previous = (SubsOpSerializer) contextData.putIfAbsent(SubsOpSerializer.class, candidate); instance = previous == null ? candidate : previous; } return instance; }
Example #17
Source File: KafkaConsumerImpl.java From vertx-kafka-client with Apache License 2.0 | 5 votes |
public synchronized KafkaConsumerImpl<K, V> registerCloseHook() { Context context = Vertx.currentContext(); if (context == null) { return this; } closeHandler.registerCloseHook((ContextInternal) context); return this; }
Example #18
Source File: KafkaAdminClientImpl.java From vertx-kafka-client with Apache License 2.0 | 5 votes |
@Override public Future<Void> deleteConsumerGroupOffsets(String groupId, Set<TopicPartition> partitions) { ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext(); Promise<Void> promise = ctx.promise(); DeleteConsumerGroupOffsetsResult deleteConsumerGroupOffsetsResult = this.adminClient.deleteConsumerGroupOffsets(groupId, Helper.toTopicPartitionSet(partitions)); deleteConsumerGroupOffsetsResult.all().whenComplete((v, ex) -> { if (ex == null) { promise.complete(); } else { promise.fail(ex); } }); return promise.future(); }
Example #19
Source File: KafkaAdminClientImpl.java From vertx-kafka-client with Apache License 2.0 | 5 votes |
@Override public Future<Void> close(long timeout) { ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext(); Promise<Void> promise = ctx.promise(); ctx.executeBlocking(prom -> { if (timeout > 0) { adminClient.close(Duration.ofMillis(timeout)); } else { adminClient.close(); } prom.complete(); }); return promise.future(); }
Example #20
Source File: KafkaWriteStreamImpl.java From vertx-kafka-client with Apache License 2.0 | 5 votes |
@Override public Future<Void> close(long timeout) { ContextInternal ctx = (ContextInternal) context.owner().getOrCreateContext(); Promise<Void> trampolineProm = ctx.promise(); this.context.<Void>executeBlocking(prom -> { if (timeout > 0) { this.producer.close(timeout, TimeUnit.MILLISECONDS); } else { this.producer.close(); } prom.complete(); }).onComplete(trampolineProm); return trampolineProm.future(); // Trampoline on caller context }
Example #21
Source File: FutureBatchLoaderImpl.java From vertx-web with Apache License 2.0 | 5 votes |
@Override public CompletionStage<List<V>> load(List<K> keys, BatchLoaderEnvironment env) { ContextInternal context = (ContextInternal) contextProvider.apply(env); Promise<List<V>> promise; if (context == null) { promise = Promise.promise(); invokeBatchLoader(keys, env, promise); } else { promise = context.promise(); context.runOnContext(v -> invokeBatchLoader(keys, env, promise)); } return promise.future().toCompletionStage(); }
Example #22
Source File: SubsOpSerializer.java From vertx-hazelcast with Apache License 2.0 | 5 votes |
public static SubsOpSerializer get(ContextInternal context) { ConcurrentMap<Object, Object> contextData = context.contextData(); SubsOpSerializer instance = (SubsOpSerializer) contextData.get(SubsOpSerializer.class); if (instance == null) { SubsOpSerializer candidate = new SubsOpSerializer(context.owner()); SubsOpSerializer previous = (SubsOpSerializer) contextData.putIfAbsent(SubsOpSerializer.class, candidate); instance = previous == null ? candidate : previous; } return instance; }
Example #23
Source File: CallbackDataFetcherImpl.java From vertx-web with Apache License 2.0 | 5 votes |
@Override public CompletionStage<T> get(DataFetchingEnvironment env) { ContextInternal context = (ContextInternal) contextProvider.apply(env); Promise<T> promise; if (context == null) { promise = Promise.promise(); invokeDataFetcher(env, promise); } else { promise = context.promise(); context.runOnContext(v -> invokeDataFetcher(env, promise)); } return promise.future().toCompletionStage(); }
Example #24
Source File: SocketConnectionBase.java From vertx-sql-client with Apache License 2.0 | 5 votes |
public SocketConnectionBase(NetSocketInternal socket, boolean cachePreparedStatements, int preparedStatementCacheSize, Predicate<String> preparedStatementCacheSqlFilter, int pipeliningLimit, ContextInternal context) { this.socket = socket; this.context = context; this.pipeliningLimit = pipeliningLimit; this.paused = false; this.psCache = cachePreparedStatements ? new PreparedStatementCache(preparedStatementCacheSize) : null; this.preparedStatementCacheSqlFilter = preparedStatementCacheSqlFilter; }
Example #25
Source File: FutureMappedBatchLoaderImpl.java From vertx-web with Apache License 2.0 | 5 votes |
@Override public CompletionStage<Map<K, V>> load(Set<K> keys, BatchLoaderEnvironment env) { ContextInternal context = (ContextInternal) contextProvider.apply(env); Promise<Map<K, V>> promise; if (context == null) { promise = Promise.promise(); invokeBatchLoader(keys, env, promise); } else { promise = context.promise(); context.runOnContext(v -> invokeBatchLoader(keys, env, promise)); } return promise.future().toCompletionStage(); }
Example #26
Source File: KafkaProducerImpl.java From vertx-kafka-client with Apache License 2.0 | 5 votes |
public KafkaProducerImpl<K, V> registerCloseHook() { Context context = Vertx.currentContext(); if (context == null) { return this; } closeHandler.registerCloseHook((ContextInternal) context); return this; }
Example #27
Source File: ProtonClientImpl.java From vertx-proton with Apache License 2.0 | 5 votes |
private void connectNetClient(NetClient netClient, String host, int port, String username, String password, ConnectCompletionHandler connectHandler, ProtonClientOptions options) { String serverName = options.getSniServerName() != null ? options.getSniServerName() : (options.getVirtualHost() != null ? options.getVirtualHost() : null); netClient.connect(port, host, serverName, res -> { if (res.succeeded()) { String virtualHost = options.getVirtualHost() != null ? options.getVirtualHost() : host; ProtonConnectionImpl conn = new ProtonConnectionImpl(vertx, virtualHost, (ContextInternal) Vertx.currentContext()); conn.disconnectHandler(h -> { LOG.trace("Connection disconnected"); if(!connectHandler.isComplete()) { connectHandler.handle(Future.failedFuture(new VertxException("Disconnected"))); } }); ProtonSaslClientAuthenticatorImpl authenticator = new ProtonSaslClientAuthenticatorImpl(username, password, options.getEnabledSaslMechanisms(), connectHandler); ProtonTransportOptions transportOptions = new ProtonTransportOptions(); transportOptions.setHeartbeat(options.getHeartbeat()); transportOptions.setMaxFrameSize(options.getMaxFrameSize()); conn.bindClient(netClient, res.result(), authenticator, transportOptions); // Need to flush here to get the SASL process going, or it will wait until calls on the connection are processed // later (e.g open()). conn.flush(); } else { connectHandler.handle(Future.failedFuture(res.cause())); } }); }
Example #28
Source File: HazelcastAsyncMap.java From vertx-hazelcast with Apache License 2.0 | 5 votes |
@Override public Future<V> remove(K k) { K kk = convertParam(k); ContextInternal context = vertx.getOrCreateContext(); CompletionStage<V> completionStage = map.removeAsync(kk); return Future.fromCompletionStage(completionStage, context).map(ConversionUtils::convertReturn); }
Example #29
Source File: QueryResultBuilder.java From vertx-sql-client with Apache License 2.0 | 5 votes |
QueryResultBuilder(Function<T, R> factory, QueryTracer tracer, Object tracingPayload, ClientMetrics metrics, Object metric, Promise<L> handler) { this.factory = factory; this.context = (ContextInternal) handler.future().context(); this.tracer = tracer; this.tracingPayload = tracingPayload; this.metrics = metrics; this.metric = metric; this.handler = handler; }
Example #30
Source File: RowStreamImpl.java From vertx-sql-client with Apache License 2.0 | 5 votes |
RowStreamImpl(PreparedStatementImpl ps, ContextInternal context, int fetch, Tuple params) { this.ps = ps; this.context = context; this.fetch = fetch; this.params = params; this.demand = Long.MAX_VALUE; }