- java.lang.Object
-
- com.github.mizosoft.methanol.internal.flow.AbstractSubscription<T>
-
- All Implemented Interfaces:
java.util.concurrent.Flow.Subscription
- Direct Known Subclasses:
AbstractPollableSubscription
public abstract class AbstractSubscription<T> extends java.lang.Object implements java.util.concurrent.Flow.SubscriptionAn abstractFlow.Subscriptionthat implements most of the machinery for execution and backpressure control.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSubscription(java.util.concurrent.Flow.Subscriber<? super T> downstream, java.util.concurrent.Executor executor)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidabort(boolean flowInterrupted)Releases resources held by this subscription.voidcancel()protected voidcancelOnComplete(java.util.concurrent.Flow.Subscriber<? super T> downstream)Calls downstream'sonCompleteafter cancelling this subscription.protected voidcancelOnError(java.util.concurrent.Flow.Subscriber<? super T> downstream, java.lang.Throwable exception, boolean flowInterrupted)Calls downstream'sonErrorwith the given exception after cancelling this subscription.protected longcurrentDemand()protected abstract longemit(java.util.concurrent.Flow.Subscriber<? super T> downstream, long emit)Emits at mostemititems to downstream usingsubmitOnNext( Subscriber, Object)as long as it returnstrue.voidfireOrKeepAlive()voidfireOrKeepAliveOnError(java.lang.Throwable exception)voidfireOrKeepAliveOnNext()protected booleanhasPendingErrors()Returnstrueif the subscriber is to be completed exceptionally.protected booleanisCancelled()Returnstrueif this subscription is cancelled.voidrequest(long n)protected booleansubmitOnNext(java.util.concurrent.Flow.Subscriber<? super T> downstream, T item)Submits given item to the downstream, returningfalseand cancelling on failure.
-
-
-
Constructor Detail
-
AbstractSubscription
protected AbstractSubscription(java.util.concurrent.Flow.Subscriber<? super T> downstream, java.util.concurrent.Executor executor)
-
-
Method Detail
-
request
public final void request(long n)
- Specified by:
requestin interfacejava.util.concurrent.Flow.Subscription
-
cancel
public final void cancel()
- Specified by:
cancelin interfacejava.util.concurrent.Flow.Subscription
-
fireOrKeepAlive
public void fireOrKeepAlive()
-
fireOrKeepAliveOnNext
public void fireOrKeepAliveOnNext()
-
fireOrKeepAliveOnError
public void fireOrKeepAliveOnError(java.lang.Throwable exception)
-
emit
protected abstract long emit(java.util.concurrent.Flow.Subscriber<? super T> downstream, long emit)
Emits at mostemititems to downstream usingsubmitOnNext( Subscriber, Object)as long as it returnstrue. The actual number of emitted items is returned, may be 0 in case of cancellation or if no items are emitted, perhaps due to lack thereof, or ifemititself is zero. If the underlying source is finished, the subscriber is completed withcancelOnComplete(Subscriber).
-
abort
protected void abort(boolean flowInterrupted)
Releases resources held by this subscription.flowInterruptedtells whether cancellation was due to flow interruption by downstream (e.g. callingcancel()or throwing fromonNextoronSubscribe), or due to ending the normal flow of signals (onSubscribe -> onNext* -> (onError | onComplete)).
-
isCancelled
protected final boolean isCancelled()
Returnstrueif this subscription is cancelled.falseresult is immediately outdated. Can be used by implementation to halt producing items in case the subscription was asynchronously cancelled.
-
hasPendingErrors
protected final boolean hasPendingErrors()
Returnstrueif the subscriber is to be completed exceptionally.falseresult is immediately outdated. Can be used by implementation to halt producing items in case the subscription was asynchronously signalled with an error.
-
cancelOnError
protected final void cancelOnError(java.util.concurrent.Flow.Subscriber<? super T> downstream, java.lang.Throwable exception, boolean flowInterrupted)
Calls downstream'sonErrorwith the given exception after cancelling this subscription.flowInterruptedtells whether the error interrupted the normal flow of signals.
-
cancelOnComplete
protected final void cancelOnComplete(java.util.concurrent.Flow.Subscriber<? super T> downstream)
Calls downstream'sonCompleteafter cancelling this subscription.
-
submitOnNext
protected final boolean submitOnNext(java.util.concurrent.Flow.Subscriber<? super T> downstream, T item)
Submits given item to the downstream, returningfalseand cancelling on failure.falseis also returned if the subscription is already cancelled or has pending errors. On such cases, caller should stop emitting items.
-
currentDemand
protected long currentDemand()
-
-