class Poco::ActiveDispatcher
Overview
This class is used to implement an active object with strictly serialized method execution. More…
#include <ActiveDispatcher.h> class ActiveDispatcher: protected Poco::Runnable { public: // construction ActiveDispatcher(); ActiveDispatcher(Thread::Priority prio); // methods void start(ActiveRunnableBase::Ptr pRunnable); void cancel(); protected: // methods virtual void run(); void stop(); };
Inherited Members
public: // methods virtual void run() = 0;
Detailed Documentation
This class is used to implement an active object with strictly serialized method execution.
An active object, which is an ordinary object containing ActiveMethod members, executes all active methods in their own thread. This behavior does not fit the “classic” definition of an active object, which serializes the execution of active methods (in other words, only one active method can be running at any given time).
Using this class as a base class, the serializing behavior for active objects can be implemented.
The following example shows how this is done:
class ActiveObject: public ActiveDispatcher { public: ActiveObject(): exampleActiveMethod(this, &ActiveObject::exampleActiveMethodImpl) { } ActiveMethod<std::string, std::string, ActiveObject, ActiveStarter<ActiveDispatcher> > exampleActiveMethod; protected: std::string exampleActiveMethodImpl(const std::string& arg) { ... } };
The only things different from the example in ActiveMethod is that the ActiveObject in this case inherits from ActiveDispatcher, and that the ActiveMethod template for exampleActiveMethod has an additional parameter, specifying the specialized ActiveStarter for ActiveDispatcher.
Construction
ActiveDispatcher()
Creates the ActiveDispatcher.
ActiveDispatcher(Thread::Priority prio)
Creates the ActiveDispatcher and sets the priority of its thread.
Methods
void start(ActiveRunnableBase::Ptr pRunnable)
Adds the Runnable to the dispatch queue.
void cancel()
Cancels all queued methods.
virtual void run()
Do whatever the thread needs to do.
Must be overridden by subclasses.