public class TransformingReceivePort<T> extends DelegatingReceivePort<T>
ReceivePort with additional functional-transform operations, usually wrapping a plain ReceivePort.ReceivePort.EOFExceptiontarget| Modifier and Type | Method and Description |
|---|---|
<U> TransformingReceivePort<U> |
fiberTransform(FiberFactory fiberFactory,
SuspendableAction2<? extends ReceivePort<? super T>,? extends SendPort<? extends U>> transformer,
Channel<U> out)
Spawns a fiber that transforms values read from this channel and writes values to the
out channel. |
<U> TransformingReceivePort<U> |
fiberTransform(SuspendableAction2<? extends ReceivePort<? super T>,? extends SendPort<? extends U>> transformer,
Channel<U> out)
Spawns a fiber that transforms values read from this channel and writes values to the
out channel. |
TransformingReceivePort<T> |
filter(com.google.common.base.Predicate<T> pred)
Returns a
TransformingReceivePort that filters messages that satisfy a predicate from this given channel. |
<U> TransformingReceivePort<U> |
flatMap(com.google.common.base.Function<T,ReceivePort<U>> f)
Returns a
TransformingReceivePort that receives messages that are transformed by a given flat-mapping function from this channel. |
void |
forEach(SuspendableAction1<T> action)
Performs the given action on each message received by this channel.
|
<U> TransformingReceivePort<U> |
map(com.google.common.base.Function<T,U> f)
Returns a
TransformingReceivePort that receives messages that are transformed by a given mapping function from this channel. |
<U> TransformingReceivePort<U> |
reduce(Function2<U,T,U> f,
U init)
Returns a
TransformingReceivePort from which receiving messages that are transformed from a given channel by a given reduction function. |
TransformingReceivePort<T> |
take(long count)
Returns a
TakeReceivePort that can provide at most count messages from the underlying channel. |
close, equals, hashCode, isClosed, receive, receive, receive, toString, tryReceivepublic TransformingReceivePort<T> filter(com.google.common.base.Predicate<T> pred)
TransformingReceivePort that filters messages that satisfy a predicate from this given channel.
All messages (even those not satisfying the predicate) will be consumed from the original channel; those that don't satisfy the predicate will be silently discarded.
The returned TransformingReceivePort has the same hashCode as channel and is equal to it.pred - the filtering predicateTransformingReceivePort that will receive all those messages from the original channel which satisfy the predicate (i.e. the predicate returns true).public <U> TransformingReceivePort<U> map(com.google.common.base.Function<T,U> f)
TransformingReceivePort that receives messages that are transformed by a given mapping function from this channel.
The returned TransformingReceivePort has the same hashCode as channel and is equal to it.
f - the mapping functionTransformingReceivePort that returns messages that are the result of applying the mapping function to the messages received on the given channel.public <U> TransformingReceivePort<U> reduce(Function2<U,T,U> f, U init)
TransformingReceivePort from which receiving messages that are transformed from a given channel by a given reduction function.
The returned TransformingReceivePort has the same hashCode as channel and is equal to it.f - The reduction function.init - The initial input to the reduction function.ReceivePort that returns messages that are the result of applying the reduction function to the messages received on the given channel.public <U> TransformingReceivePort<U> flatMap(com.google.common.base.Function<T,ReceivePort<U>> f)
TransformingReceivePort that receives messages that are transformed by a given flat-mapping function from this channel.
Unlike map, the mapping function does not returns a single output message for every input message, but
a new ReceivePort. All the returned ports are concatenated into a single ReceivePort that receives the messages received by all
the ports in order.
To return a single value the mapping function can make use of Channels.singletonReceivePort(Object). To return a collection,
it can make use of Channels.toReceivePort(Iterable). To emit no values, the function can return Channels.emptyReceivePort()
or null.
The returned TransformingReceivePort can only be safely used by a single receiver strand.
The returned TransformingReceivePort has the same hashCode as channel and is equal to it.
f - the mapping functionTransformingReceivePort that returns messages that are the result of applying the mapping function to the messages received on the given channel.public TransformingReceivePort<T> take(long count)
TakeReceivePort that can provide at most count messages from the underlying channel.
The returned TransformingReceivePort has the same hashCode as channel and is equal to it.
count - The maximum number of messages extracted from the underlying channel.public <U> TransformingReceivePort<U> fiberTransform(SuspendableAction2<? extends ReceivePort<? super T>,? extends SendPort<? extends U>> transformer, Channel<U> out)
out channel.
When the transformation terminates. the output channel is automatically closed. If the transformation terminates abnormally
(throws an exception), the output channel is closed with that exception.
out - the output channeltransformer - the transforming operationTransformingReceivePort wrapping the out channel.public <U> TransformingReceivePort<U> fiberTransform(FiberFactory fiberFactory, SuspendableAction2<? extends ReceivePort<? super T>,? extends SendPort<? extends U>> transformer, Channel<U> out)
out channel.
When the transformation terminates. the output channel is automatically closed. If the transformation terminates abnormally
(throws an exception), the output channel is closed with that exception.
fiberFactory - will be used to create the fiberout - the output channeltransformer - the transforming operationTransformingReceivePort wrapping the out channel.public void forEach(SuspendableAction1<T> action) throws SuspendExecution, java.lang.InterruptedException
action - SuspendExecutionjava.lang.InterruptedException