/** * Delegates call to {@link ExecutorService#submit(Callable)} and propagates thread locals to it * like defined by {@link ThreadLocalPropagateContext}. */ public <T> Future<T> submit(Callable<T> callable) { return executor.submit(ThreadLocalPropagateContext.wrap(callable)); }
/** * Asynchronously runs the given task wrapping it with {@link * ThreadLocalPropagateContext#wrap(Runnable)} * * @param runnable task to run * @return completable future bounded to the task */ public CompletableFuture<Void> runAsync(Runnable runnable) { return CompletableFuture.runAsync(ThreadLocalPropagateContext.wrap(runnable), executor); }
@Override public void process(Runnable runnable) { executorService.execute(ThreadLocalPropagateContext.wrap(runnable)); } }
/** * Delegates call to {@link ExecutorService#execute(Runnable)} and propagates thread locals to it * like defined by {@link ThreadLocalPropagateContext}. */ public void execute(Runnable runnable) { executor.execute(ThreadLocalPropagateContext.wrap(runnable)); }
@Override protected Callable<Object> newCallable(Object resource, Method method, Object[] params) { return ThreadLocalPropagateContext.wrap((super.newCallable(resource, method, params))); } }
/** * Stops some of the system services preparing system to full shutdown. System status is changed * from {@link SystemStatus#RUNNING} to {@link SystemStatus#PREPARING_TO_SHUTDOWN}. * * @throws ConflictException when system status is different from running */ public void stopServices() throws ConflictException { if (!statusRef.compareAndSet(RUNNING, PREPARING_TO_SHUTDOWN)) { throw new ConflictException( "System shutdown has been already called, system status: " + statusRef.get()); } ExecutorService exec = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("ShutdownSystemServicesPool") .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .build()); exec.execute(ThreadLocalPropagateContext.wrap(this::doStopServices)); exec.shutdown(); }
/** * Suspends some of the system services preparing system to lighter shutdown. System status is * changed from {@link SystemStatus#RUNNING} to {@link SystemStatus#PREPARING_TO_SHUTDOWN}. * * @throws ConflictException when system status is different from running */ public void suspendServices() throws ConflictException { if (!statusRef.compareAndSet(RUNNING, PREPARING_TO_SHUTDOWN)) { throw new ConflictException( "System shutdown has been already called, system status: " + statusRef.get()); } ExecutorService exec = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("SuspendSystemServicesPool") .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .build()); exec.execute(ThreadLocalPropagateContext.wrap(this::doSuspendServices)); exec.shutdown(); }
publishWorkspaceStatusEvent(workspaceId, STOPPING, status, options.get(WORKSPACE_STOP_REASON)); return CompletableFuture.runAsync( ThreadLocalPropagateContext.wrap(new StopRuntimeTask(workspace, options, stoppedBy)), sharedPool.getExecutor());
ThreadLocalPropagateContext.wrap(new StartRuntimeTask(workspace, options, runtime)), sharedPool.getExecutor()); } catch (ValidationException e) {