funtik::MultiProcessRpcServer Class Reference
[XML-RPC handling]

multi process handler for RPC requests. More...

#include <mprocess_rpc_server.h>

List of all members.

Public Types

enum  ProcessState { RUN = 1, FINISH = 2 }

Public Member Functions

 MultiProcessRpcServer (unsigned uNumProcess=0, bool bHandleSigchld=true, bool wbxml_mode=false)
 Constructs the rpc server.
 MultiProcessRpcServer (ulxr::Protocol *poProtocol, unsigned uNumProcess, bool bHandleSigchld=true, bool wbxml_mode=false)
 Constructs the rpc server.
virtual ~MultiProcessRpcServer ()
 Destructs the rpc server.
virtual unsigned getNumProcesses () const
 Gets the number of started processes.
virtual bool terminateAllProcess (bool bForce, long lTimeout=3000)
 Terminates all process.
void setMaxNumProcesses (unsigned uNumProcesses)
 Set max number of executed processes.
unsigned getMaxNumProcesses () const
 Get max number of executed processes.
ulxr::DispatchergetDispatcher () const
 Get dispatcher.
void resetDispatcher (ulxr::Protocol *poProtocol=0)
 Reset dispather.
virtual void serverLoop ()
 Start main server loop.
virtual void handleRequest ()
 handle request.
virtual bool waitConnection (bool bInterruptBySig=true)
 wait the connection.
void setState (int iState)
 Set state of process.
void printProcess () const
 print state of all children process.
int getState () const
 Get current state of process.
virtual std::map< pid_t, ProcessContextgetProcInfo () const
 Get current process statistics.
virtual bool waitChildren (long lTimeout=-1) const
 wait finish all child process.

Static Public Member Functions

static void sigchild_handler (int signal)
 The signal handler function.

Protected Member Functions

virtual void doChild ()
 Start child process.
virtual void acceptConnection ()
virtual void storeFuncResult (const ulxr::MethodCall &callMethod, const ulxr::MethodResponse &respMethod) const
 store or print information about result RPC call.
virtual ulxr::MethodCall handleXmlRequest ()
 Read xml query and parse it.
virtual void blockSigchld ()
 Block SIGCHLD.
virtual void unblockSigchld ()
 Unblock SIGCHLD.
virtual void storeProcessData (pid_t pid)
 store information about process.
virtual void sweepProcessData ()
 sweep process table.
virtual void sigchild_register ()
 the register of signal handler function.
virtual void sigchild_unregister ()
 the register of signal handler function.

Protected Attributes

sigaction old_sigchld
unsigned m_maxProcesses
std::auto_ptr< ulxr::Dispatcherm_poDispatcher
int m_iState
bool m_wbxml_mode

Static Protected Attributes

static std::map< pid_t, ProcessContextm_mapProcesses

Private Attributes

bool m_bHandleSigchld

Classes

struct  ProcessContext


Detailed Description

multi process handler for RPC requests.

This create separate process for every request. Have some wrappers for dispatcher methods(example AddMethods).

Definition at line 71 of file mprocess_rpc_server.h.


Member Enumeration Documentation

enum funtik::MultiProcessRpcServer::ProcessState

Enumerator:
RUN 
FINISH 

Definition at line 271 of file mprocess_rpc_server.h.


Constructor & Destructor Documentation

funtik::MultiProcessRpcServer::MultiProcessRpcServer ( unsigned  uNumProcess = 0,
bool  bHandleSigchld = true,
bool  wbxml_mode = false 
)

Constructs the rpc server.

Constructs the rpc server. It is default constructor. NOTE: you must set bHandleSigchld=false only if you handle signals manually.

Parameters:
uNumProcess number of max process
bHandleSigchld true: handle signal sigchild
wbxml_mode true: data is sent as wbxml
See also:
sigchild_handler().

Definition at line 323 of file mprocess_rpc_server.cpp.

References m_bHandleSigchld, m_poDispatcher, m_wbxml_mode, and sigchild_register().

funtik::MultiProcessRpcServer::MultiProcessRpcServer ( ulxr::Protocol poProtocol,
unsigned  uNumProcess,
bool  bHandleSigchld = true,
bool  wbxml_mode = false 
)

