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.String
boundary
private static int
CANCELLED
private static java.util.concurrent.Flow.Subscriber<java.nio.ByteBuffer>
CANCELLED_SUBSCRIBER
private boolean
complete
private long
demand
private static java.lang.invoke.VarHandle
DEMAND
private java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer>
downstream
private java.util.concurrent.Executor
executor
private static int
KEEP_ALIVE
private ProgressMonitor
monitor
private static java.lang.invoke.VarHandle
PART_SUBSCRIBER
private int
partIndex
private java.util.List<Part>
parts
private java.util.concurrent.Flow.Subscriber<java.nio.ByteBuffer>
partSubscriber
private static java.lang.invoke.VarHandle
PENDING_ERROR
private java.lang.Throwable
pendingError
private static int
RUN
private int
state
private static java.lang.invoke.VarHandle
STATE
private static int
SUBSCRIBED
(package private) static java.util.concurrent.Executor
SYNC_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 void
abort(boolean flowInterrupted)
Called when the subscription is cancelled.void
cancel()
private void
cancelOnComplete(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)
Calls downstream'sonComplete
after cancelling this subscription.private void
cancelOnError(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, java.lang.Throwable error, boolean flowInterrupted)
Calls downstream'sonError
after cancelling this subscription.private long
emit(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, long emit)
Main method for item emission.private long
getAndAddDemand(java.lang.Object owner, java.lang.invoke.VarHandle demand, long n)
Adds given count to demand not exceedingLong.MAX_VALUE
.private int
getAndBitwiseOrState(int bits)
private boolean
hasPendingErrors()
Returnstrue
if the subscriber is to be completed exceptionally.private boolean
isCancelled()
Returnstrue
if cancelled.private java.nio.ByteBuffer
nextPartHeaders()
private java.nio.ByteBuffer
pollNext()
private java.lang.Throwable
propagateError(java.lang.Throwable error)
Sets pending error or adds new one as suppressed in case of multiple error sources.void
request(long n)
private void
run()
private void
signal()
void
signal(boolean force)
Schedules a signaller task.void
signalError(java.lang.Throwable error)
private boolean
submitOnNext(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, java.nio.ByteBuffer item)
Submits given item to the downstream, returningfalse
and cancelling on failure.private void
subscribeOnDrain(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream)
private boolean
subscribeToPart(Part part)
private long
subtractAndGetDemand(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:
request
in interfacejava.util.concurrent.Flow.Subscription
-
cancel
public final void cancel()
- Specified by:
cancel
in 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.force
tells whether to schedule in case of no demand
-
signalError
public final void signalError(java.lang.Throwable error)
-
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(java.util.concurrent.Flow.Subscriber<? super java.nio.ByteBuffer> downstream, java.lang.Throwable error, boolean flowInterrupted)
Calls downstream'sonError
after cancelling this subscription.flowInterrupted
tells 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'sonComplete
after 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, returningfalse
and 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 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
private java.nio.ByteBuffer pollNext()
-
nextPartHeaders
private java.nio.ByteBuffer nextPartHeaders()
-
subscribeToPart
private boolean subscribeToPart(Part part)
-
-