Reference‎ > ‎

Services: Event service

The event service allows you to be notified of logic events as they occur, in real time.

To register an event service, you must implement the interface com.autobizlogic.abl.event.LogicListener, and register the implementing class. You can do so in two ways.

In the config file

You can specify a class in the ABLConfig.properties file (you can specify more than one class by separating them with commas). If you do so, the class (or classes) will be instantiated when the ABL engine is activated (typically when Hibernate starts up), and will receive notifications as long as the ABL engine is active. An example of the entry in ABLConfig.properties file:

globalEventListeners = autobizlogic.demo.buslogicdemospring.DemoEventListener


Programmatically

You can also register your listener class by calling:

LogicListener listener = new MyEventListener();
com.autobizlogic.abl.event.GlobalLogicEventHandler.getGlobalLogicListenerHandler().addLogicListener(listener);

However, this is less preferred, because this API is subject to change.


Events

Once your listener is registered, it will receive LogicEvents, or rather, instances of the various subclasses of LogicEvent. Note that this applies to all sessions and transactions: if you need to discriminate between events of different sessions and transactions (and you usually do), you'll need to call the event's getContext, which returns an instance of LogicTransactionContext which is unique for each transaction.

Each subclass of LogicEvent contains information specific to the type of event. For instance, LogicAfterConstraintEvent points to the constraint that has just been fired, and the ConstraintFailure if the constraint in fact has failed. All events also point to the persistent bean for which the rule fired, and they also have the amount of time (in nanoseconds -- as best as the system can resolve time) taken up by the rule.

Implementing an event listener

Because event listeners are invoked in real time as the rules are fired, they need to be careful about the amount of time they take. If they are slow, they will slow down the entire system. Also, they need to be thread-safe.

Comments