Class BasicActor<Message,V>
- java.lang.Object
-
- co.paralleluniverse.actors.ActorImpl<Message>
-
- co.paralleluniverse.actors.Actor<Message,V>
-
- co.paralleluniverse.actors.BasicActor<Message,V>
-
- All Implemented Interfaces:
ActorBuilder<Message,V>
,Joinable<V>
,Port<Message>
,PortAutoCloseable
,ReceivePort<Message>
,Stranded
,SuspendableCallable<V>
,java.io.Serializable
,java.lang.AutoCloseable
public abstract class BasicActor<Message,V> extends Actor<Message,V>
A subclass ofActor
that provides selective receive capabilities.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class co.paralleluniverse.actors.ActorImpl
ActorImpl.ActorLifecycleListener
-
Nested classes/interfaces inherited from interface co.paralleluniverse.strands.channels.ReceivePort
ReceivePort.EOFException
-
-
Field Summary
-
Fields inherited from class co.paralleluniverse.actors.ActorImpl
flightRecorder, ref
-
-
Constructor Summary
Constructors Constructor Description BasicActor()
Creates a new unnamed actor.BasicActor(MailboxConfig mailboxConfig)
Creates a new, unnamed actor.BasicActor(Strand strand, MailboxConfig mailboxConfig)
BasicActor(Strand strand, java.lang.String name, MailboxConfig mailboxConfig)
BasicActor(java.lang.String name)
Creates a new actor.BasicActor(java.lang.String name, MailboxConfig mailboxConfig)
Creates a new actor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getName()
Returns this actor's name.protected java.lang.Object
readResolve()
<T> T
receive(long timeout, java.util.concurrent.TimeUnit unit, MessageProcessor<? super Message,T> proc)
Performs a selective receive.<M extends Message>
Mreceive(long timeout, java.util.concurrent.TimeUnit unit, java.lang.Class<M> type)
Performs a selective receive based on type.<T> T
receive(MessageProcessor<? super Message,T> proc)
Performs a selective receive.<T> T
receive(Timeout timeout, MessageProcessor<? super Message,T> proc)
Performs a selective receive.<M extends Message>
Mreceive(Timeout timeout, java.lang.Class<M> type)
Performs a selective receive based on type.<M extends Message>
Mreceive(java.lang.Class<M> type)
Performs a selective receive based on type.<T> T
tryReceive(MessageProcessor<? super Message,T> proc)
Tries to perform a selective receive.<M extends Message>
MtryReceive(java.lang.Class<M> type)
Tries to performs a selective receive based on type.-
Methods inherited from class co.paralleluniverse.actors.Actor
addLifecycleListener, build, checkCodeSwap, checkThrownIn, close, currentActor, doRun, filterMessage, get, get, getActor, getDeathCause, getMonitor, getQueueLength, getStrand, handleLifecycleMessage, hire, hire, internalSend, internalSendNonSuspendable, interrupt, isClosed, isDone, isInActor, isRegistered, isStarted, join, join, link, linked, mailbox, makeRef, migrate, migrateAndRestart, monitor, monitorAddDeath, monitorAddMessage, monitorResetSkippedMessages, monitorSkippedMessage, newActor, newActor, onCodeChange, receive, receive, receive, ref, register, register, reinstantiate, removeLifecycleListener, removeObserverListeners, run, self, sendSync, setForwardWatch, setMonitor, setName, setStrand, spawn, spawn, spawn, spawnThread, start, stopMonitor, throwIn, toString, tryReceive, trySend, unlink, unlinked, unregister, unwatch, verifyInActor, verifyOnActorStrand, watch, writeReplace
-
Methods inherited from class co.paralleluniverse.actors.ActorImpl
close, getLifecycleListener, getMailbox, isRecordingLevel, record, record, record, record, record, record, record, sendOrInterrupt
-
-
-
-
Constructor Detail
-
BasicActor
public BasicActor(java.lang.String name, MailboxConfig mailboxConfig)
Creates a new actor.- Parameters:
name
- the actor name (may benull
).mailboxConfig
- the actor's mailbox settings; ifnull
, the default config - unbounded mailbox - will be used.
-
BasicActor
public BasicActor(MailboxConfig mailboxConfig)
Creates a new, unnamed actor.- Parameters:
mailboxConfig
- the actor's mailbox settings; ifnull
, the default config - unbounded mailbox - will be used.
-
BasicActor
public BasicActor(java.lang.String name)
Creates a new actor. The default mailbox config - unbounded mailbox - will be used.- Parameters:
name
- the actor name (may benull
).
-
BasicActor
public BasicActor()
Creates a new unnamed actor.
-
BasicActor
public BasicActor(Strand strand, java.lang.String name, MailboxConfig mailboxConfig)
-
BasicActor
public BasicActor(Strand strand, MailboxConfig mailboxConfig)
-
-
Method Detail
-
receive
public final <T> T receive(MessageProcessor<? super Message,T> proc) throws SuspendExecution, java.lang.InterruptedException
Performs a selective receive. This method blocks until a message that isselected
by the givenMessageProcessor
is available in the mailbox, and returns the value returned byMessageProcessor.process
.Messages that are not selected, are temporarily skipped. They will remain in the mailbox until another call to receive (selective or non-selective) retrieves them.
- Type Parameters:
T
- The type of the returned value- Parameters:
proc
- performs the selection.- Returns:
- The non-null value returned by
MessageProcessor.process
- Throws:
java.lang.InterruptedException
SuspendExecution
-
receive
public final <T> T receive(long timeout, java.util.concurrent.TimeUnit unit, MessageProcessor<? super Message,T> proc) throws java.util.concurrent.TimeoutException, SuspendExecution, java.lang.InterruptedException
Performs a selective receive. This method blocks (but for no longer than the given timeout) until a message that isselected
by the givenMessageProcessor
is available in the mailbox, and returns the value returned byMessageProcessor.process
. If the given timeout expires, this method returnsnull
.Messages that are not selected, are temporarily skipped. They will remain in the mailbox until another call to receive (selective or non-selective) retrieves them.
- Type Parameters:
T
- The type of the returned value- Parameters:
timeout
- the duration to wait for a matching message to arrive.unit
- timeout's time unit.proc
- performs the selection.- Returns:
- The non-null value returned by
MessageProcessor.process
, ornull
if the timeout expired. - Throws:
java.lang.InterruptedException
java.util.concurrent.TimeoutException
SuspendExecution
-
receive
public final <T> T receive(Timeout timeout, MessageProcessor<? super Message,T> proc) throws java.util.concurrent.TimeoutException, SuspendExecution, java.lang.InterruptedException
Performs a selective receive. This method blocks (but for no longer than the given timeout) until a message that isselected
by the givenMessageProcessor
is available in the mailbox, and returns the value returned byMessageProcessor.process
. If the given timeout expires, this method returnsnull
.Messages that are not selected, are temporarily skipped. They will remain in the mailbox until another call to receive (selective or non-selective) retrieves them.
- Type Parameters:
T
- The type of the returned value- Parameters:
timeout
- the method will not block for longer than the amount remaining in theTimeout
proc
- performs the selection.- Returns:
- The non-null value returned by
MessageProcessor.process
, ornull
if the timeout expired. - Throws:
java.lang.InterruptedException
java.util.concurrent.TimeoutException
SuspendExecution
-
tryReceive
public final <T> T tryReceive(MessageProcessor<? super Message,T> proc)
Tries to perform a selective receive. If a messageselected
by the givenMessageProcessor
is immediately available in the mailbox, returns the value returned byMessageProcessor.process
. This method never blocks.Messages that are not selected, are temporarily skipped. They will remain in the mailbox until another call to receive (selective or non-selective) retrieves them.
- Type Parameters:
T
- The type of the returned value- Parameters:
proc
- performs the selection.- Returns:
- The non-null value returned by
MessageProcessor.process
, ornull
if no message was slected.
-
receive
public final <M extends Message> M receive(java.lang.Class<M> type) throws SuspendExecution, java.lang.InterruptedException
Performs a selective receive based on type. This method blocks until a message of the given type is available in the mailbox, and returns it.Messages that are not selected, are temporarily skipped. They will remain in the mailbox until another call to receive (selective or non-selective) retrieves them.
- Parameters:
type
- the type of the messages to select- Returns:
- The next message of the wanted type.
- Throws:
java.lang.InterruptedException
SuspendExecution
-
receive
public final <M extends Message> M receive(long timeout, java.util.concurrent.TimeUnit unit, java.lang.Class<M> type) throws SuspendExecution, java.lang.InterruptedException, java.util.concurrent.TimeoutException
Performs a selective receive based on type. This method blocks (but for no longer than the given timeout) until a message of the given type is available in the mailbox, and returns it. If the given timeout expires, this method returnsnull
.Messages that are not selected, are temporarily skipped. They will remain in the mailbox until another call to receive (selective or non-selective) retrieves them.
- Parameters:
timeout
- the duration to wait for a matching message to arrive.unit
- timeout's time unit.type
- the type of the messages to select- Returns:
- The next message of the wanted type, or
null
if the timeout expires. - Throws:
SuspendExecution
java.lang.InterruptedException
java.util.concurrent.TimeoutException
-
receive
public final <M extends Message> M receive(Timeout timeout, java.lang.Class<M> type) throws SuspendExecution, java.lang.InterruptedException, java.util.concurrent.TimeoutException
Performs a selective receive based on type. This method blocks (but for no longer than the given timeout) until a message of the given type is available in the mailbox, and returns it. If the given timeout expires, this method returnsnull
.Messages that are not selected, are temporarily skipped. They will remain in the mailbox until another call to receive (selective or non-selective) retrieves them.
- Parameters:
timeout
- the method will not block for longer than the amount remaining in theTimeout
type
- the type of the messages to select- Returns:
- The next message of the wanted type, or
null
if the timeout expires. - Throws:
SuspendExecution
java.lang.InterruptedException
java.util.concurrent.TimeoutException
-
tryReceive
public final <M extends Message> M tryReceive(java.lang.Class<M> type)
Tries to performs a selective receive based on type. If a message of the given type is immediately found in the mailbox, it is returned. Otherwise this method returnsnull
. This method never blocks.Messages that are not selected, are temporarily skipped. They will remain in the mailbox until another call to receive (selective or non-selective) retrieves them.
- Type Parameters:
M
- The type of the returned message- Parameters:
type
- the type of the messages to select- Returns:
- The next message of the wanted type if immediately found;
null
otherwise.
-
getName
public final java.lang.String getName()
Description copied from class:Actor
Returns this actor's name.
-
readResolve
protected java.lang.Object readResolve() throws java.io.ObjectStreamException
- Overrides:
readResolve
in classActor<Message,V>
- Throws:
java.io.ObjectStreamException
-
-