This class describes an actor. More...
#include <actor.hpp>
Public Member Functions | |
const volatile ActorState & | state () const |
Get the current actor state. | |
bool | setState (ActorState oldState, ActorState nextState) |
Atomically set the state of this actor to nextState . | |
Actor (ActorState initialState=UNINITIALIZED, bool trapExit=false) | |
Constructor. | |
void | resume (Context *schedulerCtx) |
Resumes this actor after the last call to yield(). | |
bool | isBlocked () const |
Returns state == BLOCKED. | |
bool | isDetached () const |
Returns state == DETACHED. | |
virtual bool | backlinkTo (ActorRef &who) |
Link who to this actor and return true on success. | |
virtual void | linkTo (const ActorRef &who) |
Link who to this actor. | |
virtual void | enqueue (const Message &msg) |
Enqueues msg to the actors mailbox. | |
Protected Member Functions | |
bool | filterTimeoutEvents (const Message &msg) |
Implementation of a TimeoutEvent filter. | |
virtual bool | filterIncomingMessage (const Message &msg) |
Override this method if you want to filter incoming messages before they are enqueued to the mailbox. | |
void | doExit (boost::int32_t reason) |
Set exitReason to reason and perform some cleanup code. | |
void | normalExit () |
Equal to doExit(exit_reasons::NORMAL_EXIT) . | |
Message | lastReceivedMessage () const |
Get the last received message. | |
void | forwardLastReceivedMessage (ActorRef &whom) const |
Forwards the last received message to whom . | |
virtual void | act ()=0 |
Override this method with your actors behavior. | |
virtual void | onExit () |
Override this method if you want to run some cleanup code before your actor gets deleted. | |
void | yield (ActorState mYieldState=READY) |
Relinquish control to the scheduler. | |
void | receiveAndInvoke (Invoker &imp) |
Receive a message that matches one of the pattern of imp and invoke the corresponding callback. | |
template<class CaseClass > | |
void | waitFor () |
Wait until a message of the type CaseClass was received. | |
bool | tryReceiveAndInvoke (Invoker &imp) |
Try to receive a message that matches one of the pattern of imp and invoke the corresponding callback. | |
bool | receiveAndInvokeWithin (Invoker &imp, boost::uint16_t msTimeout) |
Try to receive a message within msTimeout ms that matches one of the pattern imp . | |
Message | receive () |
Receive a message and return it. | |
bool | tryReceive (Message &storage) |
Try to dequeue a message from the mailbox. | |
bool | receiveWithin (Message &storage, boost::uint16_t msTimeout) |
Try to receive a message within msTimeout . | |
void | reply (const Any &val1) |
Reply to the last received message. | |
template<class A > | |
ActorRef | spawn_link () |
Spawn an actor and link to it. | |
void | futureMessage (boost::uint32_t msTimeout, const Any &v1) |
Send a message to this actor after msTimeout milliseconds. | |
Related Functions | |
(Note that these are not member functions.) | |
template<class A > | |
ActorRef | spawn () |
Spawn a new instance of T. |
This class describes an actor.
Definition at line 118 of file actor.hpp.
acedia::Actor::Actor | ( | ActorState | initialState = UNINITIALIZED , |
|
bool | trapExit = false | |||
) |
bool acedia::Actor::backlinkTo | ( | ActorRef & | who | ) | [virtual] |
Link who
to this actor and return true on success.
If you call backlinkTo on an exited actor that actor will return true but calls linkExited on who
.
who | the actor which asks for a backlink |
Implements acedia::AbstractActor.
bool acedia::Actor::filterIncomingMessage | ( | const Message & | msg | ) | [protected, virtual] |
Override this method if you want to filter incoming messages before they are enqueued to the mailbox.
Be very careful if you override this method in your subclass! The default implementation calls filterTimeoutEvents and filters AddRemoteLink messages.
msg
was filtered and should not be enqueued to the mailbox; otherwise false bool acedia::Actor::filterTimeoutEvents | ( | const Message & | msg | ) | [protected] |
void acedia::Actor::forwardLastReceivedMessage | ( | ActorRef & | whom | ) | const [inline, protected] |
Forwards the last received message to whom
.
Equal to: forward(lastReceivedMessage(), whom
);
Message acedia::Actor::lastReceivedMessage | ( | ) | const [inline, protected] |
void acedia::Actor::onExit | ( | ) | [protected, virtual] |
Override this method if you want to run some cleanup code before your actor gets deleted.
This method is called just before the actor gets deleted and _after_ all links are notified.
This method is intended for cleanup code, e.g. to close all open connections or files.
The default implementation does nothing.
bool acedia::Actor::receiveAndInvokeWithin | ( | Invoker & | imp, | |
boost::uint16_t | msTimeout | |||
) | [protected] |
bool acedia::Actor::receiveWithin | ( | Message & | storage, | |
boost::uint16_t | msTimeout | |||
) | [protected] |
void acedia::Actor::reply | ( | const Any & | val1 | ) | [protected] |
Reply to the last received message.
Equal to send(lastReceivedMessage().sender(), ...)
.
bool acedia::Actor::setState | ( | ActorState | oldState, | |
ActorState | nextState | |||
) |
ActorRef acedia::Actor::spawn_link | ( | ) | [inline, protected] |
bool acedia::Actor::tryReceive | ( | Message & | storage | ) | [protected] |
bool acedia::Actor::tryReceiveAndInvoke | ( | Invoker & | imp | ) | [protected] |
Try to receive a message that matches one of the pattern of imp
and invoke the corresponding callback.
This member function does not block or wait and returns false if there was no matching message in the mailbox.
void acedia::Actor::yield | ( | ActorState | mYieldState = READY |
) | [protected] |
ActorRef spawn | ( | ) | [related] |
Spawn a new instance of T.
Spawn a new instance of T which must provide a no-arg constructor and return an ActorRef to it.
Definition at line 178 of file acedia.hpp.