NCBI C++ ToolKit
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
CSchedulerEngine Class Reference

Search Toolkit Book for CSchedulerEngine

CSchedulerEngine CSchedulerEngine is an engine that can be used with CAppJobDispatcher. More...

#include <gui/utils/scheduler_engine.hpp>

+ Inheritance diagram for CSchedulerEngine:
+ Collaboration diagram for CSchedulerEngine:

Classes

struct  CJobRecord
 record that holds infromation about a job More...
 

Public Types

typedef IAppJob::EJobState TJobState
 
- Public Types inherited from CObject
enum  EAllocFillMode { eAllocFillNone = 1, eAllocFillZero, eAllocFillPattern }
 Control filling of newly allocated memory. More...
 
typedef CObjectCounterLocker TLockerType
 Default locker type for CRef. More...
 
typedef CAtomicCounter TCounter
 Counter type is CAtomiCounter. More...
 
typedef TCounter::TValue TCount
 Alias for value type of counter. More...
 
- Public Types inherited from IAppJobEngine
typedef CAppJobDispatcher TDisp
 
typedef IAppJob::EJobState TJobState
 

Public Member Functions

 CSchedulerEngine ()
 CSchedulerEngine. More...
 
virtual ~CSchedulerEngine ()
 
IAppJobEngine implementation
virtual bool IsActive ()
 Returns true if Engine supports "active" model i.e. More...
 
virtual void SetListener (IAppJobEngineListener *listener)
 For "active" mode set a Listener that will be notified when the state of a Job changes. More...
 
void StartJob (IAppJob &job, IEngineParams *)
 If Engine cannot start the Job and exception shall be thrown. More...
 
virtual void CancelJob (IAppJob &job)
 Cancel job in the engine If job is not running yet - just remove from the pending queue otherwise uses IInterruptible to notify the job about cancel request. More...
 
virtual void SuspendJob (IAppJob &)
 
virtual void ResumeJob (IAppJob &)
 
virtual TJobState GetJobState (IAppJob &job) const
 
virtual void ShutDown ()
 stop any background threads and free resources associated with the Engine More...
 
virtual void RequestCancel ()
 asyncronous request all jobs to Cancel More...
 
- Public Member Functions inherited from CObject
 CObject (void)
 Constructor. More...
 
 CObject (const CObject &src)
 Copy constructor. More...
 
virtual ~CObject (void)
 Destructor. More...
 
CObjectoperator= (const CObject &src) THROWS_NONE
 Assignment operator. More...
 
bool CanBeDeleted (void) const THROWS_NONE
 Check if object can be deleted. More...
 
bool IsAllocatedInPool (void) const THROWS_NONE
 Check if object is allocated in memory pool (not system heap) More...
 
bool Referenced (void) const THROWS_NONE
 Check if object is referenced. More...
 
bool ReferencedOnlyOnce (void) const THROWS_NONE
 Check if object is referenced only once. More...
 
void AddReference (void) const
 Add reference to object. More...
 
void RemoveReference (void) const
 Remove reference to object. More...
 
void ReleaseReference (void) const
 Remove reference without deleting object. More...
 
virtual void DoNotDeleteThisObject (void)
 Mark this object as not allocated in heap – do not delete this object. More...
 
virtual void DoDeleteThisObject (void)
 Mark this object as allocated in heap – object can be deleted. More...
 
void * operator new (size_t size)
 Define new operator for memory allocation. More...
 
void * operator new[] (size_t size)
 Define new[] operator for 'array' memory allocation. More...
 
void operator delete (void *ptr)
 Define delete operator for memory deallocation. More...
 
void operator delete[] (void *ptr)
 Define delete[] operator for memory deallocation. More...
 
void * operator new (size_t size, void *place)
 Define new operator. More...
 
void operator delete (void *ptr, void *place)
 Define delete operator. More...
 
void * operator new (size_t size, CObjectMemoryPool *place)
 Define new operator using memory pool. More...
 
void operator delete (void *ptr, CObjectMemoryPool *place)
 Define delete operator. More...
 
virtual void DebugDump (CDebugDumpContext ddc, unsigned int depth) const
 Define method for dumping debug information. More...
 
