use of reactor.core.Disposable in project reactor-core by reactor.
the class SchedulerTask method call.
@Override
@Nullable
public Void call() {
thread = Thread.currentThread();
Disposable d = null;
try {
for (; ; ) {
d = parent;
if (d == TAKEN || d == null) {
break;
}
if (PARENT.compareAndSet(this, d, TAKEN)) {
break;
}
}
try {
task.run();
} catch (Throwable ex) {
Schedulers.handleError(ex);
}
} finally {
thread = null;
Future f;
for (; ; ) {
f = future;
if (f == CANCELLED || FUTURE.compareAndSet(this, f, FINISHED)) {
break;
}
}
if (d != null) {
d.dispose();
}
}
return null;
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class MonoCacheTimeTest method coordinatorReachableThroughCacheInnerSubscriptionsOnly.
@Test
public void coordinatorReachableThroughCacheInnerSubscriptionsOnly() throws InterruptedException {
TestPublisher<Integer> source = TestPublisher.create();
MonoCacheTime<Integer> cached = new MonoCacheTime<>(source.mono(), // short cache TTL should trigger state change if source is not never
Duration.ofMillis(100), Schedulers.parallel());
Disposable d1 = cached.subscribe();
cached.subscribe();
WeakReference<Signal<Integer>> refCoordinator = new WeakReference<>(cached.state);
assertThat(refCoordinator.get()).isInstanceOf(MonoCacheTime.CoordinatorSubscriber.class);
Thread.sleep(150);
source = null;
cached = null;
System.gc();
assertThat(refCoordinator.get()).isInstanceOf(MonoCacheTime.CoordinatorSubscriber.class);
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class SchedulersTest method testWorkerScheduleSupportZeroPeriod.
@Test
public void testWorkerScheduleSupportZeroPeriod() throws InterruptedException {
try (TaskCheckingScheduledExecutor executorService = new TaskCheckingScheduledExecutor()) {
CountDownLatch latch = new CountDownLatch(2);
Disposable.Composite tasks = Disposables.composite();
Disposable disposable = Schedulers.workerSchedulePeriodically(executorService, tasks, latch::countDown, 0, 0, TimeUnit.MILLISECONDS);
latch.await();
disposable.dispose();
Thread.sleep(100);
int tasksBefore = executorService.tasks.size();
Thread.sleep(100);
int tasksAfter = executorService.tasks.size();
assertThat(tasksAfter).isEqualTo(tasksBefore);
assertThat(tasks.size()).isEqualTo(0);
}
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class SchedulersTest method schedulerDecoratorDisposedWhenRemoved.
@Test
public void schedulerDecoratorDisposedWhenRemoved() {
AtomicBoolean disposeTracker = new AtomicBoolean();
class DisposableDecorator implements BiFunction<Scheduler, ScheduledExecutorService, ScheduledExecutorService>, Disposable {
@Override
public ScheduledExecutorService apply(Scheduler scheduler, ScheduledExecutorService service) {
return service;
}
@Override
public void dispose() {
disposeTracker.set(true);
}
}
DisposableDecorator decorator = new DisposableDecorator();
Schedulers.addExecutorServiceDecorator("k1", decorator);
assertThat(Schedulers.removeExecutorServiceDecorator("k1")).as("decorator removed").isSameAs(decorator);
assertThat(disposeTracker).as("decorator disposed").isTrue();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class SchedulersTest method testDirectScheduleZeroPeriodicallyCancelsSchedulerTask.
@Test
public void testDirectScheduleZeroPeriodicallyCancelsSchedulerTask() throws Exception {
try (TaskCheckingScheduledExecutor executorService = new TaskCheckingScheduledExecutor()) {
CountDownLatch latch = new CountDownLatch(2);
Disposable disposable = Schedulers.directSchedulePeriodically(executorService, latch::countDown, 0, 0, TimeUnit.MILLISECONDS);
latch.await();
disposable.dispose();
// avoid race of checking the status of futures vs cancelling said futures
await().atMost(500, TimeUnit.MILLISECONDS).pollDelay(10, TimeUnit.MILLISECONDS).pollInterval(50, TimeUnit.MILLISECONDS).until(executorService::isAllTasksCancelledOrDone);
}
}
Aggregations