Constructs the rpc server.

Constructs the rpc server.

NOTE: you must set bHandleSigchld=false only if you handle signals manually.

Parameters:
poProtocol Protocol object
uNumProcess number of max process
bHandleSigchld true: handle signal sigchild
wbxml_mode true: data is sent as wbxml

Definition at line 336 of file mprocess_rpc_server.cpp.

References m_bHandleSigchld, m_poDispatcher, m_wbxml_mode, and sigchild_register().

funtik::MultiProcessRpcServer::~MultiProcessRpcServer (  )  [virtual]

Destructs the rpc server.

Destructs the rpc server. The all connection will be closed. All children will be killed.

Definition at line 350 of file mprocess_rpc_server.cpp.

References m_bHandleSigchld, sigchild_unregister(), and terminateAllProcess().


Member Function Documentation

unsigned funtik::MultiProcessRpcServer::getNumProcesses (  )  const [virtual]

Gets the number of started processes.

Gets the number of started processes.

Returns:
number of processes

Definition at line 256 of file mprocess_rpc_server.cpp.

References m_mapProcesses.

Referenced by printProcess(), and terminateAllProcess().

bool funtik::MultiProcessRpcServer::terminateAllProcess ( bool  bForce,
long  lTimeout = 3000 
) [virtual]

Terminates all process.

The process only get a signal and must terminate themselves! After this commands the new processes will not created. Future version might include a way to kill the threads with brute force after some grace time.

Parameters:
bForce true if need kill all proccesses, after lTimeout wait.
lTimeout time in ms to wait finished of process .
Returns:
true if all process was finished, else return false.

Definition at line 273 of file mprocess_rpc_server.cpp.

References FINISH, getNumProcesses(), getProcInfo(), sweepProcessData(), and waitChildren().

Referenced by serverLoop(), and ~MultiProcessRpcServer().

void funtik::MultiProcessRpcServer::setMaxNumProcesses ( unsigned  uNumProcesses  ) 

Set max number of executed processes.

Set max number of executed processes.

Parameters:
uNumProcesses 

Definition at line 261 of file mprocess_rpc_server.cpp.

References m_maxProcesses.

unsigned funtik::MultiProcessRpcServer::getMaxNumProcesses (  )  const

Get max number of executed processes.

Get max number of executed processes. If number of executed will be more then generate exception.

Returns:
max number of executed processes.

Definition at line 267 of file mprocess_rpc_server.cpp.

References m_maxProcesses.

ulxr::Dispatcher * funtik::MultiProcessRpcServer::getDispatcher (  )  const

Get dispatcher.

The received dispatcher can be initialized,etc. NOTE: don`t delete received dispatcher manually.

Returns:
pointer to the dispatcher object.

Definition at line 381 of file mprocess_rpc_server.cpp.

References m_poDispatcher.

void funtik::MultiProcessRpcServer::resetDispatcher ( ulxr::Protocol poProtocol = 0  ) 

Reset dispather.

It destroy old dispather and create new,empty dispather.

Parameters:
poProtocol if protocol not 0 then new will be used.

Definition at line 386 of file mprocess_rpc_server.cpp.

References m_poDispatcher.

void funtik::MultiProcessRpcServer::serverLoop (  )  [virtual]

Start main server loop.

The main process function that does the work. If dispatcher don`t set than it generate Exception. serverLoop exit if ServerState = FINISH

Definition at line 244 of file mprocess_rpc_server.cpp.

References handleRequest(), m_iState, RUN, terminateAllProcess(), ULXR_PCHAR, and ULXR_TRACE.

void funtik::MultiProcessRpcServer::sigchild_handler ( int  signal  )  [static]

The signal handler function.

The signal handler function. It is invoke when child finish work.

it wait children (via waitpid) and update inner structures.

WARNING: if you redefine sighchild_handler in children class then you must call MultiProcessRpcServer::sigchild_handler from your SIGCHILD handler.

Parameters:
signal signal number
See also:
sigchild_register().

Definition at line 358 of file mprocess_rpc_server.cpp.

References FINISH, and m_mapProcesses.

Referenced by sigchild_register().

