The Original CHomP Software
|
This class defines a generic task object (coordinator or worker) for the multi-work distributed computations framework. More...
#include <mwtask.h>
Public Member Functions | |
mwTask () | |
The default constructor. More... | |
virtual | ~mwTask () |
The destructor. More... | |
void | Port (int number) |
Sets the port number for the communication or 0 to use none. More... | |
int | Port () const |
Returns the current port number. More... | |
void | ControlNumber (unsigned int number) |
Sets the control number for identification. More... | |
unsigned int | ControlNumber () const |
Returns the currently set identification control number. More... | |
void | TimeOut (int seconds) |
Sets the network connection time-out interval in seconds. More... | |
int | TimeOut () const |
Returns the currently set network connection time-out interval. More... | |
int | LogFile (const char *filename) |
Begins logging detailed communication debug information to the given file. More... | |
void | LogFile (const mwTask &other) |
Uses another task's log file to log this task's information. More... | |
void | LogClose () |
Closes the log file and adds a line with the time information unless this log file was borrowed from another task. More... | |
int | Add (const char *name, int port=-1) |
Adds an address to the list of computers to connect to at the beginning of working or coordinating. More... | |
int | Load (const char *filename) |
Loads computer addresses from the given file. More... | |
int | QuitWorkers () |
Quits all the workers whose addresses were added with the 'Add' and 'Load' functions. More... | |
Static Protected Member Functions | |
static int | SendMessage (int fd, unsigned int ctrl, unsigned int code, const mwData &x) |
Sends a message with data to the given socket. More... | |
static int | RecvMessage (int fd, unsigned int &ctrl, unsigned int &code, mwData &x) |
Receives a message with data from the given socket. More... | |
Protected Attributes | |
std::ofstream * | logFile |
The debug log file stream. More... | |
std::vector< std::string > | computers |
A list of workers or coordinators to connect to at start-up. More... | |
std::vector< int > | ports |
A list of port numbers of workers to connect to at start-up. More... | |
Private Member Functions | |
mwTask (const mwTask &) | |
The copy constructor is forbidden. More... | |
mwTask & | operator= (const mwTask &) |
The assignment operator is forbidden. More... | |
Private Attributes | |
int | portnum |
The network communication port number. More... | |
unsigned int | ctrlnum |
The control number that is used to recognize a compatible worker or a compatible coordinator. More... | |
int | timeout |
The network communication time-out in seconds. More... | |
bool | logBorrowed |
Is this log file pointer borrowed from another task? More... | |
This class defines a generic task object (coordinator or worker) for the multi-work distributed computations framework.
It is the common part of a worker task and a coordinator task, and contains some general settings that apply to both. Note that this class is inherited by the worker and the coordinator class in the virtual mode, which allows one to create a class that is both a worker and a coordinator at the same time (although this is not recommended in general).
|
inline |
The default constructor.
Definition at line 219 of file mwtask.h.
|
inlinevirtual |
The destructor.
Definition at line 304 of file mwtask.h.
References LogClose().
|
inlineprivate |
|
inline |
Adds an address to the list of computers to connect to at the beginning of working or coordinating.
The addresses must be in the form "computer.domain:port". If port is not defined then the default port number is used.
Definition at line 350 of file mwtask.h.
References computers, chomp::multiwork::mwError, chomp::multiwork::mwOk, portnum, and ports.
Referenced by Load().
|
inline |
Returns the currently set identification control number.
Definition at line 332 of file mwtask.h.
References ctrlnum.
Referenced by chomp::multiwork::mwCoordinator::RecvMessageC(), chomp::multiwork::mwWorker::RecvMessageW(), chomp::multiwork::mwCoordinator::SendMessageC(), and chomp::multiwork::mwWorker::SendMessageW().
|
inline |
|
inline |
Loads computer addresses from the given file.
Returns the number of acquired addresses or mwError.
Definition at line 395 of file mwtask.h.
References Add(), chomp::multiwork::mwError, chomp::multiwork::mwOk, and portnum.
|
inline |
Closes the log file and adds a line with the time information unless this log file was borrowed from another task.
Definition at line 231 of file mwtask.h.
References logBorrowed, and logFile.
|
inline |
Begins logging detailed communication debug information to the given file.
Returns mwOk on success, mwError if cannot open/create the file.
Definition at line 252 of file mwtask.h.
References LogClose(), logFile, chomp::multiwork::mwError, and chomp::multiwork::mwOk.
|
inline |
Uses another task's log file to log this task's information.
Definition at line 286 of file mwtask.h.
References logBorrowed, LogClose(), and logFile.
|
inline |
Returns the current port number.
Definition at line 321 of file mwtask.h.
References portnum.
Referenced by chomp::multiwork::mwCoordinator::BeginListening(), chomp::multiwork::mwWorker::Work(), and chomp::multiwork::mwWorker::WorkOne().
|
inline |
|
inline |
Quits all the workers whose addresses were added with the 'Add' and 'Load' functions.
Returns mwOk or mwError.
Definition at line 492 of file mwtask.h.
References computers, ctrlnum, logFile, chomp::multiwork::mwByeMsg, chomp::multiwork::mwConnect(), chomp::multiwork::mwDisconnect(), chomp::multiwork::mwDontKeepMsg, chomp::multiwork::mwOk, ports, and SendMessage().
|
inlinestaticprotected |
Receives a message with data from the given socket.
Receives a message from the given socket.
Verifies the received control code if it is correct. Returns mwOk on success or mwError in the case of failure.
Returns mwOk, mwError or mwLost.
Definition at line 437 of file mwtask.h.
References chomp::multiwork::mwError, chomp::multiwork::mwOk, and chomp::multiwork::mwRecvBytes().
Referenced by chomp::multiwork::mwCoordinator::RecvMessageC(), and chomp::multiwork::mwWorker::RecvMessageW().
|
inlinestaticprotected |
Sends a message with data to the given socket.
Sends a message to the given socket.
The message includes a control number. Returns mwOk on success and mwError in the case of failure.
Returns mwOk, mwError or mwLost.
Definition at line 427 of file mwtask.h.
References chomp::multiwork::mwSendBytes().
Referenced by QuitWorkers(), chomp::multiwork::mwCoordinator::SendMessageC(), and chomp::multiwork::mwWorker::SendMessageW().
|
inline |
Returns the currently set network connection time-out interval.
Definition at line 343 of file mwtask.h.
References timeout.
Referenced by chomp::multiwork::mwCoordinator::RunLoop(), chomp::multiwork::mwWorker::Work(), and chomp::multiwork::mwWorker::WorkOne().
|
inline |
|
protected |
A list of workers or coordinators to connect to at start-up.
Definition at line 201 of file mwtask.h.
Referenced by Add(), chomp::multiwork::mwCoordinator::ConnectWorkers(), QuitWorkers(), and chomp::multiwork::mwWorker::Work().
|
private |
The control number that is used to recognize a compatible worker or a compatible coordinator.
Note: The worker sends its negation.
Definition at line 168 of file mwtask.h.
Referenced by ControlNumber(), and QuitWorkers().
|
private |
Is this log file pointer borrowed from another task?
Definition at line 181 of file mwtask.h.
Referenced by LogClose(), and LogFile().
|
protected |
The debug log file stream.
Definition at line 177 of file mwtask.h.
Referenced by chomp::multiwork::mwCoordinator::BeginListening(), chomp::multiwork::mwCoordinator::ConnectWorkers(), chomp::multiwork::mwCoordinator::Coordinate(), chomp::multiwork::mwCoordinator::DisconnectAll(), LogClose(), LogFile(), QuitWorkers(), chomp::multiwork::mwCoordinator::RecvMessageC(), chomp::multiwork::mwWorker::RecvMessageW(), chomp::multiwork::mwCoordinator::RunLoop(), chomp::multiwork::mwCoordinator::RunLoopLocally(), chomp::multiwork::mwWorker::Work(), and chomp::multiwork::mwWorker::WorkOne().
|
private |
|
protected |
A list of port numbers of workers to connect to at start-up.
Definition at line 204 of file mwtask.h.
Referenced by Add(), chomp::multiwork::mwCoordinator::ConnectWorkers(), QuitWorkers(), and chomp::multiwork::mwWorker::Work().
|
private |
The network communication time-out in seconds.
Definition at line 171 of file mwtask.h.
Referenced by TimeOut(), and chomp::multiwork::mwWorker::Work().