NCBI C++ ToolKit
|
Search Toolkit Book for CSchedulerEngine
CSchedulerEngine CSchedulerEngine is an engine that can be used with CAppJobDispatcher. More...
#include <gui/utils/scheduler_engine.hpp>
Classes | |
struct | CJobRecord |
record that holds infromation about a job More... | |
Public Types | |
typedef IAppJob::EJobState | TJobState |
![]() | |
enum | EAllocFillMode { eAllocFillNone = 1 , eAllocFillZero , eAllocFillPattern } |
Control filling of newly allocated memory. More... | |
typedef CObjectCounterLocker | TLockerType |
Default locker type for CRef. More... | |
typedef atomic< Uint8 > | TCounter |
Counter type is CAtomiCounter. More... | |
typedef Uint8 | TCount |
Alias for value type of counter. More... | |
![]() | |
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... | |
![]() | |
CObject (void) | |
Constructor. More... | |
CObject (const CObject &src) | |
Copy constructor. More... | |
virtual | ~CObject (void) |
Destructor. More... | |
CObject & | operator= (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... | |
![]() | |
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 |
![]() | |
virtual | ~IAppJobEngine () |
Protected Member Functions | |
void | x_WorkOnThread () |
performs job execution on a separate scheduling thread More... | |
void | x_RunJob () |
unsigned long | x_GetWaitPeriod () |
![]() | |
virtual void | DeleteThis (void) |
Virtual method "deleting" this object. More... | |
Protected Attributes | |
CMutex | m_Mutex |
list< CJobRecord > | m_Jobs |
CSemaphore | m_WakeSignal |
CAtomicCounter_WithAutoInit | m_StopRequested |
IAppJobEngineListener * | m_Listener |
CRef< CThread > | m_WorkerThread |
Friends | |
class | CSchedulerEngineThread |
Additional Inherited Members | |
![]() | |
static NCBI_XNCBI_EXPORT void | ThrowNullPointerException (void) |
Define method to throw null pointer exception. More... | |
static NCBI_XNCBI_EXPORT 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 void | EnableDebugDump (bool on) |
![]() | |
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... | |
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.
Definition at line 66 of file scheduler_engine.hpp.
CSchedulerEngine::CSchedulerEngine | ( | ) |
Definition at line 64 of file scheduler_engine.cpp.
References CSchedulerEngineThread, CThread::fRunNice, m_WorkerThread, CRef< C, Locker >::Reset(), and CThread::Run().
|
virtual |
Definition at line 72 of file scheduler_engine.cpp.
|
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().
|
virtual |
Implements IAppJobEngine.
Definition at line 166 of file scheduler_engine.cpp.
References IAppJob::eInvalid, i, m_Jobs, and m_Mutex.
|
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.
|
virtual |
asyncronous request all jobs to Cancel
Implements IAppJobEngine.
Definition at line 86 of file scheduler_engine.cpp.
|
virtual |
Implements IAppJobEngine.
Definition at line 158 of file scheduler_engine.cpp.
References NCBI_THROW.
|
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.
|
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().
|
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.
|
virtual |
Implements IAppJobEngine.
Definition at line 150 of file scheduler_engine.cpp.
References NCBI_THROW.
|
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().
|
protected |
Definition at line 209 of file scheduler_engine.cpp.
References CTime::eCurrent, IAppJob::eFailed, IAppJob::eRunning, i, m_Jobs, m_Listener, m_Mutex, NCBI_CATCH, IAppJobEngineListener::OnEngineJobStateChanged(), and IAppJob::Run().
Referenced by 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().
|
friend |
Definition at line 64 of file scheduler_engine.hpp.
Referenced by CSchedulerEngine().
|
protected |
Definition at line 111 of file scheduler_engine.hpp.
Referenced by CancelJob(), GetJobState(), StartJob(), x_GetWaitPeriod(), and x_RunJob().
|
protected |
Definition at line 115 of file scheduler_engine.hpp.
Referenced by SetListener(), StartJob(), and x_RunJob().
|
mutableprotected |
Definition at line 110 of file scheduler_engine.hpp.
Referenced by CancelJob(), GetJobState(), StartJob(), x_GetWaitPeriod(), and x_RunJob().
|
protected |
Definition at line 113 of file scheduler_engine.hpp.
Referenced by ShutDown(), and x_WorkOnThread().
|
protected |
Definition at line 112 of file scheduler_engine.hpp.
Referenced by CancelJob(), ShutDown(), StartJob(), and x_WorkOnThread().
Definition at line 117 of file scheduler_engine.hpp.
Referenced by CSchedulerEngine(), and ShutDown().