@Override public void close() { ExecutorServiceHelpers.shutdown(executor, maintenanceExecutor); } }
@VisibleForTesting public ConnectionFactoryImpl(ClientConfig clientConfig, Integer numThreadsInPool) { this.executor = ExecutorServiceHelpers.newScheduledThreadPool(getNumThreads(numThreadsInPool), "clientInternal"); this.clientConfig = clientConfig; this.group = getEventLoopGroup(); }
/** * This method will ensure the notification is intimated to the listeners of the same type. * * @param notification Notification to be notified. * @param <T> Type of notification. */ @Synchronized public <T extends Notification> void notify(final T notification) { String type = notification.getClass().getSimpleName(); map.get(type).forEach(l -> { log.info("Executing listener of type: {} for notification: {}", type, notification); ExecutorServiceHelpers.execute(() -> l.getListener().onNotification(notification), throwable -> log.error("Exception while executing listener for notification: {}", notification), () -> log.info("Completed execution of notify for notification :{}", notification), l.getExecutor()); }); }
@Test public void testParallelCreateStream() throws Exception { final ExecutorService executorService = ExecutorServiceHelpers.newScheduledThreadPool(10, "testParallelCreateStream"); Semaphore createCount = new Semaphore(-19); AtomicBoolean success = new AtomicBoolean(true); for (int i = 0; i < 10; i++) { executorService.submit(() -> { for (int j = 0; j < 2; j++) { try { CompletableFuture<Boolean> createStreamStatus; createStreamStatus = controllerClient.createStream("scope1", "streamparallel", StreamConfiguration.builder() .scalingPolicy(ScalingPolicy.fixed(1)) .build()); log.info("{}", createStreamStatus.get()); assertTrue(createStreamStatus.get()); createCount.release(); } catch (Exception e) { log.error("Exception when creating stream: {}", e); // Don't wait for other threads to complete. success.set(false); createCount.release(20); } } }); } createCount.acquire(); ExecutorServiceHelpers.shutdown(executorService); assertTrue(success.get()); }
@Override public ExecutorServiceHelpers.Snapshot getStorePoolSnapshot() { return this.storeExecutor.get() != null ? ExecutorServiceHelpers.getSnapshot(this.storeExecutor.get()) : null; }
@Test public void testParallelGetCurrentSegments() throws Exception { final ExecutorService executorService = ExecutorServiceHelpers.newScheduledThreadPool(10, "testParallelGetCurrentSegments"); Semaphore createCount = new Semaphore(-19); AtomicBoolean success = new AtomicBoolean(true); ExecutorServiceHelpers.shutdown(executorService); assertTrue(success.get());
private void report() { ExecutorServiceHelpers.Snapshot s = ExecutorServiceHelpers.getSnapshot(this.executor); if (s != null) { this.queueSize.reportSuccessValue(s.getQueueSize()); this.activeThreads.reportSuccessValue(s.getActiveThreadCount()); } } }
@Override public void close() { ExecutorServiceHelpers.shutdown(this.executor); } }
/** * Creates a new instance of the SelfTest class. * * @param testConfig The configuration to use for the test. * @param builderConfig The configuration to use for building the StreamSegmentStore Service. */ SelfTest(TestConfig testConfig, ServiceBuilderConfig builderConfig) { Preconditions.checkNotNull(builderConfig, "builderConfig"); this.testConfig = Preconditions.checkNotNull(testConfig, "testConfig"); this.closed = new AtomicBoolean(); this.actors = new ArrayList<>(); this.testCompletion = new AtomicReference<>(); this.state = new TestState(); this.executor = ExecutorServiceHelpers.newScheduledThreadPool(testConfig.getThreadPoolSize(), "self-test"); this.store = StoreAdapter.create(testConfig, builderConfig, this.executor); this.dataSource = new ProducerDataSource(this.testConfig, this.state, this.store); Services.onStop(this, this::shutdownCallback, this::shutdownCallback, this.executor); this.reporter = new Reporter(this.state, this.testConfig, this.store::getStorePoolSnapshot, this.executor); }
val testPoolSnapshot = ExecutorServiceHelpers.getSnapshot(this.executorService); val joinPoolSnapshot = ExecutorServiceHelpers.getSnapshot(ForkJoinPool.commonPool()); val storePoolSnapshot = this.storePoolSnapshotProvider.get(); long time = System.nanoTime();
ExecutorServiceHelpers.execute( runCount::incrementAndGet, exceptionHolder::set, exceptionHolder.set(null); finallyCount.set(0); ExecutorServiceHelpers.execute( () -> { throw new IntentionalException(); AssertExtensions.assertThrows( "execute did not throw appropriate exception when executor was closed", () -> ExecutorServiceHelpers.execute( runCount::incrementAndGet, exceptionHolder::set,
@Override public void close() { log.info("Closing Pinger periodic task"); ExecutorServiceHelpers.shutdown(executor); } }
this.scheduledExecutor = ExecutorServiceHelpers.newScheduledThreadPool(1, "fetch-controllers"); } else { this.scheduledExecutor = null;
/** * Shuts down the given ExecutorServices in two phases, using a timeout of 5 seconds: * 1. Prevents new tasks from being submitted. * 2. Awaits for currently running tasks to terminate. If they don't terminate within the given timeout, they will be * forcibly cancelled. * * @param pools The ExecutorServices to shut down. */ public static void shutdown(ExecutorService... pools) { shutdown(Duration.ofSeconds(5), pools); }
public StreamManagerImpl(ClientConfig clientConfig) { this.executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "StreamManager-Controller"); this.controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(clientConfig) .build(), executor); this.connectionFactory = new ConnectionFactoryImpl(clientConfig); this.streamCutHelper = new StreamCutHelper(controller, connectionFactory); }
@Override public void close() { log.info("Shutting down connection factory"); if (closed.compareAndSet(false, true)) { // Shut down the event loop to terminate all threads. group.shutdownGracefully(); ExecutorServiceHelpers.shutdown(executor); } }
/** * Invoke the createStream method, ensure we are able to create scope, stream. * * @throws InterruptedException if interrupted * @throws URISyntaxException If URI is invalid * @throws ExecutionException if error in create stream */ @Before public void setup() throws InterruptedException, ExecutionException { Controller controller = getController(); executorService = ExecutorServiceHelpers.newScheduledThreadPool(4, "ReadWithAutoScaleTest-main"); //create a scope Boolean createScopeStatus = controller.createScope(SCOPE).get(); log.debug("Create scope status {}", createScopeStatus); //create a stream Boolean createStreamStatus = controller.createStream(SCOPE, STREAM_NAME, CONFIG).get(); log.debug("Create stream status {}", createStreamStatus); }
@Override @Synchronized public void shutdown() { if (!shutdown) { log.info("Shutting down ControllerNameResolver"); if (this.scheduledExecutor != null) { ExecutorServiceHelpers.shutdown(this.scheduledExecutor); } shutdown = true; } }
executorService = ExecutorServiceHelpers.newScheduledThreadPool(5, "AutoScaleTest-main"); Boolean createScopeStatus = controller.createScope(SCOPE).get(); log.debug("create scope status {}", createScopeStatus);
@Override public void cleanupTaskStore() throws IOException { if (executor != null) { ExecutorServiceHelpers.shutdown(executor); } } }