ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes | List of all members
TMPWorker Class Reference

This class works in conjuction with TMPClient, reacting to messages received from it as specified by the Notify and HandleInput methods.

When TMPClient::Fork is called, a TMPWorker instance is passed to it which will take control of the ROOT session in the children processes.

After forking, every time a message is sent or broadcast to the workers, TMPWorker::Notify is called and the message is retrieved. Messages exchanged between TMPClient and TMPWorker should be sent with the MPSend() standalone function.
If the code of the message received is above 1000 (i.e. it is an MPCode) the qualified TMPWorker::HandleInput method is called, that takes care of handling the most generic type of messages. Otherwise the unqualified (possibly overridden) version of HandleInput is called, allowing classes that inherit from TMPWorker to manage their own protocol.
An application's worker class should inherit from TMPWorker and implement a HandleInput method that overrides TMPWorker's.

Definition at line 20 of file TMPWorker.h.

Public Member Functions

 TMPWorker ()
 Class constructor. More...
 
virtual ~TMPWorker ()
 
 TMPWorker (const TMPWorker &)=delete
 
TMPWorkeroperator= (const TMPWorker &)=delete
 
virtual void Init (int fd, unsigned workerN)
 This method is called by children processes right after forking. More...
 
void Run ()
 
TSocketGetSocket ()
 
pid_t GetPid ()
 
unsigned GetNWorker () const
 

Private Member Functions

virtual void HandleInput (MPCodeBufPair &msg)
 Handle a message with an EMPCode. More...
 

Private Attributes

std::unique_ptr< TSocketfS
 This worker's socket. The unique_ptr makes sure resources are released. More...
 
pid_t fPid
 the PID of the process in which this worker is running More...
 
unsigned fNWorker
 the ordinal number of this worker (0 to nWorkers-1) More...
 

#include <TMPWorker.h>

Inheritance diagram for TMPWorker:
[legend]

Constructor & Destructor Documentation

TMPWorker::TMPWorker ( )

Class constructor.

Note that this does not set variables like fPid or fS (worker's socket).
These operations are handled by the Init method, which is called after forking.
This separation is in place because the instantiation of a worker must be done once before forking, while the initialization of the members must be done after forking by each of the children processes.

Definition at line 42 of file TMPWorker.cxx.

virtual TMPWorker::~TMPWorker ( )
inlinevirtual

Definition at line 26 of file TMPWorker.h.

TMPWorker::TMPWorker ( const TMPWorker )
delete

Member Function Documentation

unsigned TMPWorker::GetNWorker ( ) const
inline
pid_t TMPWorker::GetPid ( )
inline

Definition at line 34 of file TMPWorker.h.

TSocket* TMPWorker::GetSocket ( )
inline
void TMPWorker::HandleInput ( MPCodeBufPair msg)
privatevirtual

Handle a message with an EMPCode.

This method is called upon receiving a message with a code >= 1000 (i.e. EMPCode). It handles the most generic types of messages.
Classes inheriting from TMPWorker should implement their own HandleInput function, that should be able to handle codes specific to that application.
The appropriate version of the HandleInput method (TMPWorker's or the overriding version) is automatically called depending on the message code.

Reimplemented in TPoolWorker< F, T, void >, TPoolWorker< F, void, R >, TPoolProcessor< F >, and TPoolWorker< F, T, R >.

Definition at line 88 of file TMPWorker.cxx.

Referenced by Run().

void TMPWorker::Init ( int  fd,
unsigned  workerN 
)
virtual

This method is called by children processes right after forking.

Initialization of worker properties that must be delayed until after forking must be done here.
For example, Init saves the pid into fPid, and adds the TMPWorker to the main eventloop (as a TFileHandler).
Make sure this operations are performed also by overriding implementations, e.g. by calling TMPWorker::Init explicitly.

Reimplemented in TPoolProcessor< F >.

Definition at line 55 of file TMPWorker.cxx.

Referenced by TMPClient::Fork(), and TPoolProcessor< F >::Init().

TMPWorker& TMPWorker::operator= ( const TMPWorker )
delete
void TMPWorker::Run ( )

Definition at line 63 of file TMPWorker.cxx.

Referenced by TMPClient::Fork().

Member Data Documentation

unsigned TMPWorker::fNWorker
private

the ordinal number of this worker (0 to nWorkers-1)

Definition at line 43 of file TMPWorker.h.

Referenced by GetNWorker(), HandleInput(), and Init().

pid_t TMPWorker::fPid
private

the PID of the process in which this worker is running

Definition at line 42 of file TMPWorker.h.

Referenced by GetPid(), and Init().

std::unique_ptr<TSocket> TMPWorker::fS
private

This worker's socket. The unique_ptr makes sure resources are released.

Definition at line 41 of file TMPWorker.h.

Referenced by GetSocket(), HandleInput(), Init(), and Run().

Collaboration diagram for TMPWorker:
[legend]

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