void funtik::MultiProcessRpcServer::handleRequest (  )  [virtual]

handle request.

The child process that does the work. Every child process will started in this function. Exceptions: ulxr::Exception,ulxr::ConnectionException

Definition at line 96 of file mprocess_rpc_server.cpp.

References acceptConnection(), blockSigchld(), doChild(), m_mapProcesses, m_maxProcesses, m_poDispatcher, storeProcessData(), sweepProcessData(), ulxr::SystemError, ULXR_PCHAR, ULXR_TRACE, and unblockSigchld().

Referenced by serverLoop().

bool funtik::MultiProcessRpcServer::waitConnection ( bool  bInterruptBySig = true  )  [virtual]

wait the connection.

It blocked function wait connection and return true if connection received.

Returns:
true if exist validate connection, false if bInterruptBySig is true and received signal.

Definition at line 414 of file mprocess_rpc_server.cpp.

References ulxr::getLastErrorString(), m_poDispatcher, ulxr::SystemError, and ULXR_PCHAR.

void funtik::MultiProcessRpcServer::setState ( int  iState  ) 

Set state of process.

Set state of process.

Parameters:
iState set state.

Definition at line 403 of file mprocess_rpc_server.cpp.

References m_iState.

void funtik::MultiProcessRpcServer::printProcess (  )  const

print state of all children process.

NOTE: Use this function only for tests.

Definition at line 441 of file mprocess_rpc_server.cpp.

References getNumProcesses(), and getProcInfo().

int funtik::MultiProcessRpcServer::getState (  )  const

Get current state of process.

Get current state of process.

Returns:
current state of process.

Definition at line 409 of file mprocess_rpc_server.cpp.

References m_iState.

std::map< pid_t, MultiProcessRpcServer::ProcessContext > funtik::MultiProcessRpcServer::getProcInfo (  )  const [virtual]

Get current process statistics.

Definition at line 520 of file mprocess_rpc_server.cpp.

References m_mapProcesses.

Referenced by printProcess(), and terminateAllProcess().

bool funtik::MultiProcessRpcServer::waitChildren ( long  lTimeout = -1  )  const [virtual]

wait finish all child process.

Parameters:
lTimeout time for wait in miliseconds.
Returns:
true if all processes finished else return false.

Definition at line 525 of file mprocess_rpc_server.cpp.

References ulxr::getLastErrorString(), and ulxr::getLatin1().

Referenced by terminateAllProcess().

void funtik::MultiProcessRpcServer::doChild (  )  [protected, virtual]

Start child process.

The child process that does the work. Every child process will started in this function.

Definition at line 75 of file mprocess_rpc_server.cpp.

References ulxr::Protocol::close(), handleXmlRequest(), ulxr::Protocol::isPersistent(), ulxr::Protocol::isTransmitOnly(), m_poDispatcher, m_wbxml_mode, ulxr::Protocol::sendRpcResponse(), storeFuncResult(), ULXR_PCHAR, and ULXR_TRACE.

Referenced by handleRequest().

void funtik::MultiProcessRpcServer::acceptConnection (  )  [protected, virtual]

Definition at line 160 of file mprocess_rpc_server.cpp.

References m_poDispatcher.

Referenced by handleRequest().

void funtik::MultiProcessRpcServer::storeFuncResult ( const ulxr::MethodCall callMethod,
const ulxr::MethodResponse respMethod 
) const [protected, virtual]

store or print information about result RPC call.

It can be used for store information about call RPC method in log,etc. On default it write info to the console(cout).

Definition at line 573 of file mprocess_rpc_server.cpp.

References ulxr::getLastErrorString(), ulxr::getLatin1(), ulxr::MethodCall::getMethodName(), ulxr::MethodResponse::isOK(), and m_poDispatcher.

Referenced by doChild().

ulxr::MethodCall funtik::MultiProcessRpcServer::handleXmlRequest (  )  [protected, virtual]

Read xml query and parse it.

Definition at line 170 of file mprocess_rpc_server.cpp.

