NCBI C++ ToolKit
scheduler_engine.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_OBJUTILS___SCHEDULER_ENGINE__HPP
2 #define GUI_OBJUTILS___SCHEDULER_ENGINE__HPP
3 
4 /* $Id: scheduler_engine.hpp 35731 2016-06-15 21:00:09Z katargir $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk
30  *
31  * File Description:
32  *
33  */
34 
36 
37 #include <corelib/ncbithr.hpp>
38 
40 
42 {
43 public:
44  virtual ~IWaitPeriod() {}
45 
46  /// returns a period of time after which the task shall be executed again
47  virtual CTimeSpan GetWaitPeriod() = 0;
48 };
49 
50 ///////////////////////////////////////////////////////////////////////////////
51 /// CSchedulerEngine
52 /// CSchedulerEngine is an engine that can be used with CAppJobDispatcher.
53 /// The idea of CSchedulerEngine is to use a single background thread for
54 /// periodic execution of multiple jobs. This kind of engine is useful for
55 /// doing quick repetitive tasks such as polling external services every once
56 /// in while. All jobs share the same thread so they should execute really quick.
57 /// To be compatible with CSchedulerEngine a job needs to implement
58 /// IWaitPeriod interface.
59 
61  : public CObject,
62  public IAppJobEngine
63 {
64  friend class CSchedulerEngineThread;
65 public:
67 
69  virtual ~CSchedulerEngine();
70 
71  /// @name IAppJobEngine implementation
72  /// @{
73  virtual bool IsActive();
74 
75  virtual void SetListener(IAppJobEngineListener* listener);
76 
77  void StartJob(IAppJob& job, IEngineParams* /*params = NULL*/);
78 
79  virtual void CancelJob(IAppJob& job);
80  virtual void SuspendJob(IAppJob& /*job*/);
81  virtual void ResumeJob(IAppJob& /*job*/);
82 
83  virtual TJobState GetJobState(IAppJob& job) const;
84 
85  virtual void ShutDown();
86  virtual void RequestCancel();
87  /// @}
88 
89 protected:
90  /// record that holds infromation about a job
91  struct CJobRecord
92  {
94  m_Job(&job),
95  m_JobState(TJobState::eRunning),
96  m_NextExec(CTime::eCurrent) {}
97 
101  };
102 
103 protected:
104  /// performs job execution on a separate scheduling thread
105  void x_WorkOnThread();
106  void x_RunJob();
107 
108  unsigned long x_GetWaitPeriod();
109 
110  mutable CMutex m_Mutex;
111  list<CJobRecord> m_Jobs;
114 
116 
118 };
119 
120 
122 
123 #endif // GUI_OBJUTILS___SCHEDULER_ENGINE__HPP
CAtomicCounter_WithAutoInit –.
Definition: ncbicntr.hpp:120
CMutex –.
Definition: ncbimtx.hpp:749
CObject –.
Definition: ncbiobj.hpp:180
CSchedulerEngineThread.
CSchedulerEngine CSchedulerEngine is an engine that can be used with CAppJobDispatcher.
list< CJobRecord > m_Jobs
IAppJob::EJobState TJobState
CAtomicCounter_WithAutoInit m_StopRequested
IAppJobEngineListener * m_Listener
CRef< CThread > m_WorkerThread
CSemaphore –.
Definition: ncbimtx.hpp:1375
CTimeSpan.
Definition: ncbitime.hpp:1313
CTime –.
Definition: ncbitime.hpp:296
IAppJobEngineListener - receives notifications about changes in job state.
IAppJobEngine.
IAppJob.
Definition: app_job.hpp:82
virtual ~IWaitPeriod()
virtual CTimeSpan GetWaitPeriod()=0
returns a period of time after which the task shall be executed again
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIUTILS_EXPORT
Definition: gui_export.h:518
Multi-threading – classes, functions, and features.
record that holds infromation about a job
Modified on Fri Sep 20 14:57:50 2024 by modify_doxy.py rev. 669887