new DelegateServiceScheduler.UnsupportedScheduledExecutorService(threadPool); unsupportedScheduledExecutorService.shutdownNow(); threadPool.shutdownNow(); scheduledThreadPool.shutdownNow();
static final Object scanExecutor(Executor executor, Scannable.Attr key) { if (executor instanceof DelegateServiceScheduler.UnsupportedScheduledExecutorService) { executor = ((DelegateServiceScheduler.UnsupportedScheduledExecutorService) executor).get();
static final Object scanExecutor(Executor executor, Scannable.Attr key) { if (executor instanceof DelegateServiceScheduler.UnsupportedScheduledExecutorService) { executor = ((DelegateServiceScheduler.UnsupportedScheduledExecutorService) executor).get();
@SuppressWarnings("unchecked") static ScheduledExecutorService convert(ExecutorService executor) { if (executor instanceof ScheduledExecutorService) { return (ScheduledExecutorService) executor; } return new UnsupportedScheduledExecutorService(executor); }
@Test public void scanExecutorCapacity() { Executor plain = Runnable::run; ExecutorService plainService = Executors.newSingleThreadExecutor(); ExecutorService threadPool = Executors.newFixedThreadPool(3); ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(4); DelegateServiceScheduler.UnsupportedScheduledExecutorService unsupportedScheduledExecutorService = new DelegateServiceScheduler.UnsupportedScheduledExecutorService(threadPool); try { assertThat(Schedulers.scanExecutor(plain, Scannable.Attr.CAPACITY)) .as("plain").isEqualTo(null); assertThat(Schedulers.scanExecutor(plainService, Scannable.Attr.CAPACITY)) .as("plainService").isEqualTo(null); assertThat(Schedulers.scanExecutor(threadPool, Scannable.Attr.CAPACITY)) .as("threadPool").isEqualTo(3); assertThat(Schedulers.scanExecutor(scheduledThreadPool, Scannable.Attr.CAPACITY)) .as("scheduledThreadPool").isEqualTo(Integer.MAX_VALUE); assertThat(Schedulers.scanExecutor(unsupportedScheduledExecutorService, Scannable.Attr.CAPACITY)) .as("unwrapped").isEqualTo(3); } finally { plainService.shutdownNow(); unsupportedScheduledExecutorService.shutdownNow(); threadPool.shutdownNow(); scheduledThreadPool.shutdownNow(); } }
@SuppressWarnings("unchecked") static ScheduledExecutorService convert(ExecutorService executor) { if (executor instanceof ScheduledExecutorService) { return (ScheduledExecutorService) executor; } return new UnsupportedScheduledExecutorService(executor); }