class Poco::TaskManager
Overview
The TaskManager manages a collection of tasks and monitors their lifetime. More…
#include <TaskManager.h> class TaskManager { public: // typedefs typedef AutoPtr<Task> TaskPtr; typedef std::list<TaskPtr> TaskList; // fields static const int MIN_PROGRESS_NOTIFICATION_INTERVAL; // construction TaskManager(); TaskManager(ThreadPool& pool); // methods void start(Task* pTask); void cancelAll(); void joinAll(); TaskList taskList() const; int count() const; void addObserver(const AbstractObserver& observer); void removeObserver(const AbstractObserver& observer); protected: // methods void postNotification(const Notification::Ptr& pNf); void taskStarted(Task* pTask); void taskProgress( Task* pTask, float progress ); void taskCancelled(Task* pTask); void taskFinished(Task* pTask); void taskFailed( Task* pTask, const Exception& exc ); };
Detailed Documentation
The TaskManager manages a collection of tasks and monitors their lifetime.
A TaskManager has a built-in NotificationCenter that is used to send out notifications on task progress and task states. See the TaskNotification class and its subclasses for the various events that result in a notification. To keep the number of notifications small, a TaskProgressNotification will only be sent out once in 100 milliseconds.
Construction
TaskManager()
Creates the TaskManager, using the default ThreadPool.
TaskManager(ThreadPool& pool)
Creates the TaskManager, using the given ThreadPool.
Methods
void start(Task* pTask)
Starts the given task in a thread obtained from the thread pool.
The TaskManager takes ownership of the Task object and deletes it when it it finished.
void cancelAll()
Requests cancellation of all tasks.
void joinAll()
Waits for the completion of all the threads in the TaskManager ‘s thread pool.
Note: joinAll() will wait for ALL tasks in the TaskManager ‘s ThreadPool to complete. If the ThreadPool has threads created by other facilities, these threads must also complete before joinAll() can return.
TaskList taskList() const
Returns a copy of the internal task list.
int count() const
Returns the number of tasks in the internal task list.
void addObserver(const AbstractObserver& observer)
Registers an observer with the NotificationCenter.
Usage:
Observer<MyClass, MyNotification> obs(*this, &MyClass::handleNotification); notificationCenter.addObserver(obs);
void removeObserver(const AbstractObserver& observer)
Unregisters an observer with the NotificationCenter.
void postNotification(const Notification::Ptr& pNf)
Posts a notification to the task manager’s notification center.