Author: cziegeler
Date: Sun May 25 03:21:53 2008
New Revision: 659952
URL: http://svn.apache.org/viewvc?rev=659952&view=rev
Log:
SLING-477: Add default max retry count with default value of 10.
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/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=659952&r1=659951&r2=659952&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
Sun May 25 03:21:53 2008
@@ -154,6 +154,16 @@
});
}
+ 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/JobEventHandler.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=659952&r1=659951&r2=659952&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
Sun May 25 03:21:53 2008
@@ -79,9 +79,18 @@
/** @scr.property valueRef="DEFAULT_SLEEP_TIME" */
protected static final String CONFIG_PROPERTY_SLEEP_TIME = "sleep.time";
+ /** Default number of job retries. */
+ protected static final long DEFAULT_MAX_JOB_RETRIES = 10;
+
+ /** @scr.property valueRef="DEFAULT_MAX_JOB_RETRIES" */
+ protected static final String CONFIG_PROPERTY_MAX_JOB_RETRIES =
"max.job.retries";
+
/** We check every 20 secs by default. */
protected long sleepTime;
+ /** How often should a job be retried by default. */
+ protected long maxJobRetries;
+
/** Background session. */
protected Session backgroundSession;
@@ -113,11 +122,8 @@
} else {
this.cleanupPeriod = DEFAULT_CLEANUP_PERIOD;
}
- if ( context.getProperties().get(CONFIG_PROPERTY_SLEEP_TIME) != null )
{
- this.sleepTime =
(Long)context.getProperties().get(CONFIG_PROPERTY_SLEEP_TIME) * 1000;
- } else {
- this.sleepTime = DEFAULT_SLEEP_TIME * 1000;
- }
+ 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);
super.activate(context);
}
@@ -696,27 +702,28 @@
boolean reschedule = shouldReschedule;
if ( shouldReschedule ) {
// check if we exceeded the number of retries
+ long retries = this.maxJobRetries;
if ( job.getProperty(EventUtil.PROPERTY_JOB_RETRIES) != null ) {
- int retries = (Integer)
job.getProperty(EventUtil.PROPERTY_JOB_RETRIES);
- int retryCount = 0;
- if ( job.getProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT) !=
null ) {
- retryCount =
(Integer)job.getProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT);
- }
- retryCount++;
- if ( retryCount > retries ) {
- reschedule = false;
- }
- // update event with retry count
- final Dictionary<String, Object> newProperties;
- // create a new dictionary
- newProperties = new Hashtable<String, Object>();
- final String[] names = job.getPropertyNames();
- for(int i=0; i<names.length; i++ ) {
- newProperties.put(names[i], job.getProperty(names[i]));
- }
- newProperties.put(EventUtil.PROPERTY_JOB_RETRY_COUNT,
retryCount);
- job = new Event(job.getTopic(), newProperties);
+ retries = (Integer)
job.getProperty(EventUtil.PROPERTY_JOB_RETRIES);
+ }
+ int retryCount = 0;
+ if ( job.getProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT) != null )
{
+ retryCount =
(Integer)job.getProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT);
+ }
+ retryCount++;
+ if ( retryCount > retries ) {
+ reschedule = false;
+ }
+ // update event with retry count
+ final Dictionary<String, Object> newProperties;
+ // create a new dictionary
+ newProperties = new Hashtable<String, Object>();
+ final String[] names = job.getPropertyNames();
+ for(int i=0; i<names.length; i++ ) {
+ newProperties.put(names[i], job.getProperty(names[i]));
}
+ newProperties.put(EventUtil.PROPERTY_JOB_RETRY_COUNT, retryCount);
+ job = new Event(job.getTopic(), newProperties);
}
final boolean parallelProcessing =
job.getProperty(EventUtil.PROPERTY_JOB_PARALLEL) != null;
// we have to use the same session for unlocking that we used for
locking!