private void flush() { Broadcaster<T> _currentWindow = windowBroadcaster; if (_currentWindow != null) { windowBroadcaster = null; _currentWindow.onComplete(); } }
@Override protected void doError(Throwable ev) { for (Broadcaster<T> bucket : currentWindows) { bucket.onError(ev); } currentWindows.clear(); super.doError(ev); }
@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; }
/** * 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 public Action<O, O> get() { Broadcaster<O> newStream = Broadcaster.<O>create(getEnvironment(), getDispatcher()).capacity(capacity); if (queueSupplier == null) { subscribeWithSubscription(newStream, new DropSubscription<O>(Action.this, newStream) { @Override public void request(long elements) { super.request(elements); requestUpstream(capacity, isComplete(), elements); } }); } else { subscribeWithSubscription(newStream, createSubscription(newStream, queueSupplier.get())); } return newStream; } });
/** * 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 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 protected void subscribeWithSubscription(Subscriber<? super O> subscriber, PushSubscription<O> subscription) { try { if (!addSubscription(subscription)) { subscriber.onError(new IllegalStateException("The subscription cannot be linked to this Stream")); } else { subscriber.onSubscribe(subscription); } } catch (Exception e) { Exceptions.throwIfFatal(e); subscriber.onError(e); } }
@Override protected void doNext(O ev) { broadcastNext(ev); }
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; }
return super.createSubscription(subscriber, queue);
requestMapper) { this.consumer = consumer; this.requestMapperStream = Broadcaster.create(); this.requestMapperStream.onSubscribe(new Subscription() { @Override public void request(long n) {
/** * Build a {@literal Broadcaster}, 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 <T> the type of values passing through the {@literal Broadcaster} * @return a new {@link Broadcaster} */ public static <T> Broadcaster<T> create(Environment env) { return create(env, env.getDefaultDispatcher()); }
@Override public Action<O, O> get() { Broadcaster<O> newStream = Broadcaster.<O>create(getEnvironment(), getDispatcher()).capacity(capacity); if (queueSupplier == null) { subscribeWithSubscription(newStream, new DropSubscription<O>(Action.this, newStream) { @Override public void request(long elements) { super.request(elements); requestUpstream(capacity, isComplete(), elements); } }); } else { subscribeWithSubscription(newStream, createSubscription(newStream, queueSupplier.get())); } return newStream; } });
/** * Build a {@literal Broadcaster}, 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) { 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 Broadcaster<T>(env, dispatcher, Action.evaluateCapacity(dispatcher.backlogSize())); }
@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 protected void subscribeWithSubscription(Subscriber<? super O> subscriber, PushSubscription<O> subscription) { try { if (!addSubscription(subscription)) { subscriber.onError(new IllegalStateException("The subscription cannot be linked to this Stream")); } else { subscriber.onSubscribe(subscription); } } catch (Exception e) { Exceptions.throwIfFatal(e); subscriber.onError(e); } }
@Override protected void doNext(O ev) { broadcastNext(ev); }
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; }