I want to delve into more detail of the Active Object’s Activation Queue or Scheduler.
The Proxy enqueues methods for the servant (passive) object and the Scheduler dequeues and invokes these methods against the Servant. Methods are enqueued in the Proxy (and Client) thread, and methods are dequeued in the Scheduler’s own thread and invoked in that thread as well. As we saw in the previous post, the calls can be closures that we use to provide values to the Future Value objects held by the client.
The Activation scheduler run’s execution in its own thread while new method requests are enqueued in the client’s context thread. I use a simple generic queue and protect it with a Monitor.
Some method requests may have Guards, this means that the method may only be executed when the Guard returns true. The sample provided in Lavender and Schmidt’s Paper had an implementation of a Queue as a bounded buffer. Their implementation would enumerate the queue, check guards for actions, dequeue those where guards return true and then call their methods.
With my implementation of a Monitor on the Queue the use of an enumerator does not work well. I want to keep locks as short as possible, so I rather implemented a second private list of method requests that have failed to pass the Guard. I check this list when new actions are added (and the FDataReady event is set) and I also re-check the list when any action is successfully executed.
In a later post you will see how we compose the Scheduler with the Proxy, but for now its sufficient to know that the Proxy will schedule request for its servant on the Scheduler. Events will be fired in order as Guards allow.
You can download the source code. Please comment or contribute.