incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r689919 - in /incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event: JobStatusProvider.java impl/AbstractRepositoryEventHandler.java impl/EventHelper.java impl/JobEventHandler.java
Date Thu, 28 Aug 2008 18:12:07 GMT
Author: cziegeler
Date: Thu Aug 28 11:12:07 2008
New Revision: 689919

URL: http://svn.apache.org/viewvc?rev=689919&view=rev
Log:
SLING-606 : Provide a method to cancel a job.

Modified:
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java?rev=689919&r1=689918&r2=689919&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java
Thu Aug 28 11:12:07 2008
@@ -29,6 +29,11 @@
 public interface JobStatusProvider {
 
     /**
+     * This is a unique identifer which can be used to cancel the job.
+     */
+    String PROPERTY_EVENT_ID = "slingevent:eventId";
+
+    /**
      * @deprecated Use {@link #getScheduledJobs(String)} instead.
      */
     @Deprecated
@@ -75,4 +80,18 @@
      * @return A non null collection.
      */
     Collection<Event> getAllJobs(String topic, Map<String, Object> filterProps);
+
+    /**
+     * Cancel this job.
+     * @param jobId The unique identifer as found in the property {@link #PROPERTY_EVENT_ID}.
+     */
+    void cancelJob(String jobId);
+
+    /**
+     * Cancel this job.
+     * This method can be used if the topic and the provided job id is known.
+     * @param topic The job topic as put into the property {@link EventUtil#PROPERTY_JOB_TOPIC}.
+     * @param jobId The unique identifer as put into the property {@link EventUtil#PROPERTY_JOB_ID}.
+     */
+    void cancelJob(String topic, String jobId);
 }

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java?rev=689919&r1=689918&r2=689919&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
Thu Aug 28 11:12:07 2008
@@ -36,6 +36,7 @@
 import org.apache.sling.engine.SlingSettingsService;
 import org.apache.sling.event.EventPropertiesMap;
 import org.apache.sling.event.EventUtil;
+import org.apache.sling.event.JobStatusProvider;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.osgi.service.component.ComponentContext;
@@ -103,7 +104,7 @@
     private static final String[] IGNORE_PROPERTIES = new String[] {
         EventUtil.PROPERTY_DISTRIBUTE,
         EventUtil.PROPERTY_APPLICATION,
-        EventHelper.NODE_PROPERTY_NODE_PATH,
+        JobStatusProvider.PROPERTY_EVENT_ID,
         EventUtil.JobStatusNotifier.CONTEXT_PROPERTY_NAME
     };
 
@@ -311,7 +312,7 @@
                 EventHelper.NODE_PROPERTY_PROPERTIES,
                 IGNORE_PREFIXES);
 
-        eventProps.put(EventHelper.NODE_PROPERTY_NODE_PATH, eventNode.getPath());
+        eventProps.put(JobStatusProvider.PROPERTY_EVENT_ID, eventNode.getPath());
         this.addEventProperties(eventNode, eventProps);
         try {
             final Event event = new Event(topic, eventProps);

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java?rev=689919&r1=689918&r2=689919&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
Thu Aug 28 11:12:07 2008
@@ -34,7 +34,6 @@
     public static final String NODE_PROPERTY_PROPERTIES = "slingevent:properties";
     public static final String NODE_PROPERTY_PROCESSOR = "slingevent:processor";
     public static final String NODE_PROPERTY_JOBID = "slingevent:id";
-    public static final String NODE_PROPERTY_NODE_PATH = "slingevent:nodePath";
     public static final String NODE_PROPERTY_FINISHED = "slingevent:finished";
     public static final String NODE_PROPERTY_TE_EXPRESSION = "slingevent:expression";
     public static final String NODE_PROPERTY_TE_DATE = "slingevent:date";

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=689919&r1=689918&r2=689919&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
Thu Aug 28 11:12:07 2008
@@ -33,6 +33,7 @@
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 
+import javax.jcr.Item;
 import javax.jcr.ItemExistsException;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
@@ -245,11 +246,12 @@
                 }
                 final EventInfo info = new EventInfo();
                 info.event = event;
-                final String nodePath = this.getNodePath(event);
+                final String jobId = (String)event.getProperty(EventUtil.PROPERTY_JOB_ID);
+                final String jobTopic = (String)event.getProperty(EventUtil.PROPERTY_JOB_TOPIC);
+                final String nodePath = this.getNodePath(jobTopic, jobId);
 
                 // if the job has no job id, we can just write the job to the repo and don't
                 // need locking
-                final String jobId = (String)event.getProperty(EventUtil.PROPERTY_JOB_ID);
                 if ( jobId == null ) {
                     try {
                         final Node eventNode = this.writeEvent(event, nodePath);
@@ -723,14 +725,11 @@
     /**
      * Create a unique node path (folder and name) for the job.
      */
-    private String getNodePath(Event event) {
-        final String jobTopic = ((String)event.getProperty(EventUtil.PROPERTY_JOB_TOPIC)).replace('/',
'.');
-        final String jobId = (String)event.getProperty(EventUtil.PROPERTY_JOB_ID);
-
+    private String getNodePath(final String jobTopic, final String jobId) {
         if ( jobId != null ) {
-            return jobTopic + "/" + filter(jobId);
+            return jobTopic.replace('/', '.') + "/" + filter(jobId);
         }
-        return jobTopic + "/Job " + UUID.randomUUID().toString();
+        return jobTopic.replace('/', '.') + "/Job " + UUID.randomUUID().toString();
     }
 
     /**
@@ -1236,6 +1235,41 @@
     }
 
 
+    /**
+     * @see org.apache.sling.event.JobStatusProvider#cancelJob(java.lang.String, java.lang.String)
+     */
+    public void cancelJob(String topic, String jobId) {
+        if ( jobId != null && topic != null ) {
+            this.cancelJob(this.getNodePath(topic, jobId));
+        }
+    }
+
+    /**
+     * @see org.apache.sling.event.JobStatusProvider#cancelJob(java.lang.String)
+     */
+    public void cancelJob(String jobId) {
+        if ( jobId != null ) {
+            synchronized ( this.writerSession ) {
+                try {
+                    this.writerSession.refresh(false);
+                } catch (RepositoryException e) {
+                    this.ignoreException(e);
+                }
+                try {
+                    if ( this.writerSession.itemExists(jobId) ) {
+                        final Item item = this.writerSession.getItem(jobId);
+                        final Node parentNode = item.getParent();
+                        item.remove();
+                        parentNode.save();
+                    }
+                } catch (RepositoryException e) {
+                    this.logger.error("Error during cancelling job at " + jobId, e);
+                }
+            }
+        }
+    }
+
+
     private static final class JobBlockingQueue extends LinkedBlockingQueue<EventInfo>
{
 
         private EventInfo eventInfo;



Mime
View raw message