xrootd
Loading...
Searching...
No Matches
XrdClTaskManager.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3// Author: Lukasz Janyst <ljanyst@cern.ch>
4//------------------------------------------------------------------------------
5// XRootD is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// XRootD is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17//------------------------------------------------------------------------------
18
19#ifndef __XRD_CL_TASK_MANAGER_HH__
20#define __XRD_CL_TASK_MANAGER_HH__
21
22#include <ctime>
23#include <set>
24#include <list>
25#include <string>
26#include <cstdint>
27#include <pthread.h>
29
30namespace XrdCl
31{
32 //----------------------------------------------------------------------------
34 //----------------------------------------------------------------------------
35 class Task
36 {
37 public:
38 virtual ~Task() {};
39
40 //------------------------------------------------------------------------
46 //------------------------------------------------------------------------
47 virtual time_t Run( time_t now ) = 0;
48
49 //------------------------------------------------------------------------
51 //------------------------------------------------------------------------
52 const std::string &GetName() const
53 {
54 return pName;
55 }
56
57 //------------------------------------------------------------------------
59 //------------------------------------------------------------------------
60 void SetName( const std::string &name )
61 {
62 pName = name;
63 }
64
65 private:
66 std::string pName;
67 };
68
69 //----------------------------------------------------------------------------
74 //----------------------------------------------------------------------------
76 {
77 public:
78 //------------------------------------------------------------------------
80 //------------------------------------------------------------------------
82
83 //------------------------------------------------------------------------
85 //------------------------------------------------------------------------
87
88 //------------------------------------------------------------------------
90 //------------------------------------------------------------------------
91 bool Start();
92
93 //------------------------------------------------------------------------
97 //------------------------------------------------------------------------
98 bool Stop();
99
100 //------------------------------------------------------------------------
107 //------------------------------------------------------------------------
108 void RegisterTask( Task *task, time_t time, bool own = true );
109
110 //------------------------------------------------------------------------
115 //------------------------------------------------------------------------
116 void UnregisterTask( Task *task );
117
118 //------------------------------------------------------------------------
120 //------------------------------------------------------------------------
121 void RunTasks();
122
123 private:
124
125 //------------------------------------------------------------------------
126 // Task set helpers
127 //------------------------------------------------------------------------
129 {
130 TaskHelper( Task *tsk, time_t tme, bool ow = true ):
131 task(tsk), execTime(tme), own(ow) {}
133 time_t execTime;
134 bool own;
135 };
136
138 {
139 bool operator () ( const TaskHelper &th1, const TaskHelper &th2 ) const
140 {
141 return th1.execTime < th2.execTime;
142 }
143 };
144
145 typedef std::multiset<TaskHelper, TaskHelperCmp> TaskSet;
146 typedef std::list<Task*> TaskList;
147
148 //------------------------------------------------------------------------
149 // Private variables
150 //------------------------------------------------------------------------
151 uint16_t pResolution;
154 pthread_t pRunnerThread;
158 };
159}
160
161#endif // __XRD_CL_TASK_MANAGER_HH__
Definition XrdClTaskManager.hh:76
pthread_t pRunnerThread
Definition XrdClTaskManager.hh:154
void RegisterTask(Task *task, time_t time, bool own=true)
std::list< Task * > TaskList
Definition XrdClTaskManager.hh:146
void RunTasks()
Run the tasks - this loops infinitely.
bool pRunning
Definition XrdClTaskManager.hh:155
std::multiset< TaskHelper, TaskHelperCmp > TaskSet
Definition XrdClTaskManager.hh:145
XrdSysMutex pOpMutex
Definition XrdClTaskManager.hh:157
TaskManager()
Constructor.
TaskList pToBeUnregistered
Definition XrdClTaskManager.hh:153
bool Start()
Start the manager.
XrdSysMutex pMutex
Definition XrdClTaskManager.hh:156
uint16_t pResolution
Definition XrdClTaskManager.hh:151
~TaskManager()
Destructor.
void UnregisterTask(Task *task)
TaskSet pTasks
Definition XrdClTaskManager.hh:152
Interface for a task to be run by the TaskManager.
Definition XrdClTaskManager.hh:36
virtual time_t Run(time_t now)=0
std::string pName
Definition XrdClTaskManager.hh:66
void SetName(const std::string &name)
Set name of the task.
Definition XrdClTaskManager.hh:60
const std::string & GetName() const
Name of the task.
Definition XrdClTaskManager.hh:52
virtual ~Task()
Definition XrdClTaskManager.hh:38
Definition XrdSysPthread.hh:165
Definition XrdClAction.hh:34
Definition XrdClTaskManager.hh:138
bool operator()(const TaskHelper &th1, const TaskHelper &th2) const
Definition XrdClTaskManager.hh:139
Definition XrdClTaskManager.hh:129
TaskHelper(Task *tsk, time_t tme, bool ow=true)
Definition XrdClTaskManager.hh:130
Task * task
Definition XrdClTaskManager.hh:132
time_t execTime
Definition XrdClTaskManager.hh:133
bool own
Definition XrdClTaskManager.hh:134