Anda di halaman 1dari 18

1

Event Handling in AEM

Event Handling in AEM


Multiple ways to handle Events in AEM. Few of
them are:
JCR level using observation
Sling Level using sling API

Scheduled Events (Sling Scheduling)


CQ level using workflows and launchers

JCR Observation

Low level event handling

Deals directly with changes in JCR

Events like addition of node, deletion of node,


change in properties etc are handled.

Event listeners defined through code listen to events


specified.

Brings in overhead in terms of additional


development for performance and filtering events.

R Observation - Interface EventListener


Registered via ObservationManager object
Works Asynchronously
onEvent method that gets called when event occurs
public void onEvent(EventIterator events)

CR Observation - Interface ObservationManager

Acquired via workspace instacnce using getObservationManager() method


Allows registration and deregistration of event listeners
Three methods:

public void addEventListener(


EventListener listener,
int eventTypes,
String absPath,
boolean isDeep,
String uuid,
String nodeTypeName,
boolean noLocal) throws RepositoryException

public void removeEventListener(EventListener listener) throws


RepositoryException

public EventListenerIterator getRegisteredEventListeners() throws


RepositoryException

CR Observation - Interface Event

Contains details about the event fired.


Static constants of type of events:
static int NODE_ADDED
static int NODE_REMOVED
static int NODE_MOVED
static int PERSIST
static int PROPERTY_ADDED
static int PROPERTY_CHANGED
static int PROPERTY_REMOVED
Methods returning info about event:
String getPath() throws RepositoryException
int getType()
String getUserID()
String getIdentifier() throws RepositoryException
Map getInfo() throws RepositoryException
String getUserData() throws RepositoryException
long getDate() throws RepositoryException

Sling Event Handling

Events are handled using EventHandler interface

Events like Replication event, JCR events etc can be


handled using Sling API.

User defined events can be published using


EventAdmin service.

Event handling is relatively easier using Sling API.

ling Event handling- Interface EventHandler


handleEvent method gets called when event occurs
public void handleEvent(Event event)
Handles events of a particular Topic.
This topic is specified as annotation.

10

EventHandler black listing


EventAdmin, that initiates the events, has a time-out
defined for event to be handled by a handler.
Any event being handled by a handler after 5 seconds
of event occurrence, gets blacklisted.
To avoid this, use JobProcessor implementation to
handle events via Jobs.
Event gets processed in process() method.

11

Sling Scheduling

We can schedule events by using cron jobs

A cron expression specifies the frequency with which the event


should occur

A cron expression is string consisting of six-seven subexpressions each separated by a space.

An example of cron expression:


0 15 10 ? * *

Fire at 10:15 AM everyday

Implementation wise, its just an implementation of Runnable


Interface with sling property annotations.

12

Sling Scheduling

13

Workflows

Helps automate process to manage resources and publish content

Comprises of a series of steps and each step accomplishes a discrete


task

Important terms:

Model The container of workflow

Step Individual step of workflow

Transition Transition of one step to other

Workitem The task of the workflow that the workflow will do

Payload Data that goes along the workflow process

Lifecycle The lifecycle of the workflow

Inbox Indicates step to be performed by user

14

Workflows
Model:

Workflow-nodes + Workflow-transitions

Kind of entity enclosing the entire process

Has a start node and an end node

15

Workflow
Step:

Participant Step: User interference related

Process Step: System related (automatic execution)

Container: Placeholder for another model

OR Split/Join Step: Decision based step

AND Split/Join Step: Decision based step

16

Workflows
WorkItem, Payload, Inbox

17

18

References
http://blogs.adobe.com/experiencedelivers/experience-management/event_handling_incq/

https://helpx.adobe.com/experience-manager/using/events.html
http://techagyan.blogspot.com/2015/02/aem-event-handling-and-filtering.html
https://osgi.org/javadoc/r4v42/org/osgi/service/event/EventHandler.html
https://osgi.org/javadoc/r4v42/org/osgi/service/event/Event.html
http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/observation/ObservationManager.html

http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/observation/EventListener.html
https://docs.adobe.com/docs/en/aem/6-1/develop/extending/workflows.html

Anda mungkin juga menyukai