/** * Build a {@literal Broadcaster}, rfirst broadcasting the most recent signal then starting with the passed value, * then ready to broadcast values with {@link reactor.rx.action * .Broadcaster#onNext(Object)}, * {@link reactor.rx.broadcast.Broadcaster#onError(Throwable)}, {@link reactor.rx.broadcast.Broadcaster#onComplete * ()}. * Values broadcasted are directly consumable by subscribing to the returned instance. * <p> * 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> first(T value) { return new BehaviorBroadcaster<>(null, SynchronousDispatcher.INSTANCE, Long.MAX_VALUE, value); }
protected Stream<T> createWindowStream(T first) { Broadcaster<T> action = BehaviorBroadcaster.first(first, environment, dispatcher); windowBroadcaster = action; return action; }
@Override protected void onRequest(long elements) { if (upstreamSubscription != null) { super.onRequest(elements); requestUpstream(capacity, buffer.isComplete(), elements); } } };
@Override public void onNext(O ev) { if (!dispatcher.inContext()) { dispatcher.dispatch(ev, this, null); } else { synchronized (this) { if (lastSignal.type == Signal.Type.COMPLETE || lastSignal.type == Signal.Type.ERROR) return; lastSignal.value = ev; lastSignal.error = null; lastSignal.type = Signal.Type.NEXT; try { broadcastNext(ev); } catch (CancelException ce) { //IGNORE since cached } } } }
@Override public void onNext(O ev) { if (!dispatcher.inContext()) { dispatcher.dispatch(ev, this, null); } else { synchronized (this) { if (lastSignal.type == Signal.Type.COMPLETE || lastSignal.type == Signal.Type.ERROR) return; lastSignal.value = ev; lastSignal.error = null; lastSignal.type = Signal.Type.NEXT; try { broadcastNext(ev); } catch (CancelException ce) { //IGNORE since cached } } } }
/** * 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); }
@Override protected void onRequest(long elements) { if (upstreamSubscription == null) { updatePendingRequests(elements); } else { requestUpstream(NO_CAPACITY, isComplete(), elements); } } };
/** * Build a {@literal Broadcaster}, first broadcasting the most recent signal then starting with the passed value, * 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> first(T value, Environment env, Dispatcher dispatcher) { Assert.state(dispatcher.supportsOrdering(), "Dispatcher provided doesn't support event ordering. " + " For concurrent consume, refer to Stream#partition/groupBy() method and assign individual single " + "dispatchers"); return new BehaviorBroadcaster<>(env, dispatcher, Action.evaluateCapacity(dispatcher.backlogSize()), value); }
/** * 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); }
@Override protected void onRequest(long elements) { if (upstreamSubscription == null) { updatePendingRequests(elements); } else { requestUpstream(NO_CAPACITY, isComplete(), elements); } } };
/** * Build a {@literal Broadcaster}, rfirst broadcasting the most recent signal then starting with the passed value, * then ready to broadcast values with {@link reactor.rx.action * .Broadcaster#onNext(Object)}, * {@link reactor.rx.broadcast.Broadcaster#onError(Throwable)}, {@link reactor.rx.broadcast.Broadcaster#onComplete * ()}. * Values broadcasted are directly consumable by subscribing to the returned instance. * <p> * 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> first(T value) { return new BehaviorBroadcaster<>(null, SynchronousDispatcher.INSTANCE, Long.MAX_VALUE, value); }
/** * 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); }
@Override protected void onRequest(long elements) { if (upstreamSubscription != null) { super.onRequest(elements); requestUpstream(capacity, buffer.isComplete(), elements); } } };
/** * Build a {@literal Broadcaster}, first broadcasting the most recent signal then starting with the passed value, * 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> first(T value, Environment env, Dispatcher dispatcher) { Assert.state(dispatcher.supportsOrdering(), "Dispatcher provided doesn't support event ordering. " + " For concurrent consume, refer to Stream#partition/groupBy() method and assign individual single " + "dispatchers"); return new BehaviorBroadcaster<>(env, dispatcher, Action.evaluateCapacity(dispatcher.backlogSize()), value); }
/** * Build a {@literal Broadcaster}, first broadcasting the most recent signal then ready to broadcast values with * {@link * reactor.rx.broadcast.Broadcaster#onNext(Object)}, * {@link reactor.rx.broadcast.Broadcaster#onError(Throwable)}, {@link reactor.rx.broadcast.Broadcaster#onComplete * ()}. * Values broadcasted are directly consumable by subscribing to the returned instance. * <p> * 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 reactor.rx.broadcast.Broadcaster} */ public static <T> Broadcaster<T> create(Environment env) { return first(null, env); }
protected Broadcaster<T> createWindowStream(T first) { Broadcaster<T> action = BehaviorBroadcaster.first(first, environment, dispatcher); currentWindows.add(action); broadcastNext(action); return action; }
/** * 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.broadcast.Broadcaster#onNext(Object)}, * {@link reactor.rx.broadcast.Broadcaster#onError(Throwable)}, {@link reactor.rx.broadcast.Broadcaster#onComplete * ()}. * Values broadcasted are directly consumable by subscribing to the returned instance. * <p> * 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 reactor.rx.broadcast.Broadcaster} */ public static <T> Broadcaster<T> first(T value, Environment env) { return first(value, env, env.getDefaultDispatcher()); }
public Stream<O> stream() { lock.lock(); try { if (outboundStream == null) { outboundStream = BehaviorBroadcaster.first(value, environment, dispatcher).capacity(1); if (isSuccess()) { outboundStream.onComplete(); } else if (isError()) { outboundStream.onError(error); } } } finally { lock.unlock(); } return outboundStream; }
protected Stream<T> createWindowStream(T first) { Broadcaster<T> action = BehaviorBroadcaster.first(first, environment, dispatcher); windowBroadcaster = action; return action; }
/** * 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); }