Introduction

According to the active object pattern, the method execution should be separate from the method call. It is called an active object because, according to this pattern, every object owns its thread. Each method invocation is not performed instantly. Instead, it is stored in an activation list. A scheduler will decide which method to execute from the list.

Structure

The active object design pattern has the following components.

Proxy

There is a Proxy for the member functions in the active object. It triggers the construction of a request object which goes to the activation list and returns a future. The proxy runs in the client thread.

Method request

A method request includes all context information to be executed later.

Activation list

The activation list has the pending request objects. It decouples the client from the active object thread.

Scheduler

The scheduler runs in the thread of the active object. It decides which request from the activation List is executed.

Servant

The servant implements the member functions of the active objects. It supports the interface of the proxy.

Future

The future is created by the proxy. It is only necessary if the request object returns a result. The client uses the future to get the result of the request object.

Dynamic behavior

Here’s the sequence of events that transpires.

Request construction and scheduling

  • The client invokes the method on the Proxy.
  • The Proxy creates a request and passes it to the scheduler.
  • The scheduler enqueues the request on the activation list and returns a future to the client if the request returns something.

Member function execution

  • The scheduler determines which request becomes runnable.
  • It removes the request from the activation list and dispatches it to the servant.

Completion

  • It stores the result of the request object in the future.
  • It destructs the request object and the future when the client has the result.

The following illustration depicts the flow of events described above.

Get hands-on with 1400+ tech skills courses.