CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConcurrentWorker< DerivedWorkerT > Class Template Reference

#include <concurrency.h>

Inheritance diagram for ConcurrentWorker< DerivedWorkerT >:
Collaboration diagram for ConcurrentWorker< DerivedWorkerT >:

Public Member Functions

virtual ~ConcurrentWorker ()
 
virtual bool Initialize ()
 
virtual void TearDown ()
 

Protected Member Functions

 ConcurrentWorker ()
 
ConcurrentWorkers
< DerivedWorkerT > * 
master () const
 

Private Member Functions

void RegisterMaster (ConcurrentWorkers< DerivedWorkerT > *master)
 
- Private Member Functions inherited from SingleCopy
 SingleCopy ()
 

Private Attributes

ConcurrentWorkers
< DerivedWorkerT > * 
master_
 

Friends

class ConcurrentWorkers< DerivedWorkerT >
 

Detailed Description

template<class DerivedWorkerT>
class ConcurrentWorker< DerivedWorkerT >

Base class for worker classes that should be used in a ConcurrentWorkers swarm. These classes need to fulfill a number of requirements in order to satisfy the needs of the ConcurrentWorkers template.

Requirements: -> needs to define the following types:

  • expected_data - input data structure of the worker
  • returned_data - output data structure of the worker
  • worker_context - context structure for initialization information

-> implement a constructor that takes a pointer to its worker_context as its only parameter: AwesomeWorker(const AwesomeWorker::worker_context*) Note: do not rely on the context object to be available after the constructor has returned!

-> needs to define the calling-operator expecting one parameter of type: const expected_data& and returning void This will be invoked for every new job the worker should process

-> inside the implementation of the described calling-operator it needs to invoke either: master()->JobSuccessful(const returned_data&) or: master()->JobFailed(const returned_data&) as its LAST operation before returning. This will keep track of finished jobs and inform the user of Concurrent- Workers about finished jobs.

-> [optional] overwrite Initialize() and/or TearDown() to do environmental setup work, before or respectively after jobs will be processed

General Reminder: You will be running in a multi-threaded environment here! Buckle up and make suitable preparations to shield yourself from serious head-ache.

Note: This implements a Curiously Recurring Template Pattern (http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern)

Parameters
DerivedWorkerTthe class name of the inheriting class (f.e. class AwesomeWorker : public ConcurrentWorker<AwesomeWorker>)

Definition at line 669 of file concurrency.h.

Constructor & Destructor Documentation

template<class DerivedWorkerT>
virtual ConcurrentWorker< DerivedWorkerT >::~ConcurrentWorker ( )
inlinevirtual

Definition at line 671 of file concurrency.h.

template<class DerivedWorkerT>
ConcurrentWorker< DerivedWorkerT >::ConcurrentWorker ( )
inlineprotected

The actual job-processing entry point. See the description of the inheriting class requirements to learn about the semantics of this methods. DO NOT FORGET TO CALL master()->JobSuccessful() OR master()->JobFinished() at the end of thismethod!!

Note: There is no way to generally define this operator, it is therefore commented out and placed here just as a reminder.

Parameters
datathe data to be processed.

Definition at line 702 of file concurrency.h.

Member Function Documentation

template<class DerivedWorkerT>
virtual bool ConcurrentWorker< DerivedWorkerT >::Initialize ( )
inlinevirtual

Does general initialization before any jobs will get scheduled. You do not need to up-call this initialize method, since it is seen as a dummy here.

Returns
true one successful initialization

Definition at line 679 of file concurrency.h.

template<class DerivedWorkerT>
ConcurrentWorkers<DerivedWorkerT>* ConcurrentWorker< DerivedWorkerT >::master ( ) const
inlineprotected

Gets a pointer to the ConcurrentWorkers object that this worker resides in

Returns
a pointer to the ConcurrentWorkers object

Definition at line 709 of file concurrency.h.

Referenced by swissknife::CommandMigrate::AbstractMigrationWorker< DerivedT >::operator()().

Here is the caller graph for this function:

template<class DerivedWorkerT>
void ConcurrentWorker< DerivedWorkerT >::RegisterMaster ( ConcurrentWorkers< DerivedWorkerT > *  master)
inlineprivate

Definition at line 713 of file concurrency.h.

template<class DerivedWorkerT>
virtual void ConcurrentWorker< DerivedWorkerT >::TearDown ( )
inlinevirtual

Does general clean-up after the last job was processed in the worker object and it is about to vanish. You do not need to up-call this method.

Definition at line 685 of file concurrency.h.

Friends And Related Function Documentation

template<class DerivedWorkerT>
friend class ConcurrentWorkers< DerivedWorkerT >
friend

Definition at line 712 of file concurrency.h.

Member Data Documentation

template<class DerivedWorkerT>
ConcurrentWorkers<DerivedWorkerT>* ConcurrentWorker< DerivedWorkerT >::master_
private

Definition at line 718 of file concurrency.h.


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