ROOT 6.14/05 Reference Guide |
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 26 of file TMPWorker.h.
Public Member Functions | |
TMPWorker () | |
TMPWorker (unsigned nWorkers, ULong64_t maxEntries) | |
TMPWorker (const TMPWorker &)=delete | |
virtual | ~TMPWorker () |
unsigned | GetNWorker () const |
pid_t | GetPid () |
TSocket * | GetSocket () |
virtual void | Init (int fd, unsigned workerN) |
This method is called by children processes right after forking. More... | |
TMPWorker & | operator= (const TMPWorker &)=delete |
void | Run () |
Protected Member Functions | |
void | SendError (const std::string &errmsg, unsigned int code=MPCode::kError) |
Error sender. More... | |
Protected Attributes | |
std::string | fId |
identifier string in the form W<nwrk>|P<proc id>=""> More... | |
ULong64_t | fMaxNEntries |
the maximum number of entries to be processed by this worker More... | |
unsigned | fNWorkers |
the number of workers spawned More... | |
ULong64_t | fProcessedEntries |
the number of entries processed by this worker so far More... | |
Private Member Functions | |
virtual void | HandleInput (MPCodeBufPair &msg) |
Handle a message with an EMPCode. More... | |
Private Attributes | |
unsigned | fNWorker |
the ordinal number of this worker (0 to nWorkers-1) More... | |
pid_t | fPid |
the PID of the process in which this worker is running More... | |
std::unique_ptr< TSocket > | fS |
This worker's socket. The unique_ptr makes sure resources are released. More... | |
#include <TMPWorker.h>
|
inline |
Definition at line 31 of file TMPWorker.h.
|
inline |
Definition at line 33 of file TMPWorker.h.
|
inlinevirtual |
Definition at line 36 of file TMPWorker.h.
|
delete |
|
inline |
Definition at line 45 of file TMPWorker.h.
|
inline |
Definition at line 44 of file TMPWorker.h.
|
inline |
Definition at line 43 of file TMPWorker.h.
|
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 TMPWorkerExecutor< F, T, void >, TMPWorkerExecutor< F, void, R >, TMPWorkerExecutor< F, T, R >, and TMPWorkerTree.
Definition at line 89 of file TMPWorker.cxx.
|
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.
Definition at line 55 of file TMPWorker.cxx.
void TMPWorker::Run | ( | ) |
Definition at line 64 of file TMPWorker.cxx.
|
protected |
Error sender.
Definition at line 115 of file TMPWorker.cxx.
|
protected |
identifier string in the form W<nwrk>|P<proc id>="">
Definition at line 48 of file TMPWorker.h.
|
protected |
the maximum number of entries to be processed by this worker
Definition at line 50 of file TMPWorker.h.
|
private |
the ordinal number of this worker (0 to nWorkers-1)
Definition at line 60 of file TMPWorker.h.
|
protected |
the number of workers spawned
Definition at line 49 of file TMPWorker.h.
|
private |
the PID of the process in which this worker is running
Definition at line 59 of file TMPWorker.h.
|
protected |
the number of entries processed by this worker so far
Definition at line 51 of file TMPWorker.h.
|
private |
This worker's socket. The unique_ptr makes sure resources are released.
Definition at line 58 of file TMPWorker.h.