Dv::Thread::Actor< Handler > Class Template Reference

An actor is simply a thread with a mailbox. More...

#include <actor.h>

Inheritance diagram for Dv::Thread::Actor< Handler >:
Inheritance graph
[legend]
Collaboration diagram for Dv::Thread::Actor< Handler >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef Handler::argument_type Message
typedef Handler::result_type Reply
typedef MailBox< ReplyReplyBox
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< MessageReplymbox_

Detailed Description

template<typename Handler>
class Dv::Thread::Actor< Handler >

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


Member Typedef Documentation

template<typename Handler >
typedef Handler::argument_type Dv::Thread::Actor< Handler >::Message
template<typename Handler >
typedef Handler::result_type Dv::Thread::Actor< Handler >::Reply
template<typename Handler >
typedef MailBox<Reply> Dv::Thread::Actor< Handler >::ReplyBox
template<typename Handler >
typedef std::pair<Message,ReplyBox*> Dv::Thread::Actor< Handler >::MessageReply

Constructor & Destructor Documentation

template<typename Handler >
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.

Parameters:
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().

template<typename Handler >
Dv::Thread::Actor< Handler >::~Actor (  )  [inline]

Destructor.


Member Function Documentation

template<typename Handler >
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.

Parameters:
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().

template<typename Handler >
int Dv::Thread::Actor< Handler >::main (  )  [inline, virtual]
template<typename Handler >
const std::string& Dv::Thread::Actor< Handler >::name (  )  const [inline]
Returns:
the name of this actor.

References Dv::Thread::Actor< Handler >::name_.


Member Data Documentation

template<typename Handler >
std::string Dv::Thread::Actor< Handler >::name_ [private]
template<typename Handler >
size_t Dv::Thread::Actor< Handler >::delay_ [private]
template<typename Handler >
Handler& Dv::Thread::Actor< Handler >::handler_ [private]
template<typename Handler >
MailBox<MessageReply> Dv::Thread::Actor< Handler >::mbox_ [private]

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

dvthread-0.13.4 [11 December, 2009]