public final class Channels
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Channels.OverflowPolicy
Determines how a channel behaves when its internal buffer (if it has one) overflows.
|
| Modifier and Type | Method and Description |
|---|---|
static <T> ReceivePort<T> |
emptyReceivePort()
Returns an empty
ReceivePort. |
static <S,T> void |
fiberTransform(FiberFactory fiberFactory,
ReceivePort<S> in,
SendPort<T> out,
SuspendableAction2<? extends ReceivePort<? super S>,? extends SendPort<? extends T>> transformer)
Spawns a fiber that transforms values read from the
in channel and writes values to the out channel. |
static <S,T> void |
fiberTransform(ReceivePort<S> in,
SendPort<T> out,
SuspendableAction2<? extends ReceivePort<? super S>,? extends SendPort<? extends T>> transformer)
Spawns a fiber that transforms values read from the
in channel and writes values to the out channel. |
static <M> ReceivePort<M> |
filter(ReceivePort<M> channel,
com.google.common.base.Predicate<M> pred)
Returns a
ReceivePort that filters messages that satisfy a predicate from a given channel. |
static <M> SendPort<M> |
filterSend(SendPort<M> channel,
com.google.common.base.Predicate<M> pred)
Returns a
SendPort that filters messages that satisfy a predicate before sending to a given channel. |
static <S,T> ReceivePort<T> |
flatMap(ReceivePort<S> channel,
com.google.common.base.Function<S,ReceivePort<T>> f)
Returns a
ReceivePort that receives messages that are transformed by a given flat-mapping function from a given channel. |
static <S,T> SendPort<S> |
flatMapSend(Channel<S> pipe,
SendPort<T> channel,
com.google.common.base.Function<S,ReceivePort<T>> f) |
static <S,T> SendPort<S> |
flatMapSend(FiberFactory fiberFactory,
Channel<S> pipe,
SendPort<T> channel,
com.google.common.base.Function<S,ReceivePort<T>> f)
Returns a
SendPort that sends messages that are transformed by a given flat-mapping function into a given channel. |
static <T> void |
forEach(ReceivePort<T> channel,
SuspendableAction1<T> action)
Performs the given action on each message received by the given channel.
|
static <M> ReceivePort<M> |
group(java.util.Collection<? extends ReceivePort<? extends M>> channels)
Returns a
ReceivePort that receives messages from a set of channels. |
static <M> ReceivePort<M> |
group(ReceivePort<? extends M>... channels)
Returns a
ReceivePort that receives messages from a set of channels. |
static boolean |
isTickerChannel(ReceivePort<?> channel)
Tests whether a given channel is a ticker channel, namely a channel with a bounded buffer
and an
overflow policy of DISPLACE. |
static <S,T> ReceivePort<T> |
map(ReceivePort<S> channel,
com.google.common.base.Function<S,T> f)
Returns a
ReceivePort that receives messages that are transformed by a given mapping function from a given channel. |
static <T> ReceivePort<T> |
mapErrors(ReceivePort<T> channel,
com.google.common.base.Function<java.lang.Exception,T> f)
Returns a
ReceivePort that maps exceptions thrown by the underlying channel
(by channel transformations, or as a result of SendPort.close(Throwable) )
into messages. |
static <S,T> SendPort<S> |
mapSend(SendPort<T> channel,
com.google.common.base.Function<S,T> f)
Returns a
SendPort that transforms messages by applying a given mapping function before sending them to a given channel. |
static <M> Mix<? extends M> |
mix(java.util.Collection<? extends ReceivePort<? extends M>> channels)
Returns a
Mix that receives messages from a set of channels. |
static <M> Mix<? extends M> |
mix(ReceivePort<? extends M>... channels)
Returns a
Mix that receives messages from a set of channels. |
static <Message> Channel<Message> |
newChannel(int bufferSize)
Creates a new channel with the given mailbox size with other properties set to their default values.
|
static <Message> Channel<Message> |
newChannel(int bufferSize,
Channels.OverflowPolicy policy)
Creates a new channel with the given mailbox size and
Channels.OverflowPolicy, with other properties set to their default values. |
static <Message> Channel<Message> |
newChannel(int bufferSize,
Channels.OverflowPolicy policy,
boolean singleProducer,
boolean singleConsumer)
Creates a new channel with the given properties.
|
static DoubleChannel |
newDoubleChannel(int bufferSize)
Creates a new primitive
double channel with the given mailbox size with other properties set to their default values. |
static DoubleChannel |
newDoubleChannel(int bufferSize,
Channels.OverflowPolicy policy)
Creates a new primitive
double channel with the given mailbox size and Channels.OverflowPolicy, with other properties set to their default values. |
static DoubleChannel |
newDoubleChannel(int bufferSize,
Channels.OverflowPolicy policy,
boolean singleProducer,
boolean singleConsumer)
Creates a new primitive
double channel with the given properties. |
static FloatChannel |
newFloatChannel(int bufferSize)
Creates a new primitive
float channel with the given mailbox size with other properties set to their default values. |
static FloatChannel |
newFloatChannel(int bufferSize,
Channels.OverflowPolicy policy)
Creates a new primitive
float channel with the given mailbox size and Channels.OverflowPolicy, with other properties set to their default values. |
static FloatChannel |
newFloatChannel(int bufferSize,
Channels.OverflowPolicy policy,
boolean singleProducer,
boolean singleConsumer)
Creates a new primitive
float channel with the given properties. |
static IntChannel |
newIntChannel(int bufferSize)
Creates a new primitive
int channel with the given mailbox size with other properties set to their default values. |
static IntChannel |
newIntChannel(int bufferSize,
Channels.OverflowPolicy policy)
Creates a new primitive
int channel with the given mailbox size and Channels.OverflowPolicy, with other properties set to their default values. |
static IntChannel |
newIntChannel(int bufferSize,
Channels.OverflowPolicy policy,
boolean singleProducer,
boolean singleConsumer)
Creates a new primitive
int channel with the given properties. |
static LongChannel |
newLongChannel(int bufferSize)
Creates a new primitive
long channel with the given mailbox size with other properties set to their default values. |
static LongChannel |
newLongChannel(int bufferSize,
Channels.OverflowPolicy policy)
Creates a new primitive
long channel with the given mailbox size and Channels.OverflowPolicy, with other properties set to their default values. |
static LongChannel |
newLongChannel(int bufferSize,
Channels.OverflowPolicy policy,
boolean singleProducer,
boolean singleConsumer)
Creates a new primitive
long channel with the given properties. |
static <Message> ReceivePort<Message> |
newTickerConsumerFor(Channel<Message> channel)
Creates a
ReceivePort that can be used to receive messages from a a ticker channel:
a channel of bounded capacity and the DISPLACE overflow policy. |
static DoubleReceivePort |
newTickerConsumerFor(DoubleChannel channel)
Creates a
DoubleReceivePort that can be used to receive messages from a a ticker channel:
a channel of bounded capacity and the DISPLACE overflow policy. |
static FloatReceivePort |
newTickerConsumerFor(FloatChannel channel)
Creates a
FloatReceivePort that can be used to receive messages from a a ticker channel:
a channel of bounded capacity and the DISPLACE overflow policy. |
static IntReceivePort |
newTickerConsumerFor(IntChannel channel)
Creates an
IntReceivePort that can be used to receive messages from a a ticker channel:
a channel of bounded capacity and the DISPLACE overflow policy. |
static LongReceivePort |
newTickerConsumerFor(LongChannel channel)
Creates a
LongReceivePort that can be used to receive messages from a a ticker channel:
a channel of bounded capacity and the DISPLACE overflow policy. |
static <S,T> ReceivePort<T> |
reduce(ReceivePort<S> channel,
Function2<T,S,T> f,
T init)
Returns a
ReceivePort providing messages that are transformed from a given channel by a given reduction function. |
static <S,T> SendPort<S> |
reduceSend(SendPort<T> channel,
Function2<T,S,T> f,
T init)
Returns a
SendPort accepting messages that are transformed by a reduction function. |
static <T> ReceivePort<T> |
singletonReceivePort(T object)
Returns a newly created
ReceivePort that receives a single message: the object given to the function. |
static <T> ReceivePort<T> |
take(ReceivePort<T> channel,
long count)
|
static <T> ReceivePort<T> |
toReceivePort(java.lang.Iterable<T> iterable)
Returns a newly created
ReceivePort that receives all the elements iterated by the iterable. |
static <T> ReceivePort<T> |
toReceivePort(java.util.Iterator<T> iterator)
Returns a newly created
ReceivePort that receives all the elements iterated by the iterator. |
static <M> TransformingReceivePort<M> |
transform(ReceivePort<M> channel)
Returns a
TransformingReceivePort wrapping the given channel, which may be used for functional
transformations. |
static <M> TransformingSendPort<M> |
transformSend(SendPort<M> channel)
Returns a
TransformingSendPort wrapping the given channel, which may be used for functional
transformations. |
static <M> ReceivePort<M> |
zip(java.util.List<? extends ReceivePort<?>> cs,
com.google.common.base.Function<java.lang.Object[],M> f)
Returns a
ReceivePort that combines each vector of messages from a list of channels into a single combined message. |
static <M,S1,S2> ReceivePort<M> |
zip(ReceivePort<S1> c1,
ReceivePort<S2> c2,
Function2<S1,S2,M> f)
Returns a
ReceivePort that combines each vector of messages from a vector of channels into a single combined message. |
static <M,S1,S2,S3> |
zip(ReceivePort<S1> c1,
ReceivePort<S2> c2,
ReceivePort<S3> c3,
Function3<S1,S2,S3,M> f)
Returns a
ReceivePort that combines each vector of messages from a vector of channels into a single combined message. |
static <M,S1,S2,S3,S4> |
zip(ReceivePort<S1> c1,
ReceivePort<S2> c2,
ReceivePort<S3> c3,
ReceivePort<S4> c4,
Function4<S1,S2,S3,S4,M> f)
Returns a
ReceivePort that combines each vector of messages from a vector of channels into a single combined message. |
static <M,S1,S2,S3,S4,S5> |
zip(ReceivePort<S1> c1,
ReceivePort<S2> c2,
ReceivePort<S3> c3,
ReceivePort<S4> c4,
ReceivePort<S5> c5,
Function5<S1,S2,S3,S4,S5,M> f)
Returns a
ReceivePort that combines each vector of messages from a vector of channels into a single combined message. |
public static <Message> Channel<Message> newChannel(int bufferSize, Channels.OverflowPolicy policy, boolean singleProducer, boolean singleConsumer)
IllegalArgumentException if requested:
An unbounded channel ignores its overflow policy as it never overflows.Message - the type of messages that can be sent to this channel.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.policy - the Channels.OverflowPolicy specifying how the channel (if bounded) will behave if its internal buffer overflows.singleProducer - whether the channel will be used by a single producer strand.singleConsumer - whether the channel will be used by a single consumer strand.public static <Message> Channel<Message> newChannel(int bufferSize, Channels.OverflowPolicy policy)
Channels.OverflowPolicy, with other properties set to their default values.
Specifically, singleProducer will be set to false, while singleConsumer will be set to true.Message - the type of messages that can be sent to this channel.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.policy - the Channels.OverflowPolicy specifying how the channel (if bounded) will behave if its internal buffer overflows.newChannel(int, co.paralleluniverse.strands.channels.Channels.OverflowPolicy, boolean, boolean)public static <Message> Channel<Message> newChannel(int bufferSize)
Channels.OverflowPolicy will be set to BLOCK,
singleProducer will be set to false, and singleConsumer will be set to true.Message - the type of messages that can be sent to this channel.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.newChannel(int, co.paralleluniverse.strands.channels.Channels.OverflowPolicy, boolean, boolean)public static IntChannel newIntChannel(int bufferSize, Channels.OverflowPolicy policy, boolean singleProducer, boolean singleConsumer)
int channel with the given properties.
Some combinations of properties are unsupported, and will throw an IllegalArgumentException if requested:
An unbounded channel ignores its overflow policy as it never overflows.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.policy - the Channels.OverflowPolicy specifying how the channel (if bounded) will behave if its internal buffer overflows.singleProducer - whether the channel will be used by a single producer strand.singleConsumer - whether the channel will be used by a single consumer strand. Currently primitive channels only support a single
consumer, so this argument must be set to false.public static IntChannel newIntChannel(int bufferSize, Channels.OverflowPolicy policy)
int channel with the given mailbox size and Channels.OverflowPolicy, with other properties set to their default values.
Specifically, singleProducer will be set to false, while singleConsumer will be set to true.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.policy - the Channels.OverflowPolicy specifying how the channel (if bounded) will behave if its internal buffer overflows.newIntChannel(int, co.paralleluniverse.strands.channels.Channels.OverflowPolicy, boolean, boolean)public static IntChannel newIntChannel(int bufferSize)
int channel with the given mailbox size with other properties set to their default values.
Specifically, the Channels.OverflowPolicy will be set to BLOCK,
singleProducer will be set to false, and singleConsumer will be set to true.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.newIntChannel(int, co.paralleluniverse.strands.channels.Channels.OverflowPolicy, boolean, boolean)public static LongChannel newLongChannel(int bufferSize, Channels.OverflowPolicy policy, boolean singleProducer, boolean singleConsumer)
long channel with the given properties.
Some combinations of properties are unsupported, and will throw an IllegalArgumentException if requested:
An unbounded channel ignores its overflow policy as it never overflows.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.policy - the Channels.OverflowPolicy specifying how the channel (if bounded) will behave if its internal buffer overflows.singleProducer - whether the channel will be used by a single producer strand.singleConsumer - whether the channel will be used by a single consumer strand. Currently primitive channels only support a single
consumer, so this argument must be set to false.public static LongChannel newLongChannel(int bufferSize, Channels.OverflowPolicy policy)
long channel with the given mailbox size and Channels.OverflowPolicy, with other properties set to their default values.
Specifically, singleProducer will be set to false, while singleConsumer will be set to true.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.policy - the Channels.OverflowPolicy specifying how the channel (if bounded) will behave if its internal buffer overflows.newLongChannel(int, co.paralleluniverse.strands.channels.Channels.OverflowPolicy, boolean, boolean)public static LongChannel newLongChannel(int bufferSize)
long channel with the given mailbox size with other properties set to their default values.
Specifically, the Channels.OverflowPolicy will be set to BLOCK,
singleProducer will be set to false, and singleConsumer will be set to true.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.newLongChannel(int, co.paralleluniverse.strands.channels.Channels.OverflowPolicy, boolean, boolean)public static FloatChannel newFloatChannel(int bufferSize, Channels.OverflowPolicy policy, boolean singleProducer, boolean singleConsumer)
float channel with the given properties.
Some combinations of properties are unsupported, and will throw an IllegalArgumentException if requested:
An unbounded channel ignores its overflow policy as it never overflows.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.policy - the Channels.OverflowPolicy specifying how the channel (if bounded) will behave if its internal buffer overflows.singleProducer - whether the channel will be used by a single producer strand.singleConsumer - whether the channel will be used by a single consumer strand. Currently primitive channels only support a single
consumer, so this argument must be set to false.public static FloatChannel newFloatChannel(int bufferSize, Channels.OverflowPolicy policy)
float channel with the given mailbox size and Channels.OverflowPolicy, with other properties set to their default values.
Specifically, singleProducer will be set to false, while singleConsumer will be set to true.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.policy - the Channels.OverflowPolicy specifying how the channel (if bounded) will behave if its internal buffer overflows.newFloatChannel(int, co.paralleluniverse.strands.channels.Channels.OverflowPolicy, boolean, boolean)public static FloatChannel newFloatChannel(int bufferSize)
float channel with the given mailbox size with other properties set to their default values.
Specifically, the Channels.OverflowPolicy will be set to BLOCK,
singleProducer will be set to false, and singleConsumer will be set to true.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.newFloatChannel(int, co.paralleluniverse.strands.channels.Channels.OverflowPolicy, boolean, boolean)public static DoubleChannel newDoubleChannel(int bufferSize, Channels.OverflowPolicy policy, boolean singleProducer, boolean singleConsumer)
double channel with the given properties.
Some combinations of properties are unsupported, and will throw an IllegalArgumentException if requested:
An unbounded channel ignores its overflow policy as it never overflows.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.policy - the Channels.OverflowPolicy specifying how the channel (if bounded) will behave if its internal buffer overflows.singleProducer - whether the channel will be used by a single producer strand.singleConsumer - whether the channel will be used by a single consumer strand. Currently primitive channels only support a single
consumer, so this argument must be set to false.public static DoubleChannel newDoubleChannel(int bufferSize, Channels.OverflowPolicy policy)
double channel with the given mailbox size and Channels.OverflowPolicy, with other properties set to their default values.
Specifically, singleProducer will be set to false, while singleConsumer will be set to true.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.policy - the Channels.OverflowPolicy specifying how the channel (if bounded) will behave if its internal buffer overflows.newDoubleChannel(int, co.paralleluniverse.strands.channels.Channels.OverflowPolicy, boolean, boolean)public static DoubleChannel newDoubleChannel(int bufferSize)
double channel with the given mailbox size with other properties set to their default values.
Specifically, the Channels.OverflowPolicy will be set to BLOCK,
singleProducer will be set to false, and singleConsumer will be set to true.bufferSize - if positive, the number of messages that the channel can hold in an internal buffer;
0 for a transfer channel, i.e. a channel with no internal buffer.
-1 for a channel with an unbounded (infinite) buffer.newDoubleChannel(int, co.paralleluniverse.strands.channels.Channels.OverflowPolicy, boolean, boolean)public static boolean isTickerChannel(ReceivePort<?> channel)
overflow policy of DISPLACE.
A ticker channel can be passed to one of the newTickerConsumerFor methods.public static <Message> ReceivePort<Message> newTickerConsumerFor(Channel<Message> channel)
ReceivePort that can be used to receive messages from a a ticker channel:
a channel of bounded capacity and the DISPLACE overflow policy.
Each ticker consumer will yield monotonic messages, namely no message will be received more than once, and the messages will
be received in the order they're sent, but if the consumer is too slow, messages could be lost.Message - the message typechannel - a channel of bounded capacity and the DISPLACE overflow policy.ReceivePort which provides a view to the supplied ticker channel.public static IntReceivePort newTickerConsumerFor(IntChannel channel)
IntReceivePort that can be used to receive messages from a a ticker channel:
a channel of bounded capacity and the DISPLACE overflow policy.
Each ticker consumer will yield monotonic messages, namely no message will be received more than once, and the messages will
be received in the order they're sent, but if the consumer is too slow, messages could be lost.channel - an int channel of bounded capacity and the DISPLACE overflow policy.IntReceivePort which provides a view to the supplied ticker channel.public static LongReceivePort newTickerConsumerFor(LongChannel channel)
LongReceivePort that can be used to receive messages from a a ticker channel:
a channel of bounded capacity and the DISPLACE overflow policy.
Each ticker consumer will yield monotonic messages, namely no message will be received more than once, and the messages will
be received in the order they're sent, but if the consumer is too slow, messages could be lost.channel - a long channel of bounded capacity and the DISPLACE overflow policy.LongReceivePort which provides a view to the supplied ticker channel.public static FloatReceivePort newTickerConsumerFor(FloatChannel channel)
FloatReceivePort that can be used to receive messages from a a ticker channel:
a channel of bounded capacity and the DISPLACE overflow policy.
Each ticker consumer will yield monotonic messages, namely no message will be received more than once, and the messages will
be received in the order they're sent, but if the consumer is too slow, messages could be lost.channel - a float channel of bounded capacity and the DISPLACE overflow policy.FloatReceivePort which provides a view to the supplied ticker channel.public static DoubleReceivePort newTickerConsumerFor(DoubleChannel channel)
DoubleReceivePort that can be used to receive messages from a a ticker channel:
a channel of bounded capacity and the DISPLACE overflow policy.
Each ticker consumer will yield monotonic messages, namely no message will be received more than once, and the messages will
be received in the order they're sent, but if the consumer is too slow, messages could be lost.channel - a double channel of bounded capacity and the DISPLACE overflow policy.DoubleReceivePort which provides a view to the supplied ticker channel.public static <S,T> void fiberTransform(FiberFactory fiberFactory, ReceivePort<S> in, SendPort<T> out, SuspendableAction2<? extends ReceivePort<? super S>,? extends SendPort<? extends T>> transformer)
in channel and writes values to the out channel.
fiberFactory - will be used to create the fiberin - the input channelout - the output channeltransformer - the transforming operationpublic static <S,T> void fiberTransform(ReceivePort<S> in, SendPort<T> out, SuspendableAction2<? extends ReceivePort<? super S>,? extends SendPort<? extends T>> transformer)
in channel and writes values to the 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.
in - the input channelout - the output channeltransformer - the transforming operationpublic static <M> ReceivePort<M> group(ReceivePort<? extends M>... channels)
ReceivePort that receives messages from a set of channels. Messages from all given channels are funneled into
the returned channel.M - channels - ReceivePort that receives messages from channels.public static <M> ReceivePort<M> group(java.util.Collection<? extends ReceivePort<? extends M>> channels)
ReceivePort that receives messages from a set of channels. Messages from all given channels are funneled into
the returned channel.M - channels - ReceivePort that receives messages from channels.public static <M> Mix<? extends M> mix(ReceivePort<? extends M>... channels)
Mix that receives messages from a set of channels. Messages from all given channels are funneled into
the returned channel.M - channels - ReceivePort that receives messages from channels.public static <M> Mix<? extends M> mix(java.util.Collection<? extends ReceivePort<? extends M>> channels)
Mix that receives messages from a set of channels. Messages from all given channels are funneled into
the returned channel.M - channels - ReceivePort that receives messages from channels.public static <M> ReceivePort<M> filter(ReceivePort<M> channel, com.google.common.base.Predicate<M> pred)
ReceivePort that filters messages that satisfy a predicate from a 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 ReceivePort has the same hashCode as channel and is equal to it.M - the message type.channel - The channel to filterpred - the filtering predicateReceivePort that will receive all those messages from the original channel which satisfy the predicate (i.e. the predicate returns true).public static <S,T> ReceivePort<T> map(ReceivePort<S> channel, com.google.common.base.Function<S,T> f)
ReceivePort that receives messages that are transformed by a given mapping function from a given channel.
The returned ReceivePort has the same hashCode as channel and is equal to it.
S - the message type of the source (given) channel.T - the message type of the target (returned) channel.channel - the channel to transformf - the mapping functionReceivePort that returns messages that are the result of applying the mapping function to the messages received on the given channel.public static <S,T> ReceivePort<T> reduce(ReceivePort<S> channel, Function2<T,S,T> f, T init)
ReceivePort providing messages that are transformed from a given channel by a given reduction function.
The returned ReceivePort has the same hashCode as channel and is equal to it.S - The message type of the source (given) channel.T - The message type of the target (returned) channel.channel - The channel to transform.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 static <T> ReceivePort<T> mapErrors(ReceivePort<T> channel, com.google.common.base.Function<java.lang.Exception,T> f)
ReceivePort that maps exceptions thrown by the underlying channel
(by channel transformations, or as a result of SendPort.close(Throwable) )
into messages.
The returned ReceivePort has the same hashCode as channel and is equal to it.
T - the message type of the target (returned) channel.channel - the channel to transformf - the exception mapping functionpublic static <S,T> ReceivePort<T> flatMap(ReceivePort<S> channel, com.google.common.base.Function<S,ReceivePort<T>> f)
ReceivePort that receives messages that are transformed by a given flat-mapping function from a given 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 singletonReceivePort. To return a collection,
it can make use of toReceivePort(Iterable). To emit no values, the function can return emptyReceivePort()
or null.
The returned ReceivePort can only be safely used by a single receiver strand.
The returned ReceivePort has the same hashCode as channel and is equal to it.
S - the message type of the source (given) channel.T - the message type of the target (returned) channel.channel - the channel to transformf - the mapping functionReceivePort that returns messages that are the result of applying the mapping function to the messages received on the given channel.public static <T> void forEach(ReceivePort<T> channel, SuspendableAction1<T> action) throws SuspendExecution, java.lang.InterruptedException
channel - the channelaction - the actionsSuspendExecutionjava.lang.InterruptedExceptionpublic static <T> ReceivePort<T> take(ReceivePort<T> channel, long count)
channel - The channel.count - The maximum number of messages extracted from the underlying channel.ReceivePort that can provide at most count messages from channel.public static <M> ReceivePort<M> zip(java.util.List<? extends ReceivePort<?>> cs, com.google.common.base.Function<java.lang.Object[],M> f)
ReceivePort that combines each vector of messages from a list of channels into a single combined message.M - The type of the combined messagef - The combining functioncs - A vector of channelsReceivePortpublic static <M,S1,S2> ReceivePort<M> zip(ReceivePort<S1> c1, ReceivePort<S2> c2, Function2<S1,S2,M> f)
ReceivePort that combines each vector of messages from a vector of channels into a single combined message.M - The type of the combined messagef - The combining functionReceivePortpublic static <M,S1,S2,S3> ReceivePort<M> zip(ReceivePort<S1> c1, ReceivePort<S2> c2, ReceivePort<S3> c3, Function3<S1,S2,S3,M> f)
ReceivePort that combines each vector of messages from a vector of channels into a single combined message.M - The type of the combined messagef - The combining functionReceivePortpublic static <M,S1,S2,S3,S4> ReceivePort<M> zip(ReceivePort<S1> c1, ReceivePort<S2> c2, ReceivePort<S3> c3, ReceivePort<S4> c4, Function4<S1,S2,S3,S4,M> f)
ReceivePort that combines each vector of messages from a vector of channels into a single combined message.M - The type of the combined messagef - The combining functionReceivePortpublic static <M,S1,S2,S3,S4,S5> ReceivePort<M> zip(ReceivePort<S1> c1, ReceivePort<S2> c2, ReceivePort<S3> c3, ReceivePort<S4> c4, ReceivePort<S5> c5, Function5<S1,S2,S3,S4,S5,M> f)
ReceivePort that combines each vector of messages from a vector of channels into a single combined message.M - The type of the combined messagef - The combining functionReceivePortpublic static <M> TransformingReceivePort<M> transform(ReceivePort<M> channel)
TransformingReceivePort wrapping the given channel, which may be used for functional
transformations.public static <M> SendPort<M> filterSend(SendPort<M> channel, com.google.common.base.Predicate<M> pred)
SendPort that filters messages that satisfy a predicate before sending to a given channel.
Messages that don't satisfy the predicate will be silently discarded when sent.
The returned SendPort has the same hashCode as channel and is equal to it.M - the message type.channel - The channel to filterpred - the filtering predicateSendPort that will send only those messages which satisfy the predicate (i.e. the predicate returns true) to the given channel.public static <S,T> SendPort<S> mapSend(SendPort<T> channel, com.google.common.base.Function<S,T> f)
SendPort that transforms messages by applying a given mapping function before sending them to a given channel.
The returned SendPort has the same hashCode as channel and is equal to it.S - the message type of the source (returned) channel.T - the message type of the target (given) channel.channel - the channel to transformf - the mapping functionSendPort that passes messages to the given channel after transforming them by applying the mapping function.public static <S,T> SendPort<S> reduceSend(SendPort<T> channel, Function2<T,S,T> f, T init)
SendPort accepting messages that are transformed by a reduction function.
The returned SendPort has the same hashCode as channel and is equal to it.S - The message type of the source (returned) channel.T - The message type of the target (given) channel.channel - The channel to transform.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 static <S,T> SendPort<S> flatMapSend(FiberFactory fiberFactory, Channel<S> pipe, SendPort<T> channel, com.google.common.base.Function<S,ReceivePort<T>> f)
SendPort that sends messages that are transformed by a given flat-mapping function into a given 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 and sent to the channel.
To return a single value the mapping function can make use of singletonReceivePort. To return a collection,
it can make use of toReceivePort(Iterable). To emit no values, the function can return emptyReceivePort()
or null.
If multiple producers send messages into the channel, the messages from the ReceivePorts returned by the mapping function
may be interleaved with other messages.
The returned SendPort has the same hashCode as channel and is equal to it.S - the message type of the source (given) channel.T - the message type of the target (returned) channel.pipe - an intermediate channel used in the flat-mapping operation. Messages are first sent to this channel before being transformed.channel - the channel to transformf - the mapping functionReceivePort that returns messages that are the result of applying the mapping function to the messages received on the given channel.public static <S,T> SendPort<S> flatMapSend(Channel<S> pipe, SendPort<T> channel, com.google.common.base.Function<S,ReceivePort<T>> f)
public static <M> TransformingSendPort<M> transformSend(SendPort<M> channel)
TransformingSendPort wrapping the given channel, which may be used for functional
transformations.public static <T> ReceivePort<T> emptyReceivePort()
ReceivePort. The port is closed and receives no messages;public static <T> ReceivePort<T> singletonReceivePort(T object)
ReceivePort that receives a single message: the object given to the function.T - object - the single object that will be returned by the ReceivePort.public static <T> ReceivePort<T> toReceivePort(java.util.Iterator<T> iterator)
ReceivePort that receives all the elements iterated by the iterator.T - iterator - the iterator to transform into a ReceivePort.public static <T> ReceivePort<T> toReceivePort(java.lang.Iterable<T> iterable)
ReceivePort that receives all the elements iterated by the iterable.T - iterable - the iterable to transform into a ReceivePort.