@Override public synchronized WorkerExecutorImpl createSharedWorkerExecutor(String name, int poolSize, long maxExecuteTime, TimeUnit maxExecuteTimeUnit) { if (poolSize < 1) { throw new IllegalArgumentException("poolSize must be > 0"); } if (maxExecuteTime < 1) { throw new IllegalArgumentException("maxExecuteTime must be > 0"); } SharedWorkerPool sharedWorkerPool = namedWorkerPools.get(name); if (sharedWorkerPool == null) { ExecutorService workerExec = Executors.newFixedThreadPool(poolSize, new VertxThreadFactory(name + "-", checker, true, maxExecuteTime, maxExecuteTimeUnit)); PoolMetrics workerMetrics = metrics != null ? metrics.createPoolMetrics("worker", name, poolSize) : null; namedWorkerPools.put(name, sharedWorkerPool = new SharedWorkerPool(name, workerExec, workerMetrics)); } else { sharedWorkerPool.refCount++; } ContextImpl context = getOrCreateContext(); WorkerExecutorImpl namedExec = new WorkerExecutorImpl(context, sharedWorkerPool); context.addCloseHook(namedExec); return namedExec; }
private DatagramSocketImpl(VertxInternal vertx, DatagramSocketOptions options) { Transport transport = vertx.transport(); DatagramChannel channel = transport.datagramChannel(options.isIpV6() ? InternetProtocolFamily.IPv6 : InternetProtocolFamily.IPv4); transport.configure(channel, new DatagramSocketOptions(options)); ContextInternal context = vertx.getOrCreateContext(); channel.config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true); MaxMessagesRecvByteBufAllocator bufAllocator = channel.config().getRecvByteBufAllocator(); bufAllocator.maxMessagesPerRead(1); context.nettyEventLoop().register(channel); if (options.getLogActivity()) { channel.pipeline().addLast("logging", new LoggingHandler()); } VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createDatagramSocketMetrics(options) : null; this.channel = channel; this.context = context; this.demand = Long.MAX_VALUE; }
public EventBusImpl(VertxInternal vertx) { VertxMetrics metrics = vertx.metricsSPI(); this.vertx = vertx; this.metrics = metrics != null ? metrics.createEventBusMetrics() : null; }
public NetClientImpl(VertxInternal vertx, NetClientOptions options, boolean useCreatingContext) { this.vertx = vertx; this.options = new NetClientOptions(options); this.sslHelper = new SSLHelper(options, options.getKeyCertOptions(), options.getTrustOptions()); this.closeHook = completionHandler -> { NetClientImpl.this.close(); completionHandler.handle(Future.succeededFuture()); }; if (useCreatingContext) { creatingContext = vertx.getContext(); if (creatingContext != null) { creatingContext.addCloseHook(closeHook); } } else { creatingContext = null; } VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createNetClientMetrics(options) : null; logEnabled = options.getLogActivity(); idleTimeout = options.getIdleTimeout(); idleTimeoutUnit = options.getIdleTimeoutUnit(); }
public HttpClientImpl(VertxInternal vertx, HttpClientOptions options) { this.vertx = vertx; this.metrics = vertx.metricsSPI() != null ? vertx.metricsSPI().createHttpClientMetrics(options) : null; this.options = new HttpClientOptions(options); List<HttpVersion> alpnVersions = options.getAlpnVersions();
metrics.verticleDeployed(verticle);
VertxMetrics metrics = vertx.metricsSPI(); if (metrics != null) { this.metrics = metrics.createNetServerMetrics(options, new SocketAddressImpl(id.port, id.host)); this.actualPort = shared.actualPort(); VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createNetServerMetrics(options, new SocketAddressImpl(id.port, id.host)) : null; actualServer.handlerManager.addHandler(new Handlers(this, handler, exceptionHandler), listenContext);
this.metrics = metrics != null ? metrics.createHttpServerMetrics(options, address) : null; addHandlers(actualServer, listenContext); VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createHttpServerMetrics(options, address) : null;
boolean cancel() { if (cancelled.compareAndSet(false, true)) { if (metrics != null) { metrics.timerEnded(timerID, true); } future.cancel(false); return true; } else { return false; } }
InternalTimerHandler(long timerID, Handler<Long> runnable, boolean periodic, long delay, ContextImpl context) { this.context = context; this.timerID = timerID; this.handler = runnable; this.periodic = periodic; this.cancelled = new AtomicBoolean(); EventLoop el = context.nettyEventLoop(); Runnable toRun = () -> context.runOnContext(this); if (periodic) { future = el.scheduleAtFixedRate(toRun, delay, delay, TimeUnit.MILLISECONDS); } else { future = el.schedule(toRun, delay, TimeUnit.MILLISECONDS); } if (metrics != null) { metrics.timerCreated(timerID); } }
public NetClientImpl(VertxInternal vertx, NetClientOptions options, boolean useCreatingContext) { this.vertx = vertx; this.options = new NetClientOptions(options); this.sslHelper = new SSLHelper(options, options.getKeyCertOptions(), options.getTrustOptions()); this.closeHook = completionHandler -> { NetClientImpl.this.close(); completionHandler.handle(Future.succeededFuture()); }; if (useCreatingContext) { creatingContext = vertx.getContext(); if (creatingContext != null) { if (creatingContext.isMultiThreadedWorkerContext()) { throw new IllegalStateException("Cannot use NetClient in a multi-threaded worker verticle"); } creatingContext.addCloseHook(closeHook); } } else { creatingContext = null; } VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createNetClientMetrics(options) : null; logEnabled = options.getLogActivity(); idleTimeout = options.getIdleTimeout(); idleTimeoutUnit = options.getIdleTimeoutUnit(); }
public HttpClientImpl(VertxInternal vertx, HttpClientOptions options) { this.vertx = vertx; this.metrics = vertx.metricsSPI() != null ? vertx.metricsSPI().createHttpClientMetrics(options) : null; this.options = new HttpClientOptions(options); List<HttpVersion> alpnVersions = options.getAlpnVersions();
metrics.verticleDeployed(verticle);
VertxMetrics metrics = vertx.metricsSPI(); if (metrics != null) { this.metrics = metrics.createNetServerMetrics(options, new SocketAddressImpl(id.port, id.host)); this.actualPort = shared.actualPort(); VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createNetServerMetrics(options, new SocketAddressImpl(id.port, id.host)) : null; actualServer.handlerManager.addHandler(new Handlers(this, handler, exceptionHandler), listenContext);
this.metrics = metrics != null ? metrics.createHttpServerMetrics(options, address) : null; addHandlers(actualServer, listenContext); VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createHttpServerMetrics(options, address) : null;
private void cleanupNonPeriodic() { VertxImpl.this.timeouts.remove(timerID); if (metrics != null) { metrics.timerEnded(timerID, false); } ContextImpl context = getContext(); if (context != null) { context.removeCloseHook(this); } }
PoolMetrics workerPoolMetrics = metrics != null ? metrics.createPoolMetrics("worker", "vert.x-worker-thread", options.getWorkerPoolSize()) : null; ExecutorService internalBlockingExec = Executors.newFixedThreadPool(options.getInternalBlockingPoolSize(), new VertxThreadFactory("vert.x-internal-blocking-", checker, true, options.getMaxWorkerExecuteTime(), options.getMaxWorkerExecuteTimeUnit())); PoolMetrics internalBlockingPoolMetrics = metrics != null ? metrics.createPoolMetrics("worker", "vert.x-internal-blocking", options.getInternalBlockingPoolSize()) : null; internalBlockingPool = new WorkerPool(internalBlockingExec, internalBlockingPoolMetrics); namedWorkerPools = new HashMap<>();
public EventBusImpl(VertxInternal vertx) { VertxMetrics metrics = vertx.metricsSPI(); this.vertx = vertx; this.metrics = metrics != null ? metrics.createEventBusMetrics() : null; }
private DatagramSocketImpl(VertxInternal vertx, DatagramSocketOptions options) { Transport transport = vertx.transport(); DatagramChannel channel = transport.datagramChannel(options.isIpV6() ? InternetProtocolFamily.IPv6 : InternetProtocolFamily.IPv4); transport.configure(channel, new DatagramSocketOptions(options)); ContextInternal context = vertx.getOrCreateContext(); if (context.isMultiThreadedWorkerContext()) { throw new IllegalStateException("Cannot use DatagramSocket in a multi-threaded worker verticle"); } channel.config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true); MaxMessagesRecvByteBufAllocator bufAllocator = channel.config().getRecvByteBufAllocator(); bufAllocator.maxMessagesPerRead(1); context.nettyEventLoop().register(channel); if (options.getLogActivity()) { channel.pipeline().addLast("logging", new LoggingHandler()); } VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createDatagramSocketMetrics(options) : null; this.channel = channel; this.context = context; this.demand = Long.MAX_VALUE; }
@Override public synchronized WorkerExecutorImpl createSharedWorkerExecutor(String name, int poolSize, long maxExecuteTime, TimeUnit maxExecuteTimeUnit) { if (poolSize < 1) { throw new IllegalArgumentException("poolSize must be > 0"); } if (maxExecuteTime < 1) { throw new IllegalArgumentException("maxExecuteTime must be > 0"); } SharedWorkerPool sharedWorkerPool = namedWorkerPools.get(name); if (sharedWorkerPool == null) { ExecutorService workerExec = Executors.newFixedThreadPool(poolSize, new VertxThreadFactory(name + "-", checker, true, maxExecuteTime, maxExecuteTimeUnit)); PoolMetrics workerMetrics = metrics != null ? metrics.createPoolMetrics("worker", name, poolSize) : null; namedWorkerPools.put(name, sharedWorkerPool = new SharedWorkerPool(name, workerExec, workerMetrics)); } else { sharedWorkerPool.refCount++; } ContextImpl context = getOrCreateContext(); WorkerExecutorImpl namedExec = new WorkerExecutorImpl(context, sharedWorkerPool); context.addCloseHook(namedExec); return namedExec; }