Package kong.unirest.core.java
Class MultipartSubscription
- java.lang.Object
-
- kong.unirest.core.java.MultipartSubscription
-
- All Implemented Interfaces:
java.util.concurrent.Flow.Subscription
class MultipartSubscription extends java.lang.Object implements java.util.concurrent.Flow.Subscription
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringboundaryprivate static intCANCELLEDprivate static java.util.concurrent.Flow.Subscriber<java.nio.ByteBuffer>CANCELLED_SUBSCRIBERprivate booleancompleteprivate longdemandprivate static java.lang.invoke.VarHandleDEMANDprivate java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer>downstreamprivate java.util.concurrent.Executorexecutorprivate static intKEEP_ALIVEprivate ProgressMonitormonitorprivate static java.lang.invoke.VarHandlePART_SUBSCRIBERprivate intpartIndexprivate java.util.List<Part>partsprivate java.util.concurrent.Flow.Subscriber<java.nio.ByteBuffer>partSubscriberprivate static java.lang.invoke.VarHandlePENDING_ERRORprivate java.lang.ThrowablependingErrorprivate static intRUNprivate intstateprivate static java.lang.invoke.VarHandleSTATEprivate static intSUBSCRIBED(package private) static java.util.concurrent.ExecutorSYNC_EXECUTOR
-
Constructor Summary
Constructors Constructor Description MultipartSubscription(java.lang.String boundary, java.util.List<Part> parts, ProgressMonitor monitor, java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidabort(boolean flowInterrupted)Called when the subscription is cancelled.voidcancel()private voidcancelOnComplete(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)Calls downstream'sonCompleteafter cancelling this subscription.private voidcancelOnError(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, java.lang.Throwable error, boolean flowInterrupted)Calls downstream'sonErrorafter cancelling this subscription.private longemit(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, long emit)Main method for item emission.private longgetAndAddDemand(java.lang.Object owner, java.lang.invoke.VarHandle demand, long n)Adds given count to demand not exceedingLong.MAX_VALUE.private intgetAndBitwiseOrState(int bits)private booleanhasPendingErrors()Returnstrueif the subscriber is to be completed exceptionally.private booleanisCancelled()Returnstrueif cancelled.private java.nio.ByteBuffernextPartHeaders()private java.nio.ByteBufferpollNext()private java.lang.ThrowablepropagateError(java.lang.Throwable error)Sets pending error or adds new one as suppressed in case of multiple error sources.voidrequest(long n)private voidrun()private voidsignal()voidsignal(boolean force)Schedules a signaller task.voidsignalError(java.lang.Throwable error)private booleansubmitOnNext(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, java.nio.ByteBuffer item)Submits given item to the downstream, returningfalseand cancelling on failure.private voidsubscribeOnDrain(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)private booleansubscribeToPart(Part part)private longsubtractAndGetDemand(java.lang.Object owner, java.lang.invoke.VarHandle demand, long n)Subtracts given count from demand.
-
-
-
Field Detail
-
SYNC_EXECUTOR
static final java.util.concurrent.Executor SYNC_EXECUTOR
-
RUN
private static final int RUN
- See Also:
- Constant Field Values
-
KEEP_ALIVE
private static final int KEEP_ALIVE
- See Also:
- Constant Field Values
-
CANCELLED
private static final int CANCELLED
- See Also:
- Constant Field Values
-
SUBSCRIBED
private static final int SUBSCRIBED
- See Also:
- Constant Field Values
-
STATE
private static final java.lang.invoke.VarHandle STATE
-
PENDING_ERROR
private static final java.lang.invoke.VarHandle PENDING_ERROR
-
DEMAND
private static final java.lang.invoke.VarHandle DEMAND
-
PART_SUBSCRIBER
private static final java.lang.invoke.VarHandle PART_SUBSCRIBER
-
CANCELLED_SUBSCRIBER
private static final java.util.concurrent.Flow.Subscriber<java.nio.ByteBuffer> CANCELLED_SUBSCRIBER
-
boundary
private final java.lang.String boundary
-
parts
private final java.util.List<Part> parts
-
partIndex
private int partIndex
-
complete
private boolean complete
-
monitor
private final ProgressMonitor monitor
-
downstream
private final java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream
-
executor
private final java.util.concurrent.Executor executor
-
partSubscriber
private volatile java.util.concurrent.Flow.Subscriber<java.nio.ByteBuffer> partSubscriber
-
state
private volatile int state
-
demand
private volatile long demand
-
pendingError
private volatile java.lang.Throwable pendingError
-
-
Constructor Detail
-
MultipartSubscription
MultipartSubscription(java.lang.String boundary, java.util.List<Part> parts, ProgressMonitor monitor, java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)
-
-
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
-
getAndAddDemand
private long getAndAddDemand(java.lang.Object owner, java.lang.invoke.VarHandle demand, long n)Adds given count to demand not exceedingLong.MAX_VALUE.
-
subtractAndGetDemand
private long subtractAndGetDemand(java.lang.Object owner, java.lang.invoke.VarHandle demand, long n)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
public final void signalError(java.lang.Throwable error)
-
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(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, java.lang.Throwable error, boolean flowInterrupted)Calls downstream'sonErrorafter cancelling this subscription.flowInterruptedtells whether the error interrupted the normal flow of signals.
-
cancelOnComplete
private final void cancelOnComplete(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)
Calls downstream'sonCompleteafter cancelling this subscription.
-
submitOnNext
private final boolean submitOnNext(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, java.nio.ByteBuffer item)Submits given item to the downstream, returningfalseand cancelling on failure.
-
signal
private void signal()
-
run
private void run()
-
subscribeOnDrain
private void subscribeOnDrain(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)
-
propagateError
private java.lang.Throwable propagateError(java.lang.Throwable error)
Sets pending error or adds new one as suppressed in case of multiple error sources.
-
getAndBitwiseOrState
private int getAndBitwiseOrState(int bits)
-
emit
private long emit(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, long 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
private java.nio.ByteBuffer pollNext()
-
nextPartHeaders
private java.nio.ByteBuffer nextPartHeaders()
-
subscribeToPart
private boolean subscribeToPart(Part part)
-
-