ACE_Process_Strategy< SVC_HANDLER > Class Template Reference

Defines the interface for specifying a concurrency strategy for a SVC_HANDLER based on multiprocessing. More...

#include <Strategies_T.h>

Inheritance diagram for ACE_Process_Strategy< SVC_HANDLER >:
Inheritance graph
[legend]
Collaboration diagram for ACE_Process_Strategy< SVC_HANDLER >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef
ACE_Concurrency_Strategy
< SVC_HANDLER > 
base_type

Public Member Functions

 ACE_Process_Strategy (size_t n_processes=1, ACE_Event_Handler *acceptor=0, ACE_Reactor *=0, int avoid_zombies=0)
virtual int open (size_t n_processes=1, ACE_Event_Handler *acceptor=0, ACE_Reactor *=0, int avoid_zombies=0)
virtual ~ACE_Process_Strategy (void)
virtual int activate_svc_handler (SVC_HANDLER *svc_handler, void *arg=0)
void dump (void) const
 Dump the state of an object.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Protected Types

typedef
ACE_Concurrency_Strategy
< SVC_HANDLER > 
inherited

Protected Attributes

size_t n_processes_
 Number of processes to spawn.
ACE_Event_Handleracceptor_
ACE_Reactorreactor_

Detailed Description

template<class SVC_HANDLER>
class ACE_Process_Strategy< SVC_HANDLER >

Defines the interface for specifying a concurrency strategy for a SVC_HANDLER based on multiprocessing.

This class provides a strategy that manages the creation of processes to handle requests from clients concurrently using a process-per-connection model. It behaves as a "process factory", using ACE::fork() to fork threads "on-demand" to run the service specified by a user-supplied SVC_HANDLER in a separate process.

Definition at line 426 of file Strategies_T.h.


Member Typedef Documentation

template<class SVC_HANDLER >
typedef ACE_Concurrency_Strategy<SVC_HANDLER> ACE_Process_Strategy< SVC_HANDLER >::base_type

Definition at line 431 of file Strategies_T.h.

template<class SVC_HANDLER >
typedef ACE_Concurrency_Strategy<SVC_HANDLER> ACE_Process_Strategy< SVC_HANDLER >::inherited [protected]

Definition at line 468 of file Strategies_T.h.


Constructor & Destructor Documentation

template<class SVC_HANDLER >
ACE_Process_Strategy< SVC_HANDLER >::ACE_Process_Strategy ( size_t  n_processes = 1,
ACE_Event_Handler acceptor = 0,
ACE_Reactor reactor = 0,
int  avoid_zombies = 0 
) [inline]

Initialize the strategy. If avoid_zombies is non-0 then set a flag to ACE::fork() to avoid zombies.

Definition at line 137 of file Strategies_T.inl.

00141 {
00142   ACE_TRACE ("ACE_Process_Strategy<SVC_HANDLER>::ACE_Process_Strategy");
00143   if (this->open (n_processes,
00144                   acceptor,
00145                   reactor,
00146                   avoid_zombies) == -1)
00147     ACE_ERROR ((LM_ERROR,
00148                 ACE_TEXT ("%p\n"),
00149                 ACE_TEXT ("ACE_Process_Strategy")));
00150 }

template<class SVC_HANDLER >
ACE_Process_Strategy< SVC_HANDLER >::~ACE_Process_Strategy ( void   )  [inline, virtual]

Definition at line 1341 of file Strategies_T.cpp.

01342 {
01343   ACE_TRACE ("ACE_Process_Strategy<SVC_HANDLER>::~ACE_Process_Strategy");
01344 }


Member Function Documentation

template<class SVC_HANDLER >
int ACE_Process_Strategy< SVC_HANDLER >::activate_svc_handler ( SVC_HANDLER *  svc_handler,
void *  arg = 0 
) [inline, virtual]

Activate the svc_handler with an appropriate concurrency strategy. This method activates the SVC_HANDLER by first forking and then calling the open() method of the SVC_HANDLER in the child.

