Author: cziegeler
Date: Wed Apr 24 08:32:41 2013
New Revision: 1471289
URL: http://svn.apache.org/r1471289
Log:
SLING-2830 : Discontinue per job configurations for queue processing
Modified:
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/BackgroundLoader.java
Modified:
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/BackgroundLoader.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/BackgroundLoader.java?rev=1471289&r1=1471288&r2=1471289&view=diff
==============================================================================
---
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/BackgroundLoader.java
(original)
+++
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/BackgroundLoader.java
Wed Apr 24 08:32:41 2013
@@ -43,9 +43,12 @@ import org.slf4j.LoggerFactory;
/**
- * Task for loading stored jobs from the repository.
+ * Task for loading stored jobs from the resource tree.
*
- * TODO - we need better synching - especially something for loadJob(String)
+ * This component starts a background thread.
+ * The thread is only active when a stable topology view is available.
+ * Whenever the component gets activated, it loads all jobs from the
+ * resource tree. New incoming jobs are handled via a queue.
*/
public class BackgroundLoader implements Runnable {
@@ -61,6 +64,7 @@ public class BackgroundLoader implements
/** Is this still active? */
private final AtomicBoolean active = new AtomicBoolean(false);
+ /** Is this currently running? */
private volatile boolean running = false;
/** Job Manager implementation. */
@@ -78,6 +82,7 @@ public class BackgroundLoader implements
/** A local queue for handling new jobs. */
private final BlockingQueue<String> actionQueue = new
LinkedBlockingQueue<String>();
+ /** Change count to detect the initial start. */
private long changeCount = 0;
/**
@@ -129,10 +134,11 @@ public class BackgroundLoader implements
synchronized ( this.loadLock ) {
this.changeCount++;
this.running = true;
- this.loadLock.notify();
// make sure to clear out old information
this.actionQueue.clear();
this.unloadedJobs.clear();
+
+ this.loadLock.notify();
}
}
@@ -325,6 +331,9 @@ public class BackgroundLoader implements
return false;
}
+ /**
+ * Check if the component is currently running and active
+ */
private boolean isRunning() {
return this.active.get() && this.running;
}
@@ -344,10 +353,10 @@ public class BackgroundLoader implements
@Override
public void run() {
- synchronized ( loadLock ) {
- if ( isRunning() ) {
- final Iterator<String> iter =
copyUnloadedJobs.iterator();
- while ( iter.hasNext() ) {
+ final Iterator<String> iter = copyUnloadedJobs.iterator();
+ while ( iter.hasNext() ) {
+ synchronized ( loadLock ) {
+ if ( isRunning() ) {
try {
actionQueue.put(iter.next());
} catch (InterruptedException e) {
@@ -363,11 +372,18 @@ public class BackgroundLoader implements
}
}
+ /**
+ * Add a path to the load job queue if the instance is running.
+ */
public void loadJob(final String path) {
- try {
- this.actionQueue.put(path);
- } catch (final InterruptedException e) {
- this.ignoreException(e);
+ synchronized ( loadLock ) {
+ if ( isRunning() ) {
+ try {
+ this.actionQueue.put(path);
+ } catch (final InterruptedException e) {
+ this.ignoreException(e);
+ }
+ }
}
}
}