Lock Processing Example Flow
The following example demonstrates common locking requirements.
Two agents receive messages that require changes to one Customer instance.
Note that event preprocessors are multi-threaded (see Event Preprocessors for more details).
- A message comes into a channel on Agent A: a change to a customer address. TIBCO BusinessEvents dequeues the message from the queue, deserializes the message to an event, and calls the event preprocessor function. The preprocessor acquires a lock using the customer’s
extID
as the key:Cluster.DataGrid.Lock(Customer@extId, -1, false);
This function causes the thread to stop until it gets the lock. In this example, the thread gets the lock.
- Only one thread handles the RTC. Other event preprocessor threads go into a queue. During the RTC, a rule executes and modifies the customer address. After RTC completes, the post RTC phase begins: the address change is written to L1 cache, the cluster cache, and the backing store in parallel. Messages arising from the RTC are sent.
- After the post RTC actions are completed, the lock is released.
- Agent B that contains the same function shown in Step 1 (hence the same locking string) can now acquire the lock that is the function returns
true
. It proceeds with rule execution and post RTC phase and finally releasing the lock.