You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2013/03/01 09:57:21 UTC

svn commit: r1451530 - /sling/site/trunk/content/documentation/tutorials-how-tos/how-to-manage-events-in-sling.mdtext

Author: cziegeler
Date: Fri Mar  1 08:57:20 2013
New Revision: 1451530

URL: http://svn.apache.org/r1451530
Log:
CMS commit to sling by cziegeler

Modified:
    sling/site/trunk/content/documentation/tutorials-how-tos/how-to-manage-events-in-sling.mdtext

Modified: sling/site/trunk/content/documentation/tutorials-how-tos/how-to-manage-events-in-sling.mdtext
URL: http://svn.apache.org/viewvc/sling/site/trunk/content/documentation/tutorials-how-tos/how-to-manage-events-in-sling.mdtext?rev=1451530&r1=1451529&r2=1451530&view=diff
==============================================================================
--- sling/site/trunk/content/documentation/tutorials-how-tos/how-to-manage-events-in-sling.mdtext (original)
+++ sling/site/trunk/content/documentation/tutorials-how-tos/how-to-manage-events-in-sling.mdtext Fri Mar  1 08:57:20 2013
@@ -1,6 +1,5 @@
 Title: How to Manage Events in Sling
 
-
 Apache Sling provides some mechanisms and support for managing events.
 
 The event mechanism is leveraging the OSGi Event Admin Specification (OSGi Compendium 113). The OSGi API is very simple and lightweight. Sending an event is just generating the event object and calling the event admin. Receiving the event is implementing a single interface and declaring through properties which topics one is interested in. 
@@ -46,7 +45,16 @@ You can refer to the [org.apache.sling.a
 
 ## Sending Job Events
 
-To send a job event the service needs to implement the **org.osgi.service.event.EventHandler** and **org.apache.sling.event.JobProcessor** interfaces:
+To send an event the following code can be used: 
+    #!java
+    public void sendEvent() {
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(JobUtil.PROPERTY_JOB_TOPIC, JOB_TOPIC);
+        props.put("resourcePath", RESOURCE_PATH);
+        final Event myEvent = new Event(JobUtil.TOPIC_JOB, props);
+        eventAdmin.sendEvent(myEvent);
+
+However, for our example, to send a job event the service needs to implement the **org.osgi.service.event.EventHandler** and **org.apache.sling.event.JobProcessor** interfaces:
 
 
     #!java
@@ -79,6 +87,15 @@ The **org.osgi.service.event.EventHandle
 
 The **org.apache.sling.event.JobProcessor#process(Event event)** method needs to be implemented:
 
+Its logic is as follows:
+
+* The OSGI event is analyzed.
+* If the event is a file that has been added to */tmp/dropbox*:
+* * An event is created with 2 properties:
+* * * A property to set the event as a job event.
+* * * A property for the file path.
+* * The job event is sent to all the listeners that subscribe to the topic of the event.
+
     #!java
     public boolean process(Event event) {
     
@@ -132,6 +149,10 @@ To move the files the service needs to i
 
 Some class fields need to be defined:
 
+* The default log.
+* The references to the SlingRepository and the JcrResourceResolverFactory services, which are used in the implementation.
+* The destination paths of the files.
+
     #!java
     /** Default log. */
     protected final Logger log = LoggerFactory.getLogger(this.getClass());