Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 22D5CD2A5 for ; Fri, 1 Mar 2013 08:57:43 +0000 (UTC) Received: (qmail 81860 invoked by uid 500); 1 Mar 2013 08:57:43 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 81778 invoked by uid 500); 1 Mar 2013 08:57:42 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 81754 invoked by uid 99); 1 Mar 2013 08:57:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Mar 2013 08:57:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Mar 2013 08:57:40 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3EB3623889E0; Fri, 1 Mar 2013 08:57:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1451530 - /sling/site/trunk/content/documentation/tutorials-how-tos/how-to-manage-events-in-sling.mdtext Date: Fri, 01 Mar 2013 08:57:21 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130301085721.3EB3623889E0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 props = new Hashtable(); + 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());