dmlite  0.6
Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
dmlite::dmTaskExec Class Referenceabstract

#include <TaskExec.h>

Inheritance diagram for dmlite::dmTaskExec:
Inheritance graph
[legend]
Collaboration diagram for dmlite::dmTaskExec:
Collaboration graph
[legend]

Public Member Functions

 dmTaskExec ()
 
 ~dmTaskExec ()
 
int submitCmd (std::string cmd)
 
int submitCmd (std::vector< std::string > &args)
 Executes a command. Returns a positive integer as a key to reference. More...
 
void goCmd (int id)
 
void assignCmd (dmTask *task, std::vector< std::string > &args)
 Split che command string into the single parms. More...
 
int waitResult (int taskID, int tmout=5)
 
int killTask (int taskID)
 
dmTaskgetTask (int taskID)
 
int getTaskStdout (int taskID, std::string &stdout)
 
void tick ()
 
int getTaskCounters (int &tot, int &running, int &finished)
 
virtual void onLoggingRequest (Logger::Level lvl, std::string const &msg)=0
 Event invoked internally to log stuff. More...
 
virtual void onErrLoggingRequest (std::string const &msg)=0
 Event invoked internally to log stuff. More...
 

Public Attributes

std::string instance
 

Protected Member Functions

virtual void onTaskCompleted (dmTask &task)
 
virtual void onTaskRunning (dmTask &task)
 NOTE the signature. This passes copies of Task objects, not the originals. More...
 

Private Member Functions

int popen3 (int fd[3], pid_t *pid, const char **argv)
 
virtual void run (int key)
 
int killTask (dmTask *task)
 

Private Attributes

int taskcnt
 Used to create keys to be inserted into the map. This has to be treated modulo MAXINT or similar big number. More...
 
std::map< int, dmTask * > tasks
 This map works like a sparse array :-) More...
 

Detailed Description

Allows to spawn commands, useful for checksum calculations or file pulling The spawned commands are pollable, i.e. in a given moment it's possible to know the list of commands that are still running. Objects belonging to this class in general are created in the disk nodes, e.g. for running checksums or file copies and pulls

Constructor & Destructor Documentation

dmlite::dmTaskExec::dmTaskExec ( )
dmlite::dmTaskExec::~dmTaskExec ( )

Member Function Documentation

void dmlite::dmTaskExec::assignCmd ( dmTask task,
std::vector< std::string > &  args 
)

Split che command string into the single parms.

dmTask* dmlite::dmTaskExec::getTask ( int  taskID)
int dmlite::dmTaskExec::getTaskCounters ( int &  tot,
int &  running,
int &  finished 
)
int dmlite::dmTaskExec::getTaskStdout ( int  taskID,
std::string &  stdout 
)
void dmlite::dmTaskExec::goCmd ( int  id)

Actually starts the thread corresponding to a command that was just submitted Avoids race conditions

int dmlite::dmTaskExec::killTask ( int  taskID)
int dmlite::dmTaskExec::killTask ( dmTask task)
private
virtual void dmlite::dmTaskExec::onErrLoggingRequest ( std::string const &  msg)
pure virtual

Event invoked internally to log stuff.

virtual void dmlite::dmTaskExec::onLoggingRequest ( Logger::Level  lvl,
std::string const &  msg 
)
pure virtual

Event invoked internally to log stuff.

virtual void dmlite::dmTaskExec::onTaskCompleted ( dmTask task)
protectedvirtual

event for immediate notifications when a task finishes Subclasses can specialize this and apply app-dependent behavior to perform actions when something has finished running NOTE the signature. This passes copies of Task objects, not the originals

virtual void dmlite::dmTaskExec::onTaskRunning ( dmTask task)
protectedvirtual

NOTE the signature. This passes copies of Task objects, not the originals.

int dmlite::dmTaskExec::popen3 ( int  fd[3],
pid_t *  pid,
const char **  argv 
)
private
virtual void dmlite::dmTaskExec::run ( int  key)
privatevirtual

Here we invoke popen3 and block waiting for the process to end. Upon end it updates the corresponding instance of dmTask with the result and the stdout

int dmlite::dmTaskExec::submitCmd ( std::string  cmd)

Executes a command. Returns a positive integer as a key to reference the execution status and the result The mechanics is that a detached thread is started. This guy invokes popen3 and blocks waiting for the process to end. Upon end it updates the corresponding instance of dmTask with the result and the stdout

int dmlite::dmTaskExec::submitCmd ( std::vector< std::string > &  args)

Executes a command. Returns a positive integer as a key to reference.

void dmlite::dmTaskExec::tick ( )

Loops over all the tasks and:

  • send a notification to the head node about all the processes that are running or that have finished
  • garbage collect the task list.
    • Task that are finished since long (e.g. 1 hour)
    • Tasks that are stuck (e.g. 1 day)
int dmlite::dmTaskExec::waitResult ( int  taskID,
int  tmout = 5 
)

Get the results of a task. Wait at max tmout seconds until the task finishes Return 0 if the task has finished and there is a result Return nonzero if the task is still running

Member Data Documentation

std::string dmlite::dmTaskExec::instance
int dmlite::dmTaskExec::taskcnt
private

Used to create keys to be inserted into the map. This has to be treated modulo MAXINT or similar big number.

std::map<int, dmTask*> dmlite::dmTaskExec::tasks
private

This map works like a sparse array :-)


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