Author: cziegeler
Date: Thu Dec 31 10:09:38 2009
New Revision: 894800

URL: http://svn.apache.org/viewvc?rev=894800&view=rev
Log:
SLING-770 : Send notification event when a job is cancelled

Modified:
    sling/trunk/bundles/extensions/event/pom.xml
    
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
    
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java

Modified: sling/trunk/bundles/extensions/event/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/pom.xml?rev=894800&r1=894799&r2=894800&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/pom.xml (original)
+++ sling/trunk/bundles/extensions/event/pom.xml Thu Dec 31 10:09:38 2009
@@ -29,7 +29,7 @@
 
     <artifactId>org.apache.sling.event</artifactId>
     <packaging>bundle</packaging>
-    <version>2.1.1-SNAPSHOT</version>
+    <version>2.2.0-SNAPSHOT</version>
 
     <name>Apache Sling Event Support</name>
     <description>
@@ -55,7 +55,7 @@
                 <configuration>
                     <instructions>
                         <Export-Package>
-                            org.apache.sling.event;version=2.1.0
+                            org.apache.sling.event;version=2.2.0
                         </Export-Package>
                         <Private-Package>
                             org.apache.sling.event.impl
@@ -156,12 +156,10 @@
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.jmock</groupId>
             <artifactId>jmock-junit4</artifactId>
-            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>

Modified: 
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java?rev=894800&r1=894799&r2=894800&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
 (original)
+++ 
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
 Thu Dec 31 10:09:38 2009
@@ -125,6 +125,42 @@
     public static final String PROPERTY_TIMED_EVENT_DATE = "event.timed.date";
 
     /**
+     * Notification events for jobs.
+     */
+
+    /** Asynchronous notification event when a job is started.
+     * The property {...@link #PROPERTY_NOTIFICATION_JOB} contains the job 
event and the
+     * property {...@link org.osgi.service.event.EventConstants#TIMESTAMP} 
contains the
+     * timestamp of the event (as a Long).
+     * @since 2.2 */
+    public static final String TOPIC_JOB_STARTED = 
"org/apache/sling/event/notification/job/START";
+
+    /** Asynchronous notification event when a job is finished.
+     * The property {...@link #PROPERTY_NOTIFICATION_JOB} contains the job 
event and the
+     * property {...@link org.osgi.service.event.EventConstants#TIMESTAMP} 
contains the
+     * timestamp of the event (as a Long).
+     * @since 2.2 */
+    public static final String TOPIC_JOB_FINISHED = 
"org/apache/sling/event/notification/job/FINISHED";
+
+    /** Asynchronous notification event when a job failed.
+     * The property {...@link #PROPERTY_NOTIFICATION_JOB} contains the job 
event and the
+     * property {...@link org.osgi.service.event.EventConstants#TIMESTAMP} 
contains the
+     * timestamp of the event (as a Long).
+     * @since 2.2 */
+    public static final String TOPIC_JOB_FAILED = 
"org/apache/sling/event/notification/job/FAILED";
+
+    /** Asynchronous notification event when a job is cancelled.
+     * The property {...@link #PROPERTY_NOTIFICATION_JOB} contains the job 
event and the
+     * property {...@link org.osgi.service.event.EventConstants#TIMESTAMP} 
contains the
+     * timestamp of the event (as a Long).
+     * @since 2.2 */
+    public static final String TOPIC_JOB_CANCELLED = 
"org/apache/sling/event/notification/job/CANCELLED";
+
+    /** Property containing the job event.
+     * @since 2.2 */
+    public static final String PROPERTY_NOTIFICATION_JOB = 
"event.notification.job";
+
+    /**
      * Utility Methods
      */
 

Modified: 
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=894800&r1=894799&r2=894800&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
 (original)
+++ 
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
 Thu Dec 31 10:09:38 2009
@@ -25,6 +25,7 @@
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -55,6 +56,7 @@
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
+import org.osgi.service.event.EventConstants;
 
 
 /**
@@ -1131,6 +1133,9 @@
         synchronized ( this.processingEventsList ) {
             // if the event is still in the processing list, we confirm the ack
             final Object ack = this.processingEventsList.remove(eventNodePath);
+            if ( ack != null ) {
+                this.sendNotification(EventUtil.TOPIC_JOB_STARTED, job);
+            }
             return ack != null;
         }
 
@@ -1170,7 +1175,12 @@
                 newProperties.put(EventUtil.PROPERTY_JOB_RETRY_COUNT, 
retryCount);
                 newProperties.put(EventUtil.PROPERTY_JOB_RETRIES, retries);
                 job = new Event(job.getTopic(), newProperties);
+                this.sendNotification(EventUtil.TOPIC_JOB_CANCELLED, job);
+            } else {
+                this.sendNotification(EventUtil.TOPIC_JOB_FAILED, job);
             }
+        } else {
+            this.sendNotification(EventUtil.TOPIC_JOB_FINISHED, job);
         }
         final boolean parallelProcessing = 
job.getProperty(EventUtil.PROPERTY_JOB_QUEUE_NAME) != null
                                         || 
job.getProperty(EventUtil.PROPERTY_JOB_PARALLEL) != null;
@@ -1534,6 +1544,18 @@
         }
     }
 
+    /**
+     * Helper method for sending the notification events.
+     */
+    private void sendNotification(final String topic, final Event job) {
+        final EventAdmin localEA = this.eventAdmin;
+        if ( localEA != null ) {
+            final Dictionary<String, Object> props = new Hashtable<String, 
Object>();
+            props.put(EventUtil.PROPERTY_NOTIFICATION_JOB, job);
+            props.put(EventConstants.TIMESTAMP, System.currentTimeMillis());
+            localEA.postEvent(new Event(topic, props));
+        }
+    }
 
     private static final class StartedJobInfo {
         public final Event event;


Reply via email to