T - the type of elementsU - the type of the upstream StreamMessage and duplicated StreamMessagespublic abstract class AbstractStreamMessageDuplicator<T,U extends StreamMessage<T>> extends Object implements SafeCloseable
StreamMessage multiple times by duplicating the stream.
Only one subscriber can subscribe other stream messages such as DefaultStreamMessage,
DeferredStreamMessage, etc.
This factory is wrapping one of those StreamMessages and spawns duplicated stream messages
which are created using duplicateStream() and subscribed
by subscribers one by one.
The published elements can be shared across Subscribers, if you subscribe with the
SubscriptionOption.WITH_POOLED_OBJECTS, so do not manipulate the
data unless you copy them.
This factory has to be closed by close() when
you do not need the contents anymore, otherwise memory leak might happen.
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractStreamMessageDuplicator(U upstream,
SignalLengthGetter<? super T> signalLengthGetter,
io.netty.util.concurrent.EventExecutor executor,
long maxSignalLength)
Creates a new instance which subscribes to the specified upstream
StreamMessage and
publishes to multiple subscribers. |
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
Closes this duplicator and aborts all stream messages returned by
duplicateStream(). |
void |
abort(Throwable cause)
Closes this duplicator and aborts all stream messages returned by
duplicateStream()
with the specified Throwable. |
void |
close()
Closes this duplicator and prevents it from further duplication.
|
StreamMessage<T> |
duplicateStream()
Creates a new
StreamMessage that duplicates the upstream StreamMessage specified when
creating this duplicator. |
StreamMessage<T> |
duplicateStream(boolean lastStream)
Creates a new
StreamMessage that duplicates the upstream StreamMessage specified when
creating this duplicator. |
protected io.netty.util.concurrent.EventExecutor |
duplicatorExecutor()
Returns the default
EventExecutor which will be used when a user subscribes to a child
stream using StreamMessage.subscribe(Subscriber, SubscriptionOption...). |
protected AbstractStreamMessageDuplicator(U upstream, SignalLengthGetter<? super T> signalLengthGetter, @Nullable io.netty.util.concurrent.EventExecutor executor, long maxSignalLength)
StreamMessage and
publishes to multiple subscribers.upstream - the StreamMessage who will publish data to subscriberssignalLengthGetter - the signal length getter that produces the length of signalsexecutor - the executor to use for upstream signalsmaxSignalLength - the maximum length of signals. 0 disables the length limitpublic StreamMessage<T> duplicateStream()
StreamMessage that duplicates the upstream StreamMessage specified when
creating this duplicator.public StreamMessage<T> duplicateStream(boolean lastStream)
StreamMessage that duplicates the upstream StreamMessage specified when
creating this duplicator.lastStream - whether to prevent further duplicationprotected io.netty.util.concurrent.EventExecutor duplicatorExecutor()
EventExecutor which will be used when a user subscribes to a child
stream using StreamMessage.subscribe(Subscriber, SubscriptionOption...).public void close()
duplicateStream() will raise an IllegalStateException after
this method is invoked. Note that the previously duplicated streams
will not be closed but will continue publishing data until the upstream StreamMessage
is closed. All the data published from the upstream StreamMessage are cleaned up when
all duplicated streams are complete.close in interface SafeCloseableclose in interface AutoCloseablepublic void abort()
duplicateStream().
This will also clean up the data published from the upstream StreamMessage.public void abort(Throwable cause)
duplicateStream()
with the specified Throwable.
This will also clean up the data published from the upstream StreamMessage.Copyright © 2020 LeanCloud. All rights reserved.