@Override protected void onRequest(long elements) { if (upstreamSubscription == null) { updatePendingRequests(elements); } else { requestUpstream(NO_CAPACITY, isComplete(), elements); } } };
/** * Build a {@literal Broadcaster}, ready to broadcast values with {@link reactor.rx.action * .Broadcaster#onNext(Object)}, * {@link Broadcaster#onError(Throwable)}, {@link Broadcaster#onComplete()}. * Values broadcasted are directly consumable by subscribing to the returned instance. * * @param <T> the type of values passing through the {@literal Broadcaster} * @return a new {@link reactor.rx.broadcast.Broadcaster} */ public static <T> Broadcaster<T> create() { return new Broadcaster<T>(null, SynchronousDispatcher.INSTANCE, Long.MAX_VALUE); }
@Override public void requestMore(long n) { if (upstreamSubscription != null) { requestMapperStream.onNext(n); } else { synchronized (this) { if ((pendingRequests += n) < 0l) { pendingRequests = Long.MAX_VALUE; } } } }
protected Stream<T> createWindowStream() { Broadcaster<T> action = timer != null && dispatcher == SynchronousDispatcher.INSTANCE ? SerializedBroadcaster.<T>create(environment, dispatcher) : Broadcaster.<T>create(environment, dispatcher); ReactiveSubscription<T> _currentWindow = new ReactiveSubscription<T>(null, action); currentWindow = _currentWindow; action.onSubscribe(_currentWindow); return action; }
private void flush() { Broadcaster<T> _currentWindow = windowBroadcaster; if (_currentWindow != null) { windowBroadcaster = null; _currentWindow.onComplete(); } }
protected Stream<T> createWindowStream(T first) { Broadcaster<T> action = BehaviorBroadcaster.first(first, environment, dispatcher); windowBroadcaster = action; return action; }
@Override protected void doError(Throwable ev) { if (windowBroadcaster != null) { windowBroadcaster.onError(ev); windowBroadcaster = null; } super.doError(ev); }
/** * Build a {@literal Broadcaster}, ready to broadcast values, ready to broadcast values with {@link * Broadcaster#onNext(Object)}, * {@link Broadcaster#onError(Throwable)}, {@link Broadcaster#onComplete()}. * Values broadcasted are directly consumable by subscribing to the returned instance. * * A serialized broadcaster will make sure that even in a multhithreaded scenario, only one thread will be able to broadcast at a time. * The synchronization is non blocking for the publisher, using thread-stealing and first-in-first-served patterns. * * @param env the Reactor {@link reactor.Environment} to use * @param <T> the type of values passing through the {@literal Broadcaster} * @return a new {@link Broadcaster} */ public static <T> Broadcaster<T> create(Environment env) { return new SerializedBroadcaster<>(env, SynchronousDispatcher.INSTANCE, Long.MAX_VALUE); }
@Override protected void doError(Throwable ev) { synchronized (this) { if (lastSignal.type == Signal.Type.COMPLETE || lastSignal.type == Signal.Type.ERROR) return; lastSignal.value = null; lastSignal.error = ev; lastSignal.type = Signal.Type.ERROR; } super.doError(ev); }
@Override protected void doComplete() { synchronized (this) { if (lastSignal.type == Signal.Type.COMPLETE || lastSignal.type == Signal.Type.ERROR) return; lastSignal.error = null; lastSignal.type = Signal.Type.COMPLETE; } super.doComplete(); }
@Override public void request(long n) { onError(withDefault.error); } };
/** * Build a {@literal Broadcaster}, ready to broadcast values with {@link * reactor.rx.action.Action#onNext(Object)}, * {@link Broadcaster#onError(Throwable)}, {@link Broadcaster#onComplete()}. * Values broadcasted are directly consumable by subscribing to the returned instance. * * @param dispatcher the {@link reactor.core.Dispatcher} to use * @param <T> the type of values passing through the {@literal Broadcaster} * @return a new {@link Broadcaster} */ public static <T> Broadcaster<T> create(Dispatcher dispatcher) { return create(null, dispatcher); }
@Override protected void doNext(O ev) { broadcastNext(ev); }
@Override public void onSubscribe(Subscription subscription) { super.onSubscribe(subscription); serializer.onSubscribe(subscription); }
@Override public void requestMore(long elements) { throttleStream.onNext(elements); }
/** * Build a {@literal Broadcaster}, first broadcasting the most recent signal then starting with the passed value, * then ready to broadcast values with {@link * reactor.rx.action.Action#onNext(Object)}, * {@link Broadcaster#onError(Throwable)}, {@link Broadcaster#onComplete()}. * Values broadcasted are directly consumable by subscribing to the returned instance. * * @param dispatcher the {@link reactor.core.Dispatcher} to use * @param <T> the type of values passing through the {@literal Broadcaster} * @return a new {@link Broadcaster} */ public static <T> Broadcaster<T> first(T value, Dispatcher dispatcher) { return first(value, null, dispatcher); }
/** * Build a {@literal Broadcaster}, ready to broadcast values with {@link reactor.rx.action * .Broadcaster#onNext(Object)}, * {@link Broadcaster#onError(Throwable)}, {@link Broadcaster#onComplete()}. * Values broadcasted are directly consumable by subscribing to the returned instance. * * A serialized broadcaster will make sure that even in a multhithreaded scenario, only one thread will be able to broadcast at a time. * The synchronization is non blocking for the publisher, using thread-stealing and first-in-first-served patterns. * * @param <T> the type of values passing through the {@literal action} * @return a new {@link reactor.rx.action.Action} */ public static <T> Broadcaster<T> create() { return new SerializedBroadcaster<>(null, SynchronousDispatcher.INSTANCE, Long.MAX_VALUE); }
@Override protected void doNext(T value) { if(windowBroadcaster == null) { broadcastNext(createWindowStream(value)); }else{ windowBroadcaster.onNext(value); } }
/** * Build a {@literal Broadcaster}, first broadcasting the most recent signal then ready to broadcast values with * {@link * reactor.rx.action.Action#onNext(Object)}, * {@link Broadcaster#onError(Throwable)}, {@link Broadcaster#onComplete()}. * Values broadcasted are directly consumable by subscribing to the returned instance. * * @param dispatcher the {@link reactor.core.Dispatcher} to use * @param <T> the type of values passing through the {@literal Broadcaster} * @return a new {@link Broadcaster} */ public static <T> Broadcaster<T> create(Dispatcher dispatcher) { return first(null, dispatcher); }
/** * Build a {@literal Broadcaster}, first broadcasting the most recent signal then * ready to broadcast values with {@link Broadcaster#onNext * (Object)}, * {@link Broadcaster#onError(Throwable)}, {@link Broadcaster#onComplete()}. * Values broadcasted are directly consumable by subscribing to the returned instance. * * @param env the Reactor {@link reactor.Environment} to use * @param dispatcher the {@link reactor.core.Dispatcher} to use * @param <T> the type of values passing through the {@literal Stream} * @return a new {@link Broadcaster} */ public static <T> Broadcaster<T> create(Environment env, Dispatcher dispatcher) { return first(null, env, dispatcher); }