You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2010/02/10 14:12:51 UTC
svn commit: r908485 -
/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
Author: cziegeler
Date: Wed Feb 10 13:12:51 2010
New Revision: 908485
URL: http://svn.apache.org/viewvc?rev=908485&view=rev
Log:
Further refactoring for rescheduling.
Modified:
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=908485&r1=908484&r2=908485&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java Wed Feb 10 13:12:51 2010
@@ -623,41 +623,7 @@
// if we still have a job, process it
if ( info != null ) {
if ( this.executeJob(info, null) == Status.RESCHEDULE ) {
- logger.debug("Putting job {} back into the queue.", info.event);
- final EventInfo eInfo = info;
- final Date fireDate = new Date();
- fireDate.setTime(System.currentTimeMillis() + this.sleepTime * 1000);
-
- // we put it back into the queue after a specific time
- final Runnable r = new Runnable() {
-
- /**
- * @see java.lang.Runnable#run()
- */
- public void run() {
- try {
- queue.put(eInfo);
- } catch (InterruptedException e) {
- // ignore
- ignoreException(e);
- }
- }
-
- };
- try {
- this.scheduler.fireJobAt(null, r, null, fireDate);
- } catch (Exception e) {
- // we ignore the exception
- ignoreException(e);
- // then wait for the time and readd the job
- try {
- Thread.sleep(sleepTime * 1000);
- } catch (InterruptedException ie) {
- // ignore
- ignoreException(ie);
- }
- r.run();
- }
+ this.putBackIntoMainQueue(info, true);
}
}
}
@@ -696,10 +662,10 @@
}
// if we have an info, this is a reschedule
if ( newInfo != null ) {
- info = ((JobBlockingQueue)queue).reschedule(newInfo, this.scheduler);
+ info = jobQueue.reschedule(newInfo, this.scheduler);
}
} else if ( status == Status.RESCHEDULE ) {
- info = ((JobBlockingQueue)queue).reschedule(processInfo, this.scheduler);
+ info = jobQueue.reschedule(processInfo, this.scheduler);
}
}
}
@@ -1412,28 +1378,7 @@
}
}
if ( putback != null ) {
- final EventInfo info = putback;
- final long delay = (Long)job.getProperty(EventUtil.PROPERTY_JOB_RETRY_DELAY);
- final Date fireDate = new Date();
- fireDate.setTime(System.currentTimeMillis() + delay);
-
- final Runnable t = new Runnable() {
- public void run() {
- try {
- queue.put(info);
- } catch (InterruptedException e) {
- // this should never happen
- ignoreException(e);
- }
- }
- };
- try {
- this.scheduler.fireJobAt(null, t, null, fireDate);
- } catch (Exception e) {
- // we ignore the exception and just put back the job in the queue
- ignoreException(e);
- t.run();
- }
+ this.putBackIntoMainQueue(putback, false);
}
if ( !shouldReschedule ) {
return true;
@@ -1441,6 +1386,44 @@
return reschedule;
}
+ private void putBackIntoMainQueue(final EventInfo info, final boolean useSleepTime) {
+ logger.debug("Putting job {} back into the queue.", info.event);
+ final Date fireDate = new Date();
+ if ( useSleepTime ) {
+ fireDate.setTime(System.currentTimeMillis() + this.sleepTime * 1000);
+ } else {
+ final long delay = (Long)info.event.getProperty(EventUtil.PROPERTY_JOB_RETRY_DELAY);
+ fireDate.setTime(System.currentTimeMillis() + delay);
+ }
+
+ final Runnable t = new Runnable() {
+ public void run() {
+ try {
+ queue.put(info);
+ } catch (InterruptedException e) {
+ // this should never happen
+ ignoreException(e);
+ }
+ }
+ };
+ try {
+ this.scheduler.fireJobAt(null, t, null, fireDate);
+ } catch (Exception e) {
+ // we ignore the exception and just put back the job in the queue
+ ignoreException(e);
+ if ( useSleepTime ) {
+ // then wait for the time and readd the job
+ try {
+ Thread.sleep(sleepTime * 1000);
+ } catch (InterruptedException ie) {
+ // ignore
+ ignoreException(ie);
+ }
+ }
+ t.run();
+ }
+ }
+
private void checkForNotify(final Event job, final EventInfo info) {
if ( job.getProperty(EventUtil.PROPERTY_JOB_QUEUE_NAME) != null ) {
// we know the queue exists