Author: cziegeler
Date: Tue May 27 08:19:44 2008
New Revision: 660554

URL: http://svn.apache.org/viewvc?rev=660554&view=rev
Log:
Use OsgiUtil to get property values.

Modified:
    
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/DistributingEventHandler.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/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=660554&r1=660553&r2=660554&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
 Tue May 27 08:19:44 2008
@@ -66,7 +66,7 @@
 
     /** Default path for the [EMAIL PROTECTED] #CONFIG_PROPERTY_REPO_PATH} */
     private static final String DEFAULT_PROPERTY_REPO_PATH = "/sling/events";
-    
+
     /** @scr.reference */
     protected SlingRepository repository;
 
@@ -159,16 +159,6 @@
         });
     }
 
-    protected long getLongProperty(final ComponentContext context,
-            final String           propertyName,
-            final long             defaultValue) {
-        final Object value = context.getProperties().get(propertyName);
-        if ( value != null && value instanceof Long ) {
-            return (Long)value;
-        }
-        return defaultValue;
-    }
-
     protected abstract void runInBackground() throws RepositoryException;
 
     protected abstract void processWriteQueue();

Modified: 
incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java?rev=660554&r1=660553&r2=660554&view=diff
==============================================================================
--- 
incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java
 (original)
+++ 
incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java
 Tue May 27 08:19:44 2008
@@ -29,6 +29,7 @@
 import javax.jcr.query.Query;
 
 import org.apache.jackrabbit.util.ISO8601;
+import org.apache.sling.commons.osgi.OsgiUtil;
 import org.apache.sling.event.EventUtil;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.event.Event;
@@ -65,12 +66,9 @@
      */
     protected void activate(ComponentContext context)
     throws Exception {
-        final Integer i = 
(Integer)context.getProperties().get(CONFIG_PROPERTY_CLEANUP_PERIOD);
-        if ( i != null ) {
-            this.cleanupPeriod = i;
-        } else {
-            this.cleanupPeriod = DEFAULT_CLEANUP_PERIOD;
-        }
+        @SuppressWarnings("unchecked")
+        final Dictionary<String, Object> props = context.getProperties();
+        this.cleanupPeriod = 
OsgiUtil.toInteger(props.get(CONFIG_PROPERTY_CLEANUP_PERIOD), 
DEFAULT_CLEANUP_PERIOD);
         super.activate(context);
     }
 

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=660554&r1=660553&r2=660554&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
 Tue May 27 08:19:44 2008
@@ -40,6 +40,7 @@
 import javax.jcr.query.QueryManager;
 
 import org.apache.jackrabbit.util.ISO8601;
+import org.apache.sling.commons.osgi.OsgiUtil;
 import org.apache.sling.event.EventUtil;
 import org.apache.sling.event.JobStatusProvider;
 import org.osgi.framework.BundleEvent;
@@ -81,7 +82,7 @@
     protected static final String CONFIG_PROPERTY_SLEEP_TIME = "sleep.time";
 
     /** Default number of job retries. */
-    protected static final long DEFAULT_MAX_JOB_RETRIES = 10;
+    protected static final int DEFAULT_MAX_JOB_RETRIES = 10;
 
     /** @scr.property valueRef="DEFAULT_MAX_JOB_RETRIES" */
     protected static final String CONFIG_PROPERTY_MAX_JOB_RETRIES = 
"max.job.retries";
@@ -90,7 +91,7 @@
     protected long sleepTime;
 
     /** How often should a job be retried by default. */
-    protected long maxJobRetries;
+    protected int maxJobRetries;
 
     /** Background session. */
     protected Session backgroundSession;
@@ -117,14 +118,11 @@
      */
     protected void activate(final ComponentContext context)
     throws Exception {
-        final Integer i = 
(Integer)context.getProperties().get(CONFIG_PROPERTY_CLEANUP_PERIOD);
-        if ( i != null ) {
-            this.cleanupPeriod = i;
-        } else {
-            this.cleanupPeriod = DEFAULT_CLEANUP_PERIOD;
-        }
-        this.sleepTime = this.getLongProperty(context, 
CONFIG_PROPERTY_SLEEP_TIME, DEFAULT_SLEEP_TIME) * 1000;
-        this.maxJobRetries = this.getLongProperty(context, 
CONFIG_PROPERTY_MAX_JOB_RETRIES, DEFAULT_MAX_JOB_RETRIES);
+        @SuppressWarnings("unchecked")
+        final Dictionary<String, Object> props = context.getProperties();
+        this.cleanupPeriod = 
OsgiUtil.toInteger(props.get(CONFIG_PROPERTY_CLEANUP_PERIOD), 
DEFAULT_CLEANUP_PERIOD);
+        this.sleepTime = 
OsgiUtil.toLong(props.get(CONFIG_PROPERTY_SLEEP_TIME), DEFAULT_SLEEP_TIME);
+        this.maxJobRetries = 
OsgiUtil.toInteger(props.get(CONFIG_PROPERTY_MAX_JOB_RETRIES), 
DEFAULT_MAX_JOB_RETRIES);
         super.activate(context);
     }
 
@@ -703,7 +701,7 @@
         boolean reschedule = shouldReschedule;
         if ( shouldReschedule ) {
             // check if we exceeded the number of retries
-            long retries = this.maxJobRetries;
+            int retries = this.maxJobRetries;
             if ( job.getProperty(EventUtil.PROPERTY_JOB_RETRIES) != null ) {
                 retries = (Integer) 
job.getProperty(EventUtil.PROPERTY_JOB_RETRIES);
             }


Reply via email to