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 ofActorthat 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.StringgetName()Returns this actor's name.protected java.lang.ObjectreadResolve()<T> Treceive(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> Treceive(MessageProcessor<? super Message,T> proc)Performs a selective receive.<T> Treceive(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> TtryReceive(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 isselectedby the givenMessageProcessoris 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.InterruptedExceptionSuspendExecution
-
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.InterruptedExceptionPerforms a selective receive. This method blocks (but for no longer than the given timeout) until a message that isselectedby the givenMessageProcessoris 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, ornullif the timeout expired. - Throws:
java.lang.InterruptedExceptionjava.util.concurrent.TimeoutExceptionSuspendExecution
-
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 isselectedby the givenMessageProcessoris 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 theTimeoutproc- performs the selection.- Returns:
- The non-null value returned by
MessageProcessor.process, ornullif the timeout expired. - Throws:
java.lang.InterruptedExceptionjava.util.concurrent.TimeoutExceptionSuspendExecution
-
tryReceive
public final <T> T tryReceive(MessageProcessor<? super Message,T> proc)
Tries to perform a selective receive. If a messageselectedby the givenMessageProcessoris 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, ornullif 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.InterruptedExceptionSuspendExecution
-
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
nullif the timeout expires. - Throws:
SuspendExecutionjava.lang.InterruptedExceptionjava.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 theTimeouttype- the type of the messages to select- Returns:
- The next message of the wanted type, or
nullif the timeout expires. - Throws:
SuspendExecutionjava.lang.InterruptedExceptionjava.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;
nullotherwise.
-
getName
public final java.lang.String getName()
Description copied from class:ActorReturns this actor's name.
-
readResolve
protected java.lang.Object readResolve() throws java.io.ObjectStreamException- Overrides:
readResolvein classActor<Message,V>- Throws:
java.io.ObjectStreamException
-
-