use of reactor.core.scheduler.Scheduler.Worker in project reactor-core by reactor.
the class FluxInterval method subscribe.
@Override
public void subscribe(CoreSubscriber<? super Long> actual) {
Worker w = timedScheduler.createWorker();
IntervalRunnable r = new IntervalRunnable(actual, w);
actual.onSubscribe(r);
try {
w.schedulePeriodically(r, initialDelay, period, unit);
} catch (RejectedExecutionException ree) {
if (!r.cancelled) {
actual.onError(Operators.onRejectedExecution(ree, r, null, null, actual.currentContext()));
}
}
}
use of reactor.core.scheduler.Scheduler.Worker in project reactor-core by reactor.
the class FluxSubscribeOn method subscribe.
@Override
@SuppressWarnings("unchecked")
public void subscribe(CoreSubscriber<? super T> actual) {
Worker worker;
try {
worker = Objects.requireNonNull(scheduler.createWorker(), "The scheduler returned a null Function");
} catch (Throwable e) {
Operators.error(actual, Operators.onOperatorError(e, actual.currentContext()));
return;
}
SubscribeOnSubscriber<T> parent = new SubscribeOnSubscriber<>(source, actual, worker, requestOnSeparateThread);
actual.onSubscribe(parent);
try {
worker.schedule(parent);
} catch (RejectedExecutionException ree) {
if (parent.s != Operators.cancelledSubscription()) {
actual.onError(Operators.onRejectedExecution(ree, parent, null, null, actual.currentContext()));
}
}
}
use of reactor.core.scheduler.Scheduler.Worker in project reactor-core by reactor.
the class ParallelRunOn method subscribe.
@Override
@SuppressWarnings("unchecked")
public void subscribe(CoreSubscriber<? super T>[] subscribers) {
if (!validate(subscribers)) {
return;
}
int n = subscribers.length;
CoreSubscriber<T>[] parents = new CoreSubscriber[n];
boolean conditional = subscribers[0] instanceof Fuseable.ConditionalSubscriber;
for (int i = 0; i < n; i++) {
Worker w = scheduler.createWorker();
if (conditional) {
parents[i] = new FluxPublishOn.PublishOnConditionalSubscriber<>((Fuseable.ConditionalSubscriber<T>) subscribers[i], scheduler, w, true, prefetch, prefetch, queueSupplier);
} else {
parents[i] = new FluxPublishOn.PublishOnSubscriber<>(subscribers[i], scheduler, w, true, prefetch, prefetch, queueSupplier);
}
}
source.subscribe(parents);
}
use of reactor.core.scheduler.Scheduler.Worker in project reactor-core by reactor.
the class TimedSchedulerTest method massCancel.
@Test
public void massCancel() throws InterruptedException {
Scheduler timer = Schedulers.newSingle("test-timer");
try {
Worker w1 = timer.createWorker();
AtomicInteger counter = new AtomicInteger();
Runnable task = counter::getAndIncrement;
int tasks = 10;
Disposable[] c = new Disposable[tasks];
for (int i = 0; i < tasks; i++) {
c[i] = w1.schedulePeriodically(task, 500, 500, TimeUnit.MILLISECONDS);
}
w1.dispose();
for (int i = 0; i < tasks; i++) {
assertThat(c[i].isDisposed()).isTrue();
}
Assert.assertEquals(0, counter.get());
} finally {
timer.dispose();
}
}
use of reactor.core.scheduler.Scheduler.Worker in project reactor-core by reactor.
the class DelegateServiceSchedulerTest method notScheduledRejects.
@Test
public void notScheduledRejects() {
Scheduler s = Schedulers.fromExecutorService(Executors.newSingleThreadExecutor());
assertThatExceptionOfType(RejectedExecutionException.class).isThrownBy(() -> s.schedule(() -> {
}, 100, TimeUnit.MILLISECONDS)).describedAs("direct delayed scheduling").isSameAs(Exceptions.failWithRejectedNotTimeCapable());
assertThatExceptionOfType(RejectedExecutionException.class).isThrownBy(() -> s.schedulePeriodically(() -> {
}, 100, 100, TimeUnit.MILLISECONDS)).describedAs("direct periodic scheduling").isSameAs(Exceptions.failWithRejectedNotTimeCapable());
Worker w = s.createWorker();
assertThatExceptionOfType(RejectedExecutionException.class).isThrownBy(() -> w.schedule(() -> {
}, 100, TimeUnit.MILLISECONDS)).describedAs("worker delayed scheduling").isSameAs(Exceptions.failWithRejectedNotTimeCapable());
assertThatExceptionOfType(RejectedExecutionException.class).isThrownBy(() -> w.schedulePeriodically(() -> {
}, 100, 100, TimeUnit.MILLISECONDS)).describedAs("worker periodic scheduling").isSameAs(Exceptions.failWithRejectedNotTimeCapable());
}
Aggregations