JBoss.org Community Documentation
The JBoss DNA ObservationService
is responsible for listening to one or more JCR repositories
and multiplexing the events to its listeners. Unlike JCR events, this framework embeds in the events the
name of the repository and workspace that can be passed to a SessionFactory
to obtain a session
to the repository in which the change occurred. This simple design makes it very easy for JBoss DNA to
concurrently work with multiple JCR repositories.
Configuring an ObservationService is pretty easy, especially if you reuse the same SessionFactory
supplied to the SequencingService. Here's an example:
this.observationService = new ObservationService(sessionFactory); this.observationService.getAdministrator().start();
Both the ObservationService implement AdministeredService
, which has a ServiceAdministrator
used to
start, pause, and shutdown the service. In other words, the lifecycle of the services are managed in the same way.
After the observation service is started, listeners can be added. The SequencingService
implements the required
interface, and so it may be registered directly:
observationService.addListener(sequencingService);
Finally, the observation service must be wired to monitor one or your JCR repositories. This is done with
one of the monitor(...)
methods:
int eventTypes = Event.NODE_ADDED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED; observationService.monitor("Main Repository/Workspace1", eventTypes);
At this point, the observation service is listening to a JCR repository, and forwarding the appropriate events to the sequencing service, which will asynchronously process the changes and sequence the information added to or changed in the repository.