Library: Foundation
Package: Threading
Header: Poco/Activity.h
This template class helps to implement active objects. An active object uses threads to decouple method execution from method invocation, or to perform tasks autonomously, without intervention of a caller.
An activity is a (typically longer running) method that executes within its own task. Activities can be started automatically (upon object construction) or manually at a later time. Activities can also be stopped at any time. However, to make stopping an activity work, the method implementing the activity has to check periodically whether it has been requested to stop, and if so, return. Activities are stopped before the object they belong to is destroyed. Methods implementing activities cannot have arguments or return values.
Activity objects are used as follows:
class ActiveObject { public: ActiveObject(): _activity(this, &ActiveObject::runActivity) { ... } ... protected: void runActivity() { while (!_activity.isStopped()) { ... } } private: Activity<ActiveObject> _activity; };
Direct Base Classes: Runnable
All Base Classes: Runnable
Member Functions: isRunning, isStopped, run, start, stop, wait
Inherited Functions: run
typedef typename RunnableAdapterType::Callback Callback;
typedef RunnableAdapter < C > RunnableAdapterType;
Activity(
C * pOwner,
Callback method
);
Creates the activity. Call start() to start it.
~Activity();
Stops and destroys the activity.
bool isRunning() const;
Returns true if the activity is running.
bool isStopped() const;
Returns true if the activity has been requested to stop.
void start();
Starts the activity by acquiring a thread for it from the default thread pool.
void stop();
Requests to stop the activity.
void wait();
Waits for the activity to complete.
void wait(
long milliseconds
);
Waits the given interval for the activity to complete. An TimeoutException is thrown if the activity does not complete within the given interval.
void run();
See also: Poco::Runnable::run()