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 String
private static final int
private static final Flow.Subscriber
<ByteBuffer> private boolean
private long
private static final VarHandle
private final Flow.Subscriber
<? super ByteBuffer> private final Executor
private static final int
private final ProgressMonitor
private static final VarHandle
private int
private Flow.Subscriber
<ByteBuffer> private static final VarHandle
private Throwable
private static final int
private int
private static final VarHandle
private 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 void
abort
(boolean flowInterrupted) Called when the subscription is cancelled.final void
cancel()
private final void
cancelOnComplete
(Flow.Subscriber<? super ByteBuffer> downstream) Calls downstream'sonComplete
after cancelling this subscription.private final void
cancelOnError
(Flow.Subscriber<? super ByteBuffer> downstream, Throwable error, boolean flowInterrupted) Calls downstream'sonError
after cancelling this subscription.private long
emit
(Flow.Subscriber<? super ByteBuffer> downstream, long emit) Main method for item emission.private long
getAndAddDemand
(Object owner, VarHandle demand, long n) Adds given count to demand not exceedingLong.MAX_VALUE
.private int
getAndBitwiseOrState
(int bits) private final boolean
Returnstrue
if the subscriber is to be completed exceptionally.private final boolean
Returnstrue
if cancelled.private ByteBuffer
private ByteBuffer
pollNext()
private Throwable
propagateError
(Throwable error) Sets pending error or adds new one as suppressed in case of multiple error sources.final void
request
(long n) private void
run()
private void
signal()
final void
signal
(boolean force) Schedules a signaller task.final void
signalError
(Throwable error) private final boolean
submitOnNext
(Flow.Subscriber<? super ByteBuffer> downstream, ByteBuffer item) Submits given item to the downstream, returningfalse
and cancelling on failure.private void
subscribeOnDrain
(Flow.Subscriber<? super ByteBuffer> downstream) private boolean
subscribeToPart
(Part part) private long
subtractAndGetDemand
(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:
request
in interfaceFlow.Subscription
-
cancel
public final void cancel()- Specified by:
cancel
in 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.force
tells whether to schedule in case of no demand -
signalError
-
isCancelled
private final boolean isCancelled()Returnstrue
if cancelled.false
result is immediately outdated. -
hasPendingErrors
private final boolean hasPendingErrors()Returnstrue
if the subscriber is to be completed exceptionally.false
result 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'sonError
after cancelling this subscription.flowInterrupted
tells whether the error interrupted the normal flow of signals. -
cancelOnComplete
Calls downstream'sonComplete
after cancelling this subscription. -
submitOnNext
Submits given item to the downstream, returningfalse
and 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 moste
items are emitted to the downstream using {submitOnNext(Flow.Subscriber, Object)} as long as it returnstrue
. The actual number of emitted items is returned, may be0
in 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.flowInterrupted
specifies 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
-