SObjectizer
5.7
|
By default in SObjectizer all event handlers are assumed to be not thread safe. Standard dispatchers guarantee that not_thread_safe event handlers will work alone and only on the context of one working thread.
A new feature in v.5.4.0 allows to specify that event handler is a thread safe handler. It means that event handler doesn't change state of agent (or does it in thread safe manner). If user specifies a event handler as thread_safe handler it gives to SObjectizer's dispatcher a right of running thread-safe handlers of the same agent in parallel on the different working threads. But with the following conditions:
a not_thread_safe event handler can't be started until there is any other running event handler of the agent. A start of not_thread_safe event handler will be delayed until all already running event handlers finish their work; no one event handler can't be started until there is a working not_thread_safe event handler; no one thread_safe event handler can't be started until there is a working not_thread_safe event handler.
To specify thread_safe event handler it is necessary to pass additional argument to event() method in subscription chain:
As a example of thread_safe and not_thread_safe event handler lets see an agent for performing cryptography operations: encrypting and decrypting. This operations are stateless and can be done in parallel. But the agent must be reconfigured from time to time. The reconfiguration operation is stateful and event handler for reconfigure message is not_thread_safe.
User must only specify the thread_safety flag for those event handlers. All other work will be done by SObjectizer. It means that evt_encrypt and evt_decrypt will be running in parallel until an occurrence of msg_reconfigure. SObjectizer will wait until all previously started evt_encrypt/evt_decrypt finish their work and only then will start evt_reconfigure. While evt_reconfigure is working all other event handlers will be delayed and will be started only after return from evt_reconfigure:
Because event handlers can be either ordinary event handlers or synchronous service requests handlers (it depends not on handler but on message sender or service caller) it means that thread_safe event handler can be used for parallel processing of several parallel service requests.