incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r592451 - /incubator/sling/branches/Sling_Component_API/event/src/main/java/org/apache/sling/event/impl/TimedEventHandler.java
Date Tue, 06 Nov 2007 15:09:08 GMT
Author: cziegeler
Date: Tue Nov  6 07:09:08 2007
New Revision: 592451

URL: http://svn.apache.org/viewvc?rev=592451&view=rev
Log:
Allow updates of timed events: on update, the old schedule is stopped, the old event is removed
from the repository and then the new one is written into the repo and scheduled (see SLING-96)

Modified:
    incubator/sling/branches/Sling_Component_API/event/src/main/java/org/apache/sling/event/impl/TimedEventHandler.java

Modified: incubator/sling/branches/Sling_Component_API/event/src/main/java/org/apache/sling/event/impl/TimedEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/branches/Sling_Component_API/event/src/main/java/org/apache/sling/event/impl/TimedEventHandler.java?rev=592451&r1=592450&r2=592451&view=diff
==============================================================================
--- incubator/sling/branches/Sling_Component_API/event/src/main/java/org/apache/sling/event/impl/TimedEventHandler.java
(original)
+++ incubator/sling/branches/Sling_Component_API/event/src/main/java/org/apache/sling/event/impl/TimedEventHandler.java
Tue Nov  6 07:09:08 2007
@@ -174,7 +174,7 @@
                 protected Object run(Node node) throws RepositoryException {
                     final String jobId = scheduleInfo.jobId;
                     // if there is a node, we know that there is exactly one node
-                    Node foundNode = queryJob(session, jobId);
+                    final Node foundNode = queryJob(session, jobId);
                     if ( scheduleInfo.isStopEvent() ) {
                         // if this is a stop event, we should remove the node from the repository
                         // if there is no node someone else was faster and we can ignore
this
@@ -190,35 +190,23 @@
                         processEvent(event, scheduleInfo);
                         return null;
                     }
+                    // if there is already a node, it means we must handle an update
+                    if ( foundNode != null ) {
+                        try {
+                            foundNode.remove();
+                            parentNode.save();
+                        } catch (LockException le) {
+                            // if someone else has the lock this is fine
+                        }
+                        // create a stop event
+                        processEvent(event, scheduleInfo.getStopInfo());
+                    }
                     // we only write the event if this is a local one
                     if ( EventUtil.isLocal(event) ) {
-                        // if the node is present, we check if the timed event is based on
-                        // a date and has already expired
-                        if ( foundNode != null
-                            && scheduleInfo.date != null
-                            && foundNode.hasProperty(EventHelper.NODE_PROPERTY_TE_DATE)
) {
-                            final Calendar oldScheduledDate = foundNode.getProperty(EventHelper.NODE_PROPERTY_TE_DATE).getDate();
-                            final Calendar now = Calendar.getInstance();
-                            if ( oldScheduledDate.compareTo(now) <= 0 ) {
-                                // try to remove the node
-                                try {
-                                    foundNode.remove();
-                                    parentNode.save();
-                                    foundNode = null;
-                                } catch (LockException le) {
-                                    // if someone else has the lock this is fine
-                                }
-                            }
-                        }
 
-                        // if node is not present, we'll write it, lock it and schedule the
event
-                        if ( foundNode == null ) {
-                            final Node eventNode = writeEvent(event);
-                            return eventNode.lock(false, true);
-                        }
-                        // node is already in repository, this is an error as we don't support
updates
-                        // of timed events! (stopping and recreating is the way to go)
-                        logger.error("Timed event is already scheduled: " + event.getProperty(EventUtil.PROPERTY_TIMED_EVENT_TOPIC)
+ " (" + scheduleInfo.jobId + ")");
+                        // write event to repository, lock it and schedule the event
+                        final Node eventNode = writeEvent(event);
+                        return eventNode.lock(false, true);
                     }
                     return null;
                 }
@@ -553,6 +541,17 @@
             String jId = (String)event.getProperty(EventUtil.PROPERTY_JOB_ID);
 
             this.jobId = "TimedEvent: " + topic + ':' + (id != null ? id : "") + ':' + (jId
!= null ? jId : "");
+        }
+
+        private ScheduleInfo(String jobId) {
+            this.expression = null;
+            this.period = null;
+            this.date = null;
+            this.jobId = jobId;
+        }
+
+        public ScheduleInfo getStopInfo() {
+            return new ScheduleInfo(this.jobId);
         }
 
         public boolean isStopEvent() {



Mime
View raw message