Reimplemented from ACE_Concurrency_Strategy< SVC_HANDLER >.

Definition at line 431 of file Strategies_T.cpp.

00433 {
00434   ACE_TRACE ("ACE_Process_Strategy<SVC_HANDLER>::activate_svc_handler");
00435 
00436   // If <flags_> is non-0 then we won't create zombies.
00437   switch (ACE::fork (ACE_TEXT ("child"), this->flags_))
00438     {
00439     case -1:
00440       {
00441         ACE_Errno_Guard error (errno);
00442         svc_handler->destroy ();
00443       }
00444       ACE_ERROR_RETURN ((LM_ERROR,
00445                          ACE_TEXT ("%p\n"),
00446                          ACE_TEXT ("fork")),
00447                         -1);
00448       /* NOTREACHED */
00449     case 0: // In child process.
00450 
00451       // Close down the SOCK_Acceptor's handle since we don't need to
00452       // keep it open.
00453       if (this->acceptor_ != 0)
00454         // Ignore the return value here...
00455         (void) this->reactor_->remove_handler (this->acceptor_,
00456                                                ACE_Event_Handler::ACCEPT_MASK);
00457 
00458       // Call up to our ancestor in the inheritance to do the
00459       // SVC_HANDLER initialization.
00460       return this->inherited::activate_svc_handler (svc_handler, arg);
00461       /* NOTREACHED */
00462     default: // In parent process.
00463       // We need to close down the <SVC_HANDLER> here because it's
00464       // running in the child.
00465       svc_handler->destroy ();
00466       return 0;
00467     }
00468 }

template<class SVC_HANDLER >
void ACE_Process_Strategy< SVC_HANDLER >::dump ( void   )  const [inline]

Dump the state of an object.

Reimplemented from ACE_Concurrency_Strategy< SVC_HANDLER >.

Definition at line 1347 of file Strategies_T.cpp.

01348 {
01349 #if defined (ACE_HAS_DUMP)
01350   ACE_TRACE ("ACE_Process_Strategy<SVC_HANDLER>::dump");
01351 #endif /* ACE_HAS_DUMP */
01352 }

template<class SVC_HANDLER >
int ACE_Process_Strategy< SVC_HANDLER >::open ( size_t  n_processes = 1,
ACE_Event_Handler acceptor = 0,
ACE_Reactor reactor = 0,
int  avoid_zombies = 0 
) [inline, virtual]

Initialize the strategy. If avoid_zombies is non-0 then set a flag to ACE::fork() to avoid zombies.

Definition at line 416 of file Strategies_T.cpp.

00420 {
00421   ACE_TRACE ("ACE_Process_Strategy<SVC_HANDLER>::open");
00422   this->n_processes_ = n_processes;
00423   this->acceptor_ = acceptor;
00424   this->reactor_ = reactor;
00425   this->flags_ = avoid_zombies;
00426 
00427   return 0;
00428 }


Member Data Documentation

template<class SVC_HANDLER >
ACE_Event_Handler* ACE_Process_Strategy< SVC_HANDLER >::acceptor_ [protected]

This is the Acceptor in the parent is listening on. We need to make sure that we remove it from the Reactor and close it down in the child.

Definition at line 478 of file Strategies_T.h.

template<class SVC_HANDLER >
ACE_Process_Strategy< SVC_HANDLER >::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

Reimplemented from ACE_Concurrency_Strategy< SVC_HANDLER >.

Definition at line 465 of file Strategies_T.h.

template<class SVC_HANDLER >
size_t ACE_Process_Strategy< SVC_HANDLER >::n_processes_ [protected]

Number of processes to spawn.

Definition at line 471 of file Strategies_T.h.

template<class SVC_HANDLER >
ACE_Reactor* ACE_Process_Strategy< SVC_HANDLER >::reactor_ [protected]

This is the reactor the child is using in conjunction with the acceptor. We need to remove the acceptor from this reactor in the child.

Definition at line 485 of file Strategies_T.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Sun Nov 22 23:15:50 2009 for ACE by  doxygen 1.6.1