- Public Member Functions inherited from CDebugDumpable
 CDebugDumpable (void)
 
virtual ~CDebugDumpable (void)
 
void DebugDumpText (ostream &out, const string &bundle, unsigned int depth) const
 
void DebugDumpFormat (CDebugDumpFormatter &ddf, const string &bundle, unsigned int depth) const
 
void DumpToConsole (void) const
 
- Public Member Functions inherited from IAppJobEngine
virtual ~IAppJobEngine ()
 

Protected Member Functions

void x_WorkOnThread ()
 performs job execution on a separate scheduling thread More...
 
void x_RunJob ()
 
unsigned long x_GetWaitPeriod ()
 
- Protected Member Functions inherited from CObject
virtual void DeleteThis (void)
 Virtual method "deleting" this object. More...
 

Protected Attributes

CMutex m_Mutex
 
list< CJobRecordm_Jobs
 
CSemaphore m_WakeSignal
 
CAtomicCounter_WithAutoInit m_StopRequested
 
IAppJobEngineListenerm_Listener
 
CRef< CThreadm_WorkerThread
 

Friends

class CSchedulerEngineThread
 

Additional Inherited Members

- Static Public Member Functions inherited from CObject
static NCBI_NORETURN void ThrowNullPointerException (void)
 Define method to throw null pointer exception. More...
 
static NCBI_NORETURN void ThrowNullPointerException (const type_info &type)
 
static EAllocFillMode GetAllocFillMode (void)
 
static void SetAllocFillMode (EAllocFillMode mode)
 
static void SetAllocFillMode (const string &value)
 Set mode from configuration parameter value. More...
 
- Static Public Member Functions inherited from CDebugDumpable
static void EnableDebugDump (bool on)
 
- Static Public Attributes inherited from CObject
static const TCount eCounterBitsCanBeDeleted = 1 << 0
 Define possible object states. More...
 
static const TCount eCounterBitsInPlainHeap = 1 << 1
 Heap signature was found. More...
 
static const TCount eCounterBitsPlaceMask
 Mask for 'in heap' state flags. More...
 
static const int eCounterStep = 1 << 2
 Skip over the "in heap" bits. More...
 
static const TCount eCounterValid = TCount(1) << (sizeof(TCount) * 8 - 2)
 Minimal value for valid objects (reference counter is zero) Must be a single bit value. More...
 
static const TCount eCounterStateMask
 Valid object, and object in heap. More...
 

Detailed Description

CSchedulerEngine CSchedulerEngine is an engine that can be used with CAppJobDispatcher.

The idea of CSchedulerEngine is to use a single background thread for periodic execution of multiple jobs. This kind of engine is useful for doing quick repetitive tasks such as polling external services every once in while. All jobs share the same thread so they should execute really quick. To be compatible with CSchedulerEngine a job needs to implement IWaitPeriod interface.

Definition at line 60 of file scheduler_engine.hpp.

Member Typedef Documentation

Definition at line 66 of file scheduler_engine.hpp.

Constructor & Destructor Documentation

CSchedulerEngine::CSchedulerEngine ( )
CSchedulerEngine::~CSchedulerEngine ( )
virtual

Definition at line 72 of file scheduler_engine.cpp.

Member Function Documentation

void CSchedulerEngine::CancelJob ( IAppJob job)
virtual

Cancel job in the engine If job is not running yet - just remove from the pending queue otherwise uses IInterruptible to notify the job about cancel request.

Implements IAppJobEngine.

Definition at line 135 of file scheduler_engine.cpp.

References CTime::eCurrent, i, m_Jobs, m_Mutex, m_WakeSignal, CSemaphore::Post(), and IAppJob::RequestCancel().

IAppJob::EJobState CSchedulerEngine::GetJobState ( IAppJob job) const
virtual
Returns
current job state

Implements IAppJobEngine.

Definition at line 166 of file scheduler_engine.cpp.

References IAppJob::eInvalid, i, m_Jobs, and m_Mutex.

bool CSchedulerEngine::IsActive ( )
virtual

Returns true if Engine supports "active" model i.e.

will send notifications to Dispatcher when a Job running on this Engine changes its state.

Implements IAppJobEngine.

