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_INLINE ACE_Process_Strategy< SVC_HANDLER >::ACE_Process_Strategy size_t  n_processes = 1,
ACE_Event_Handler acceptor = 0,
ACE_Reactor = 0,
int  avoid_zombies = 0
 

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.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and ACE_Process_Strategy< SVC_HANDLER >::open().

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_LIB_TEXT ("%p\n"),
00149                 ACE_LIB_TEXT ("ACE_Process_Strategy")));
00150 }

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

Definition at line 1338 of file Strategies_T.cpp.

References ACE_TRACE.

01339 {
01340   ACE_TRACE ("ACE_Process_Strategy<SVC_HANDLER>::~ACE_Process_Strategy");
01341 }


Member Function Documentation

template<class SVC_HANDLER>
int ACE_Process_Strategy< SVC_HANDLER >::activate_svc_handler SVC_HANDLER *  svc_handler,
void *  arg = 0
[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 428 of file Strategies_T.cpp.

References ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TRACE, ACE::fork(), LM_ERROR, and ACE_Reactor::remove_handler().

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

template<class SVC_HANDLER>
void ACE_Process_Strategy< SVC_HANDLER >::dump void   )  const
 

Dump the state of an object.

Reimplemented from ACE_Concurrency_Strategy< SVC_HANDLER >.

Definition at line 1344 of file Strategies_T.cpp.

References ACE_TRACE.

01345 {
01346 #if defined (ACE_HAS_DUMP)
01347   ACE_TRACE ("ACE_Process_Strategy<SVC_HANDLER>::dump");
01348 #endif /* ACE_HAS_DUMP */
01349 }

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

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

Definition at line 413 of file Strategies_T.cpp.

References ACE_TRACE, and ACE_Process_Strategy< SVC_HANDLER >::n_processes_.

Referenced by ACE_Process_Strategy< SVC_HANDLER >::ACE_Process_Strategy().

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


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.

Referenced by ACE_Process_Strategy< SVC_HANDLER >::open().

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:
Generated on Thu Nov 9 11:27:26 2006 for ACE by doxygen 1.3.6