Package kong.unirest.core.java
Class MultipartSubscription
java.lang.Object
kong.unirest.core.java.MultipartSubscription
- All Implemented Interfaces:
Flow.Subscription
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stringprivate static final intprivate static final Flow.Subscriber<ByteBuffer> private booleanprivate longprivate static final VarHandleprivate final Flow.Subscriber<? super ByteBuffer> private final Executorprivate static final intprivate final ProgressMonitorprivate static final VarHandleprivate intprivate Flow.Subscriber<ByteBuffer> private static final VarHandleprivate Throwableprivate static final intprivate intprivate static final VarHandleprivate static final int(package private) static final Executor -
Constructor Summary
ConstructorsConstructorDescriptionMultipartSubscription(String boundary, List<Part> parts, ProgressMonitor monitor, Flow.Subscriber<? super ByteBuffer> downstream) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidabort(boolean flowInterrupted) Called when the subscription is cancelled.final voidcancel()private final voidcancelOnComplete(Flow.Subscriber<? super ByteBuffer> downstream) Calls downstream'sonCompleteafter cancelling this subscription.private final voidcancelOnError(Flow.Subscriber<? super ByteBuffer> downstream, Throwable error, boolean flowInterrupted) Calls downstream'sonErrorafter cancelling this subscription.private longemit(Flow.Subscriber<? super ByteBuffer> downstream, long emit) Main method for item emission.private longgetAndAddDemand(Object owner, VarHandle demand, long n) Adds given count to demand not exceedingLong.MAX_VALUE.private intgetAndBitwiseOrState(int bits) private final booleanReturnstrueif the subscriber is to be completed exceptionally.private final booleanReturnstrueif cancelled.private ByteBufferprivate ByteBufferpollNext()private ThrowablepropagateError(Throwable error) Sets pending error or adds new one as suppressed in case of multiple error sources.final voidrequest(long n) private voidrun()private voidsignal()final voidsignal(boolean force) Schedules a signaller task.final voidsignalError(Throwable error) private final booleansubmitOnNext(Flow.Subscriber<? super ByteBuffer> downstream, ByteBuffer item) Submits given item to the downstream, returningfalseand cancelling on failure.private voidsubscribeOnDrain(Flow.Subscriber<? super ByteBuffer> downstream) private booleansubscribeToPart(Part part) private longsubtractAndGetDemand(Object owner, VarHandle demand, long n) Subtracts given count from demand.
-
Field Details
-
SYNC_EXECUTOR
-
RUN
private static final int RUN- See Also:
-
KEEP_ALIVE
private static final int KEEP_ALIVE- See Also:
-
CANCELLED
private static final int CANCELLED- See Also:
-
SUBSCRIBED
private static final int SUBSCRIBED- See Also:
-
STATE
-
PENDING_ERROR
-
DEMAND
-
PART_SUBSCRIBER
-
CANCELLED_SUBSCRIBER
-
boundary
-
parts
-
partIndex
private int partIndex -
complete
private boolean complete -
monitor
-
downstream
-
executor
-
partSubscriber
-
state
private volatile int state -
demand
private volatile long demand -
pendingError
-
-
Constructor Details
-
MultipartSubscription
MultipartSubscription(String boundary, List<Part> parts, ProgressMonitor monitor, Flow.Subscriber<? super ByteBuffer> downstream)
-
-
Method Details
-
request
public final void request(long n) - Specified by:
requestin interfaceFlow.Subscription
-
cancel
public final void cancel()- Specified by:
cancelin interfaceFlow.Subscription
-
getAndAddDemand
Adds given count to demand not exceedingLong.MAX_VALUE. -
subtractAndGetDemand
Subtracts given count from demand. Caller ensures result won't be negative. -
signal
public final void signal(boolean force) Schedules a signaller task.forcetells whether to schedule in case of no demand -
signalError
-
isCancelled
private final boolean isCancelled()Returnstrueif cancelled.falseresult is immediately outdated. -
hasPendingErrors
private 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
private final void cancelOnError(Flow.Subscriber<? super ByteBuffer> downstream, Throwable error, boolean flowInterrupted) Calls downstream'sonErrorafter cancelling this subscription.flowInterruptedtells whether the error interrupted the normal flow of signals. -
cancelOnComplete
Calls downstream'sonCompleteafter cancelling this subscription. -
submitOnNext
Submits given item to the downstream, returningfalseand cancelling on failure. -
signal
private void signal() -
run
private void run() -
subscribeOnDrain
-
propagateError
Sets pending error or adds new one as suppressed in case of multiple error sources. -
getAndBitwiseOrState
private int getAndBitwiseOrState(int bits) -
emit
Main method for item emission. At mosteitems are emitted to the downstream using {submitOnNext(Flow.Subscriber, Object)} as long as it returnstrue. The actual number of emitted items is returned, may be0in case of cancellation. If the underlying source is finished, the subscriber is completed withcancelOnComplete(Flow.Subscriber). -
abort
private void abort(boolean flowInterrupted) Called when the subscription is cancelled.flowInterruptedspecifies whether cancellation was due to ending the normal flow of signals (signal|signalError) or due to flow interruption by downstream (e.g. callingcancel()or throwing fromonNext). -
pollNext
-
nextPartHeaders
-
subscribeToPart
-