Definition at line 91 of file scheduler_engine.cpp.

void CSchedulerEngine::RequestCancel ( )
virtual

asyncronous request all jobs to Cancel

Implements IAppJobEngine.

Definition at line 86 of file scheduler_engine.cpp.

void CSchedulerEngine::ResumeJob ( IAppJob )
virtual

Implements IAppJobEngine.

Definition at line 158 of file scheduler_engine.cpp.

References NCBI_THROW.

void CSchedulerEngine::SetListener ( IAppJobEngineListener listener)
virtual

For "active" mode set a Listener that will be notified when the state of a Job changes.

Implements IAppJobEngine.

Definition at line 98 of file scheduler_engine.cpp.

References m_Listener.

void CSchedulerEngine::ShutDown ( )
virtual

stop any background threads and free resources associated with the Engine

Implements IAppJobEngine.

Definition at line 77 of file scheduler_engine.cpp.

References Info(), CThread::Join(), LOG_POST, m_StopRequested, m_WakeSignal, m_WorkerThread, CSemaphore::Post(), and CAtomicCounter::Set().

void CSchedulerEngine::StartJob ( IAppJob job,
IEngineParams *  params 
)
virtual

If Engine cannot start the Job and exception shall be thrown.

Implements IAppJobEngine.

Definition at line 103 of file scheduler_engine.cpp.

References IAppJob::eRunning, IAppJob::GetDescr(), i, m_Jobs, m_Listener, m_Mutex, m_WakeSignal, NCBI_THROW, IAppJobEngineListener::OnEngineJobStateChanged(), CSemaphore::Post(), and string.

void CSchedulerEngine::SuspendJob ( IAppJob )
virtual

Implements IAppJobEngine.

Definition at line 150 of file scheduler_engine.cpp.

References NCBI_THROW.

unsigned long CSchedulerEngine::x_GetWaitPeriod ( )
protected

Definition at line 198 of file scheduler_engine.cpp.

References CTime::eCurrent, i, m_Jobs, m_Mutex, max(), and min().

Referenced by x_WorkOnThread().

void CSchedulerEngine::x_RunJob ( )
protected
void CSchedulerEngine::x_WorkOnThread ( )
protected

performs job execution on a separate scheduling thread

Definition at line 178 of file scheduler_engine.cpp.

References CAtomicCounter::Get(), Info(), LOG_POST, m_StopRequested, m_WakeSignal, CSemaphore::TryWait(), x_GetWaitPeriod(), and x_RunJob().

Referenced by CSchedulerEngineThread::Main().

Friends And Related Function Documentation

friend class CSchedulerEngineThread
friend

Definition at line 64 of file scheduler_engine.hpp.

Referenced by CSchedulerEngine().

Member Data Documentation

list<CJobRecord> CSchedulerEngine::m_Jobs
protected

Definition at line 111 of file scheduler_engine.hpp.

Referenced by CancelJob(), GetJobState(), StartJob(), x_GetWaitPeriod(), and x_RunJob().

IAppJobEngineListener* CSchedulerEngine::m_Listener
protected

Definition at line 115 of file scheduler_engine.hpp.

Referenced by SetListener(), StartJob(), and x_RunJob().

CMutex CSchedulerEngine::m_Mutex
mutableprotected

Definition at line 110 of file scheduler_engine.hpp.

Referenced by CancelJob(), GetJobState(), StartJob(), x_GetWaitPeriod(), and x_RunJob().

CAtomicCounter_WithAutoInit CSchedulerEngine::m_StopRequested
protected

Definition at line 113 of file scheduler_engine.hpp.

Referenced by ShutDown(), and x_WorkOnThread().

CSemaphore CSchedulerEngine::m_WakeSignal
protected

Definition at line 112 of file scheduler_engine.hpp.

Referenced by CancelJob(), ShutDown(), StartJob(), and x_WorkOnThread().

CRef<CThread> CSchedulerEngine::m_WorkerThread
protected

Definition at line 117 of file scheduler_engine.hpp.

Referenced by CSchedulerEngine(), and ShutDown().


The documentation for this class was generated from the following files:
Modified on Tue May 23 17:18:13 2017 by modify_doxy.py rev. 533848