Channels and Events : Event Preprocessors

Event Preprocessors
Event preprocessors are rule functions with one argument of type simple event. (Event preprocessors are not used for time or advisory events.) Event preprocessors are multithreaded. They perform tasks after an incoming message arrives at the destination and is transformed into a simple event, but before it is asserted into the Rete network (if it is — events can be consumed in the event preprocessor).
Time events do not go through an event preprocessor. If you are using cache-only cache mode, take care when designing rules that execute as a result of a time event. For example, a rule that has a join condition using a time event and a concept would not execute if the concept is not loaded in the Rete network.
You can aggregate events, edit events, and perform other kinds of event enrichment in a preprocessor. You can also use preprocessors as explained below.
Setting locks if concurrency features are used
You must set locks in the preprocessor when concurrency features are used to protect concept instances during RTC. Locking ensures that updates to concept instances during an RTC do not conflict with another set of updates to the same concept instances in another RTC. Locks are released at the end of the RTC.
Loading cache only entities
If you are using the Cache Only cache mode for any entities, you must also load the relevant entities from the cache using an event preprocessor.
Improving project efficiency
You can also use preprocessors to improve performance by avoiding unnecessary RTCs in the inference engine. For example you can consume events that are not needed. Another way to use the preprocessor for efficient processing is to transfer an event’s contents to a new concept that is not processed by the agent's set of locally active rules. Such a concept is automatically asserted, does not trigger rules, and is saved into the cache (depending on OM configuration) where it is available for processing by any agent as needed.
Preprocessor Use Guidelines
Consuming events in a preprocessor is allowed  It can be useful in some applications and reduces the flow of messages into the Rete network.
You can only modify events before they are asserted into the Rete network  Rule evaluation depends on event values at time of assertion, so values can be changed only before assertion, that is, in the preprocessor.
You can create concepts but not modify or delete existing concepts  Modifying or deleting concepts that already exist in the system could disrupt an RTC. You can modify or delete concepts that were created in the same preprocessor, however.
Concepts created in a preprocessor are not asserted until the RTC starts. So, for example, after one event preprocessor ends and before its RTC begins, no other preprocessor can access the new concept.
See Also
Loading Cache-Only Objects into the Rete Network
Using Locks to Ensure Data Integrity Within and Across Agents