acedia::Actor Class Reference

This class describes an actor. More...

#include <actor.hpp>

Inheritance diagram for acedia::Actor:
acedia::AbstractActor acedia::ReferenceCounted

List of all members.

Public Member Functions

const volatile ActorStatestate () 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.

Detailed Description

This class describes an actor.

Definition at line 118 of file actor.hpp.


Constructor & Destructor Documentation

acedia::Actor::Actor ( ActorState  initialState = UNINITIALIZED,
bool  trapExit = false 
)

Constructor.

Call this constructor in your subclass with trapExit = true to receive Exit messages if a link dies. The default behavior if a link dies is to throw an exception that kills your actor too.

initialState must be READY or DETACHED

Definition at line 537 of file actor.cpp.


Member Function Documentation

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.

Parameters:
who the actor which asks for a backlink

Implements acedia::AbstractActor.

Definition at line 604 of file actor.cpp.

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.

Returns:
true if msg was filtered and should not be enqueued to the mailbox; otherwise false

Definition at line 402 of file actor.cpp.

bool acedia::Actor::filterTimeoutEvents ( const Message msg  )  [protected]

Implementation of a TimeoutEvent filter.

Call this method if you override filterIncomingMessage in your subclass.

Returns:
true if msg containes a TimeoutEvent; otherwise false

Definition at line 370 of file actor.cpp.

void acedia::Actor::forwardLastReceivedMessage ( ActorRef whom  )  const [inline, protected]

Forwards the last received message to whom.

Equal to: forward(lastReceivedMessage(), whom);

Definition at line 227 of file actor.hpp.

Message acedia::Actor::lastReceivedMessage (  )  const [inline, protected]

Get the last received message.

Returns:
the last received message

Definition at line 220 of file actor.hpp.

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.

Definition at line 618 of file actor.cpp.

bool acedia::Actor::receiveAndInvokeWithin ( Invoker &  imp,
boost::uint16_t  msTimeout 
) [protected]

Try to receive a message within msTimeout ms that matches one of the pattern imp.

Returns:
true if a message was received; otherwise false

Definition at line 305 of file actor.cpp.

bool acedia::Actor::receiveWithin ( Message storage,
boost::uint16_t  msTimeout 
) [protected]

Try to receive a message within msTimeout.

Returns:
true if a message was dequeued and stored in storage; otherwise false

Definition at line 130 of file actor.cpp.

void acedia::Actor::reply ( const Any val1  )  [protected]

Reply to the last received message.

Equal to send(lastReceivedMessage().sender(), ...).

Definition at line 53 of file actor.cpp.

bool acedia::Actor::setState ( ActorState  oldState,
ActorState  nextState 
)

Atomically set the state of this actor to nextState.

This method atomically executes the following (pseudo) code:
atomic {
if (state == oldState) { state = nextState; return true; } else return false; }

Returns:
true if the state was changed; otherwise false

Definition at line 211 of file actor.cpp.

template<class A >
ActorRef acedia::Actor::spawn_link (  )  [inline, protected]

Spawn an actor and link to it.

Equal to:
ActorRef a = spawn<...>(...);
link(self(), a);

Definition at line 335 of file actor.hpp.

bool acedia::Actor::tryReceive ( Message storage  )  [protected]

Try to dequeue a message from the mailbox.

Returns:
true if a message was dequeued and stored in storage; otherwise false

Definition at line 77 of file actor.cpp.

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.

Returns:
true if a message was received; otherwise false

Definition at line 101 of file actor.cpp.

void acedia::Actor::yield ( ActorState  mYieldState = READY  )  [protected]

Relinquish control to the scheduler.

Suspends the execution of an actor. Commonly you don't need to call this method. But it might be useful if your actor does a very long computation and you don't want it to become detached.

Definition at line 522 of file actor.cpp.


Friends And Related Function Documentation

template<class A >
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.

Returns:
a reference to the spawned actor

Definition at line 178 of file acedia.hpp.


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.2