incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r689512 - in /incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event: EventUtil.java impl/AbstractRepositoryEventHandler.java impl/JobEventHandler.java
Date Wed, 27 Aug 2008 16:24:10 GMT
Author: cziegeler
Date: Wed Aug 27 09:24:09 2008
New Revision: 689512

URL: http://svn.apache.org/viewvc?rev=689512&view=rev
Log:
SLING-339 : Add wait time before startup to give handlers time to register. Correctly handle
application id property.

Modified:
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/EventUtil.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/JobEventHandler.java

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java?rev=689512&r1=689511&r2=689512&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
Wed Aug 27 09:24:09 2008
@@ -44,6 +44,7 @@
 
 import org.apache.jackrabbit.util.ISO9075;
 import org.apache.sling.event.EventUtil.JobStatusNotifier.NotifierContext;
+import org.apache.sling.event.impl.AbstractRepositoryEventHandler;
 import org.apache.sling.event.impl.JobEventHandler;
 import org.osgi.service.event.Event;
 import org.slf4j.LoggerFactory;
@@ -166,7 +167,8 @@
      * @return <code>true</code> if this is a local event
      */
     public static boolean isLocal(Event event) {
-        return getApplicationId(event) == null;
+        final String appId = getApplicationId(event);
+        return appId == null || appId.equals(AbstractRepositoryEventHandler.APPLICATION_ID);
     }
 
     /**

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=689512&r1=689511&r2=689512&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
Wed Aug 27 09:24:09 2008
@@ -98,6 +98,8 @@
      *  Sling settings service. */
     protected SlingSettingsService settingsService;
 
+    public static String APPLICATION_ID;
+
     /** List of ignored properties to write to the repository. */
     private static final String[] IGNORE_PROPERTIES = new String[] {
         EventUtil.PROPERTY_DISTRIBUTE,
@@ -118,6 +120,7 @@
     protected void activate(final ComponentContext context)
     throws Exception {
         this.applicationId = this.settingsService.getSlingId();
+        APPLICATION_ID = this.applicationId;
         this.repositoryPath = OsgiUtil.toString(context.getProperties().get(
             CONFIG_PROPERTY_REPO_PATH), DEFAULT_PROPERTY_REPO_PATH);
 
@@ -287,10 +290,6 @@
         eventNode.setProperty(EventHelper.NODE_PROPERTY_TOPIC, e.getTopic());
         eventNode.setProperty(EventHelper.NODE_PROPERTY_APPLICATION, this.applicationId);
 
-        // if the application property is available, we will override it
-        // if it is not available we will add it
-        eventNode.setProperty(EventUtil.PROPERTY_APPLICATION, this.applicationId);
-
         EventUtil.addProperties(eventNode,
                                 new EventPropertiesMap(e),
                                 IGNORE_PROPERTIES,

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=689512&r1=689511&r2=689512&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
Wed Aug 27 09:24:09 2008
@@ -323,6 +323,12 @@
                                   null,
                                   new String[] {this.getEventNodeType()},
                                   true);
+        // give the system some time to start
+        try {
+            Thread.sleep(1000 * 60 * 2); // 2min
+        } catch (InterruptedException e) {
+            this.ignoreException(e);
+        }
         // load unprocessed jobs from repository
         this.loadJobs();
         while ( this.running ) {
@@ -338,8 +344,9 @@
             if ( info != null && this.running ) {
                 // check for local only jobs and remove them from the queue if they're meant
                 // for another application node
+                final String appId = (String)info.event.getProperty(EventUtil.PROPERTY_APPLICATION);
                 if ( info.event.getProperty(EventUtil.PROPERTY_JOB_RUN_LOCAL) != null
-                    && !this.applicationId.equals(EventUtil.PROPERTY_APPLICATION)
) {
+                    && appId != null && !this.applicationId.equals(appId)
) {
                     info = null;
                 }
 
@@ -819,6 +826,8 @@
         if ( properties.get(EventUtil.PROPERTY_JOB_RETRY_COUNT) != null ) {
             properties.put(EventUtil.PROPERTY_JOB_RETRY_COUNT, Integer.valueOf(properties.get(EventUtil.PROPERTY_JOB_RETRY_COUNT).toString()));
         }
+        // add application id
+        properties.put(EventUtil.PROPERTY_APPLICATION, eventNode.getProperty(EventHelper.NODE_PROPERTY_APPLICATION).getString());
     }
 
     /**



Mime
View raw message