Observation

This module enables applications to register interest in events that describe changes to a workspace, and then monitor and respond to those events. The observations mechanism dispatches events when a persistent change is made to the workspace.

How to define an EventListener.

Currently two types of event listeners are supported, you can either use your own EventListener class or specify a command to be executed in case of an event.

Under the configuration node there is a listeners node and is there where you will add yours.

Step 1. Create a new content node and give it a meaningful name.

Step 2. Create node data items:
  • mandatory
    • active: true/false, default false (the eventlistener won't be activated unless you set active to true and all mandatory fields are defined)
    • listener: (content node)
      • class: the name of your custom EventListener class or the name of the class to handle commands: info.magnolia.module.observation.commands.CommandEventListener
If we want to run a command we need to create a sub content node named command and the following parameters under listener another content node - command: Example of a command with node type restriction
        • class: of the command class
        • one by one the parameters to send to the command, for that the command class should have getters and setters for this variables not all the commands have this.
      • a content node named params with the parameters to send to the command, not all the commands need this.
      • nodeType: the command will just be run for that node type.
    • eventTypes: the name of the events that will be listener for, possible values: NODE_ADDED, NODE_REMOVED, PROPERTY_ADDED, PROPERTY_CHANGED, PROPERTY_REMOVED. If setting more than one write them separated by commas ",". By default it will listen for all the events
    • path: the absolute path from which the event will be triggered.
    • repository: name of the repository where the event will be listened for.
  • optional:
    • description: description of what the eventListener does
    • delay: milliseconds to wait before activating the event listener
    • includeSubNodes: true/false, false by default
    • maxDelay: max number of milliseconds to wait before activating the event listener
    • nodeType: name of node that trigger events, if null (default) it will be triggered for all node types
Example of a simple custom event listener