Elastic Social Manual / Version 2307
Table Of Contents
Differing from the CoreMedia CMS Content Server and its Unified
API the ModelServiceListener
is a local listener at
ModelService
that is only notified before and after Model#save()
and Model#remove()
calls from models that were created from that
ModelService
.
To register a ModelServiceListener
at the ModelService
it has to be
in the application context. This can be achieved by annotating the ModelServiceListener
implementation with javax.inject.Named
and using component scanning.
For a fault-tolerant processing of ModelServiceListener
events, it is recommended to
immediately queue the work to be done with the TaskQueueService
. A listener following this
pattern looks like this:
@Named public class MyObjectsModelServiceListener extends ModelServiceListenerBase { @Inject private TaskQueueService taskQueueService; private MyTask defer() { return taskQueueService.queue("mytasks", MyTasks.class); } public void afterSave(Collection<? extends Model> models) { defer().processSave(models); } public void afterRemove(Collection<? extends Model> models) { defer().processRemove(models); } }
Example 4.9. Listener