How to combine many agents onto a single thread¶
Problem¶
You've constructed your process out of multiple agents, but want several of them to run on the same thread.
Solution¶
Combine your agents into a CompositeAgent
, and schedule the CompositeAgent
in an AgentRunner
.
Sample¶
1 2 3 4 5 6 7 |
|
Discussion¶
The agents within a CompositeAgent
share the same thread and idle strategy. Their duty cycles are called sequentially, in the order they are added in the CompositeAgent
constructor. When you run a Media Driver with a SHARED Threading Strategy, the Conductor, Sender and Receiver agents are scheduled within a CompositeAgent
.
The default thread name is a composite of the roleName provided for each agent. If needed, the CompositeAgent's thread name can be set using roleName()
.
An alternative approach to do this is to use an AgentInvoker
, and run invoke()
within the duty cycle of your other agent.