SObjectizer
5.5
|
A new type of agents is introduced in v.5.3.0 – ad-hoc agents. They are agents which could be constructed and registered without necessity of defining dedicated C++ class.
To construct ad-hoc agent is necessary to call define_method for cooperation object. This method returns a special proxy object which is used to definition of behaviour of new agent. For example this method chain creates agents which handles a message and a signal.
Ad-hoc agent uses default cooperation dispatcher binder:
But another dispatcher binder could be specified as an argument for define_agent() method:
Ordinary agents have so_evt_start() and so_evt_finish() methods which are called at the start and at the end of agent work. Similar behaviour could be specified to ad-hoc agents by on_start() and on_finish() methods chains:
Ordinary agents could reimplement so_exception_reaction() method to specify reaction to non-handled exceptions. Ad-hoc agents do not have that method. If ad-hoc agent should specify some reaction to non-handled exception this could be done by exception_reaction() method chain:
Ad-hoc agents have the following major differences from ordinary agents.
Ad-hoc agents have no access to so_environment. An ordinary agent could do:
Ad-hoc agent should store reverence to so_enviroment as a capture variable:
Ad-hoc agents cannot have states. Ordinary agents could define states by creating so_5::rt::state_t objects and then switching from one state to another. Ad-hoc agents have only one state which is hidden from the developer.
Ad-hoc agents have no access to the cooperation they belong. The ordinary agent could do:
But ad-hoc agent cannot.
Lambda functions which are used as event handlers for ad-hoc agents should have one of the following prototypes:
It is impossible to pass event_data_t object as argument to ad-hoc agent's event. So it is impossible to resend the same message object from ad-hoc agent's event (because there is not access to so_5::rt::event_data_t::make_reference() method).