since v12.20
The CustomEventHandler can be used to raise a CustomEvent to be processed by any appropriate CustomEventListener listening to that event. The corresponding CustomEventListener may also be located within another novomind iAGENT process. The event will be processed by any appropriate CustomEventListener within the same process or another connected and running iAGENT process. The CustomEventHandler can be used in the novomind iAGENT routing process, the novomind iAGENT Desk process, the novomind iAGENT Chat Agent process and also in the novomind iAGENT Core process.
Please annotate your implementation of CustomEventListener with at least one of these runtime annotations:
to ensure, that your plugin will be loaded during runtime within the desired novomind iAGENT process. Additionally annotate your plugin class with the runtime annotation CustomEventFilter and specify the names of the events in the annotation parameter that your plugin should listen to.
Example:
@MailAgentPlugin
@CustomEventFilter(names = { "myTestEvent" } )
public class MyCustomEventListener implements CustomEventListener {
@Inject
Logger log;
@Override
public void processEvent(CustomEvent customEvent) {
log.info("Processed {}", customEvent);
}
}
The example implements a plugin class within the novomind iAGENT Desk process listening to a CustomEvent with the name myTestEvent
.
Furthermore raise the event in any other plugin or bean component of any other app within any novomind iAGENT process by injecting the CustomEventHandler.
Example:
@CustomManagedBean("myActionBean")
public class MyActionBean implements CustomBean {
@Inject
Logger log
@Inject
CustomEventHandler customEventHandler;
public void action() {
try {
customEventHandler.raiseEvent(
new CustomEvent("myTestEvent")
.setAttribute("my-action", "test")
.setAttribute("any-key", "any-value"));
} catch (ValidationException e) {
log.error("Error raising test event", e);
}
}
}
The example implements a bean component that raises a CustomEvent to be processed by any specific CustomEventListener listening to that event, e.g. the MyCustomEventListener
plugin from the example above.
CustomEvents
are processed asynchronously that means raising an event does not provide any return value to wait for until the event has been received.
Although a thread pool is used to process CustomEvents
it is highly recommended not to implement the CustomEventListener
blocking or performing any long term operations within the processEvent
method.
The thread pool provides parallel event processing of CustomEvents
but also guarantees that CustomEvents
with the same name are processed sequentially to avoid similar CustomEvents
overtaking each other.
Please note that the maximum total size of data passed to a CustomEvent as attributes is limited to 100 kilo bytes of characters (not including the attribute keys). If the maximum size is exceeded, a ValidationException
will be thrown on raising the event.