DelegateServiceScheduler(ExecutorService executorService) { ScheduledExecutorService exec = convert(executorService); this.executor = Schedulers.decorateExecutorService(this, exec); }
CachedService(@Nullable ElasticScheduler parent) { this.parent = parent; if (parent != null) { this.exec = Schedulers.decorateExecutorService(parent, parent.get()); } else { this.exec = Executors.newSingleThreadScheduledExecutor(); this.exec.shutdownNow(); } }
@Override public void start() { //TODO SingleTimedScheduler didn't implement start, check if any particular reason? ScheduledExecutorService b = null; for (; ; ) { ScheduledExecutorService a = executor; if (a != TERMINATED) { if (b != null) { b.shutdownNow(); } return; } if (b == null) { b = Schedulers.decorateExecutorService(this, this.get()); } if (EXECUTORS.compareAndSet(this, a, b)) { return; } } }
@Override public void start() { ScheduledExecutorService[] b = null; for (;;) { ScheduledExecutorService[] a = executors; if (a != SHUTDOWN) { if (b != null) { for (ScheduledExecutorService exec : b) { exec.shutdownNow(); } } return; } if (b == null) { b = new ScheduledExecutorService[n]; for (int i = 0; i < n; i++) { b[i] = Schedulers.decorateExecutorService(this, this.get()); } } if (EXECUTORS.compareAndSet(this, a, b)) { return; } } }
void init(int n) { ScheduledExecutorService[] a = new ScheduledExecutorService[n]; for (int i = 0; i < n; i++) { a[i] = Schedulers.decorateExecutorService(this, this.get()); } EXECUTORS.lazySet(this, a); }
private void init() { EXECUTORS.lazySet(this, Schedulers.decorateExecutorService(this, this.get())); }
@Test public void decorateTwiceWithSameSchedulerInstance() { Scheduler instance = Schedulers.newElastic("TWICE", 1); ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); Schedulers.decorateExecutorService(instance, service); Schedulers.decorateExecutorService(instance, service); assertThat(simpleMeterRegistry.getMeters() .stream() .map(m -> m.getId().getTag("name")) .distinct()) .containsOnly( "elastic(\"TWICE\")-0", "elastic(\"TWICE\")-1" ); }
@Test public void schedulersInstrumentation() { try { assertThatCode(() -> { Schedulers.enableMetrics(); Scheduler s = Schedulers.newSingle("foo"); Schedulers.decorateExecutorService(s, Executors.newSingleThreadScheduledExecutor()); s.schedule(() -> System.out.println("schedulers instrumentation no micrometer")); }) .doesNotThrowAnyException(); } finally { Schedulers.disableMetrics(); } }
DelegateServiceScheduler(ExecutorService executorService) { ScheduledExecutorService exec = convert(executorService); this.executor = Schedulers.decorateExecutorService(this, exec); }
CachedService(@Nullable ElasticScheduler parent) { this.parent = parent; if (parent != null) { this.exec = Schedulers.decorateExecutorService(parent, parent.get()); } else { this.exec = Executors.newSingleThreadScheduledExecutor(); this.exec.shutdownNow(); } }
@Override public void start() { //TODO SingleTimedScheduler didn't implement start, check if any particular reason? ScheduledExecutorService b = null; for (; ; ) { ScheduledExecutorService a = executor; if (a != TERMINATED) { if (b != null) { b.shutdownNow(); } return; } if (b == null) { b = Schedulers.decorateExecutorService(this, this.get()); } if (EXECUTORS.compareAndSet(this, a, b)) { return; } } }
@Override public void start() { ScheduledExecutorService[] b = null; for (;;) { ScheduledExecutorService[] a = executors; if (a != SHUTDOWN) { if (b != null) { for (ScheduledExecutorService exec : b) { exec.shutdownNow(); } } return; } if (b == null) { b = new ScheduledExecutorService[n]; for (int i = 0; i < n; i++) { b[i] = Schedulers.decorateExecutorService(this, this.get()); } } if (EXECUTORS.compareAndSet(this, a, b)) { return; } } }
void init(int n) { ScheduledExecutorService[] a = new ScheduledExecutorService[n]; for (int i = 0; i < n; i++) { a[i] = Schedulers.decorateExecutorService(this, this.get()); } EXECUTORS.lazySet(this, a); }
private void init() { EXECUTORS.lazySet(this, Schedulers.decorateExecutorService(this, this.get())); }