close

Filter

Elastic Social Manual / Version 2110

Table Of Contents

4.4 Listening to Model Changes

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


Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.