Class MessageSelector<M1,M2>
- java.lang.Object
-
- co.paralleluniverse.actors.behaviors.MessageSelector<M1,M2>
-
- All Implemented Interfaces:
MessageProcessor<java.lang.Object,M2>
public abstract class MessageSelector<M1,M2> extends java.lang.Object implements MessageProcessor<java.lang.Object,M2>
A fluent interface for creatingMessageProcessor
s that select messages matching a few simple criteria.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <M extends FromMessage>
MessageSelector<M,M>from(ActorRef<?> actor)
Creates aMessageProcessor
that selectsFromMessage
s from the given actor.protected abstract boolean
matches(M1 m)
<M extends M1>
MessageSelector<M1,M>ofType(java.lang.Class<M> type)
Selects messages of the given class.M2
process(java.lang.Object m)
An implementation of this method is used to select messages off an actor's queue for the purpose of selective receive.static <M> MessageSelector<java.lang.Object,M>
select()
Creates a newMessageSelector
.<M extends IdMessage>
MessageSelector<M,M>withId(java.lang.Object id)
Returns aMessageSelector
that selectsIdMessage
s with the given id.
-
-
-
Method Detail
-
select
public static <M> MessageSelector<java.lang.Object,M> select()
Creates a newMessageSelector
.- Returns:
- A new
MessageSelector
that selects all messages.
-
ofType
public <M extends M1> MessageSelector<M1,M> ofType(java.lang.Class<M> type)
Selects messages of the given class.- Parameters:
type
- The class of the messages to select.- Returns:
- a new
MessageSelector
that selects messages of the given class.
-
from
public <M extends FromMessage> MessageSelector<M,M> from(ActorRef<?> actor)
Creates aMessageProcessor
that selectsFromMessage
s from the given actor.- Parameters:
actor
- The sender of the message to select (should be equal toFromMessage.getFrom()
)- Returns:
- a new
MessageSelector
that selects messages from the given sender.
-
withId
public <M extends IdMessage> MessageSelector<M,M> withId(java.lang.Object id)
Returns aMessageSelector
that selectsIdMessage
s with the given id.- Parameters:
id
- The id of the message to select (should be equal toIdMessage.getId()
)- Returns:
- a new
MessageSelector
that selects messages from the given id.
-
matches
protected abstract boolean matches(M1 m)
-
process
public final M2 process(java.lang.Object m)
Description copied from interface:MessageProcessor
An implementation of this method is used to select messages off an actor's queue for the purpose of selective receive. If the message is selected (i.e. it should be processed now), then this method should return a non-null value. If the message is to be skipped, this method should returnnull
. The value returned by this method, will be returned by thereceive
method this instance has been passed to.If the message is selected, this method may process it (and may even call
receive
for nested selective receives), or it may choose to return the message and have it processed when it is returned from the enclosingreceive
.- Specified by:
process
in interfaceMessageProcessor<M1,M2>
- Parameters:
m
- The message- Returns:
- A non-null value if the message is selected;
null
if the message is to be skipped.
-
-