An actor is simply a thread with a mailbox. More...
#include <actor.h>
Public Types | |
typedef Handler::argument_type | Message |
typedef Handler::result_type | Reply |
typedef MailBox< Reply > | ReplyBox |
typedef std::pair< Message, ReplyBox * > | MessageReply |
Public Member Functions | |
Actor (const std::string &name, Handler &handler, size_t delay=2000, size_t max_capacity=0, unsigned int min_debug_level=0, Debugable *debug_master=0) | |
Constructor. | |
~Actor () | |
Destructor. | |
void | request (const Message &m, ReplyBox *r=0) |
Send a request to an actor, with an optional mailbox to which a reply may be sent. | |
int | main () |
The default life of an actor. | |
const std::string & | name () const |
Private Attributes | |
std::string | name_ |
size_t | delay_ |
Handler & | handler_ |
MailBox< MessageReply > | mbox_ |
An actor is simply a thread with a mailbox.
The mailbox is the interface to the thread: whenever a request is made, a message is put in the mailbox, the thread goes to work. If the request includes a return mailbox, the result of the work will be put there (the return mailbox).
The template parameter Handler
should be derived from std::unary_function<Message,Reply>
where Message
is the type of the messages the actor expects in its inbox and Reply
the type of message that the actor will use to reply
typedef Handler::argument_type Dv::Thread::Actor< Handler >::Message |
typedef Handler::result_type Dv::Thread::Actor< Handler >::Reply |
typedef MailBox<Reply> Dv::Thread::Actor< Handler >::ReplyBox |
typedef std::pair<Message,ReplyBox*> Dv::Thread::Actor< Handler >::MessageReply |
Dv::Thread::Actor< Handler >::Actor | ( | const std::string & | name, | |
Handler & | handler, | |||
size_t | delay = 2000 , |
|||
size_t | max_capacity = 0 , |
|||
unsigned int | min_debug_level = 0 , |
|||
Debugable * | debug_master = 0 | |||
) | [inline] |
Constructor.
The constructor also starts the thread.
name | of this actor | |
handler | function this function will be called with a received message as parameter; it is assumed to return a reply if necessary. | |
delay | in millisecs that an actor will wait for a message on an inbox, before giving up (and checking whether it has been killed) | |
max_capacity | of the actor mailbox | |
min_debug_level | ||
debug_master |
References Dv::Thread::Thread::start().
Dv::Thread::Actor< Handler >::~Actor | ( | ) | [inline] |
Destructor.
void Dv::Thread::Actor< Handler >::request | ( | const Message & | m, | |
ReplyBox * | r = 0 | |||
) | [inline] |
Send a request to an actor, with an optional mailbox to which a reply may be sent.
m | request message | |
r | pointer (may be 0) to optional mailbox. If not zero, the actor will put a reply on this mailbox. |
References Dv::Thread::Actor< Handler >::mbox_, and Dv::Thread::MailBox< M >::put().
int Dv::Thread::Actor< Handler >::main | ( | ) | [inline, virtual] |
The default life of an actor.
Reimplemented from Dv::Thread::Thread.
References Dv::Thread::Actor< Handler >::delay_, Dv::Thread::MailBox< M >::get(), Dv::Thread::Actor< Handler >::handler_, Dv::Thread::Thread::killed(), and Dv::Thread::Actor< Handler >::mbox_.
const std::string& Dv::Thread::Actor< Handler >::name | ( | ) | const [inline] |
References Dv::Thread::Actor< Handler >::name_.
std::string Dv::Thread::Actor< Handler >::name_ [private] |
Referenced by Dv::Thread::Actor< Handler >::name().
size_t Dv::Thread::Actor< Handler >::delay_ [private] |
Referenced by Dv::Thread::Actor< Handler >::main().
Handler& Dv::Thread::Actor< Handler >::handler_ [private] |
Referenced by Dv::Thread::Actor< Handler >::main().
MailBox<MessageReply> Dv::Thread::Actor< Handler >::mbox_ [private] |
Referenced by Dv::Thread::Actor< Handler >::main(), and Dv::Thread::Actor< Handler >::request().
dvthread-0.13.4 | [11 December, 2009] |