# Poco

# class ActiveDispatcher

Library: Foundation
Package: Threading
Header: Poco/ActiveDispatcher.h

## Description

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.

## Inheritance

Direct Base Classes: Runnable

All Base Classes: Runnable

## Member Summary

Member Functions: cancel, run, start, stop

Inherited Functions: run

## Constructors

### ActiveDispatcher

ActiveDispatcher();

Creates the ActiveDispatcher.

### ActiveDispatcher

ActiveDispatcher(
Thread::Priority prio
);

Creates the ActiveDispatcher and sets the priority of its thread.

## Destructor

### ~ActiveDispatcher

~ActiveDispatcher() override;

Destroys the ActiveDispatcher.

## Member Functions

### cancel

void cancel();

Cancels all queued methods.

### start

void start(
ActiveRunnableBase::Ptr pRunnable
);

Adds the Runnable to the dispatch queue.

### run

void run() override;

See also: Poco::Runnable::run()

### stop

void stop();