Event listener is responsible for JCR level events which means it can capture events related to changes in the content repository.
Following are the events to which an event listener listens:
Event.NODE_ADDED
Event.NODE_MOVED
Event.NODE_REMOVED
Event.PERSIST
Event.PROPERTY_ADDED
Event.PROPERTY_CHANGED
Event.PROPERTY_REMOVED
How to listen to an JCR event?
An event is listened by implementing EventListener interface which belongs to javax.jcr.observation package.
Listener Implementation will consist of following three methods:
activate(): This method helps registering the listener by adding event listener to the observation manager. Following is the method to register an event listener. Objects.requireNonNull(session).getWorkspace().getObservationManager(). addEventListener(EventListener listener, int eventTypes, String absPath, boolean isDeep, String[] uuid, String[] nodeTypeName, boolean noLocal)
deactivate(): This method will unbind the event listener we bound in activate method.
onEvent(): This method is executed when an event is listened. The business logic is written inside this method.
That's all for today! If you've found this blog post informative or helpful, I’d greatly appreciate it if you could give it a like. It keeps me motivated 💛
Enjoying my ad-free blog? Support by buying me a coffee! I've kept this space ad-free, sponsoring it myself to maintain its purity. Your contribution would help keep the site afloat and ensure quality content. Thanks for being part of this ad-free community.