References ulxr::Protocol::ConnBody, ulxr::Protocol::ConnError, ulxr::Protocol::ConnSwitchToBody, ulxr::MethodCallParserBase::getMethodCall(), m_poDispatcher, m_wbxml_mode, ulxr::NotConformingError, ulxr::TransportError, ULXR_DOUT_READ, ULXR_DOUT_XML, ULXR_GET_STRING, ulxr_i18n, ULXR_PCHAR, ULXR_RECV_BUFFER_SIZE, and ULXR_TRACE.

Referenced by doChild().

void funtik::MultiProcessRpcServer::blockSigchld (  )  [protected, virtual]

Block SIGCHLD.

Definition at line 453 of file mprocess_rpc_server.cpp.

References ulxr::getLastErrorString(), and ulxr::getLatin1().

Referenced by handleRequest().

void funtik::MultiProcessRpcServer::unblockSigchld (  )  [protected, virtual]

Unblock SIGCHLD.

NOTE: if SIGCHILD was blocked before call blockSigchld().

See also:
blockSigchld().

Definition at line 484 of file mprocess_rpc_server.cpp.

References ulxr::getLastErrorString(), and ulxr::getLatin1().

Referenced by handleRequest().

void funtik::MultiProcessRpcServer::storeProcessData ( pid_t  pid  )  [protected, virtual]

store information about process.

Definition at line 515 of file mprocess_rpc_server.cpp.

References m_mapProcesses, and RUN.

Referenced by handleRequest().

void funtik::MultiProcessRpcServer::sweepProcessData (  )  [protected, virtual]

sweep process table.

Sweep all complete process.

Definition at line 311 of file mprocess_rpc_server.cpp.

References FINISH, and m_mapProcesses.

Referenced by handleRequest(), and terminateAllProcess().

void funtik::MultiProcessRpcServer::sigchild_register (  )  [protected, virtual]

the register of signal handler function.

See also:
sigchild_handler(),sigchild_unregister().

Definition at line 367 of file mprocess_rpc_server.cpp.

References sigchild_handler().

Referenced by MultiProcessRpcServer().

void funtik::MultiProcessRpcServer::sigchild_unregister (  )  [protected, virtual]

the register of signal handler function.

See also:
sigchild_handler(),sigchild_register().

Definition at line 376 of file mprocess_rpc_server.cpp.

Referenced by ~MultiProcessRpcServer().


Member Data Documentation

struct sigaction funtik::MultiProcessRpcServer::old_sigchld [protected]

Definition at line 348 of file mprocess_rpc_server.h.

unsigned funtik::MultiProcessRpcServer::m_maxProcesses [protected]

Definition at line 351 of file mprocess_rpc_server.h.

Referenced by getMaxNumProcesses(), handleRequest(), and setMaxNumProcesses().

std::map< pid_t, MultiProcessRpcServer::ProcessContext > funtik::MultiProcessRpcServer::m_mapProcesses [static, protected]

Definition at line 352 of file mprocess_rpc_server.h.

Referenced by getNumProcesses(), getProcInfo(), handleRequest(), sigchild_handler(), storeProcessData(), and sweepProcessData().

std::auto_ptr<ulxr::Dispatcher> funtik::MultiProcessRpcServer::m_poDispatcher [protected]

Definition at line 353 of file mprocess_rpc_server.h.

Referenced by acceptConnection(), doChild(), getDispatcher(), handleRequest(), handleXmlRequest(), MultiProcessRpcServer(), resetDispatcher(), storeFuncResult(), and waitConnection().

int funtik::MultiProcessRpcServer::m_iState [protected]

Definition at line 354 of file mprocess_rpc_server.h.

Referenced by getState(), serverLoop(), and setState().

bool funtik::MultiProcessRpcServer::m_wbxml_mode [protected]

Definition at line 355 of file mprocess_rpc_server.h.

Referenced by doChild(), handleXmlRequest(), and MultiProcessRpcServer().

bool funtik::MultiProcessRpcServer::m_bHandleSigchld [private]

Definition at line 357 of file mprocess_rpc_server.h.

Referenced by MultiProcessRpcServer(), and ~MultiProcessRpcServer().


The documentation for this class was generated from the following files:
Generated on Sun Aug 19 20:09:00 2007 for ulxmlrpcpp by  doxygen 1.5.1