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 2008/02/14 09:34:18 UTC
svn commit: r627681 - in
/incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl:
AbstractRepositoryEventHandler.java JobEventHandler.java
Author: cziegeler
Date: Thu Feb 14 00:34:13 2008
New Revision: 627681
URL: http://svn.apache.org/viewvc?rev=627681&view=rev
Log:
Clean up session handling a litle bit.
Modified:
incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
Modified: incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java?rev=627681&r1=627680&r2=627681&view=diff
==============================================================================
--- incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java (original)
+++ incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java Thu Feb 14 00:34:13 2008
@@ -115,7 +115,9 @@
processWriteQueue();
} catch (Throwable t) {
logger.error("Writer thread stopped with exception: " + t.getMessage(), t);
+ running = false;
}
+ stopWriterSession();
}
};
t.start();
@@ -125,13 +127,14 @@
runInBackground();
} catch (Throwable t) {
logger.error("Background thread stopped with exception: " + t.getMessage(), t);
+ running = false;
}
}
};
t2.start();
}
- protected abstract void runInBackground();
+ protected abstract void runInBackground() throws RepositoryException;
protected abstract void processWriteQueue();
@@ -152,9 +155,6 @@
} catch (InterruptedException e) {
this.ignoreException(e);
}
-
- // close session
- this.stopWriterSession();
}
/**
Modified: incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=627681&r1=627680&r2=627681&view=diff
==============================================================================
--- incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java (original)
+++ incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java Thu Feb 14 00:34:13 2008
@@ -96,7 +96,6 @@
} else {
this.sleepTime = DEFAULT_SLEEP_TIME * 1000;
}
- this.backgroundSession = this.createSession();
super.activate(context);
}
@@ -201,7 +200,18 @@
/**
* This method runs in the background and processes the local queue.
*/
- protected void runInBackground() {
+ protected void runInBackground() throws RepositoryException {
+ this.backgroundSession = this.createSession();
+ this.backgroundSession.getWorkspace().getObservationManager()
+ .addEventListener(this,
+ javax.jcr.observation.Event.PROPERTY_REMOVED,
+ this.repositoryPath,
+ true,
+ null,
+ new String[] {this.getEventNodeType()},
+ true);
+ // load unprocessed jobs from repository
+ this.loadJobs();
while ( this.running ) {
// so let's wait/get the next job from the queue
EventInfo info = null;
@@ -296,25 +306,6 @@
}
/**
- * Start the repository session and add this handler as an observer
- * for new events created on other nodes.
- * @throws RepositoryException
- */
- protected void startWriterSession() throws RepositoryException {
- super.startWriterSession();
- // load unprocessed jobs from repository
- this.loadJobs();
- this.backgroundSession.getWorkspace().getObservationManager()
- .addEventListener(this,
- javax.jcr.observation.Event.PROPERTY_REMOVED,
- this.repositoryPath,
- true,
- null,
- new String[] {this.getEventNodeType()},
- true);
- }
-
- /**
* @see org.apache.sling.core.event.impl.JobPersistenceHandler#getContainerNodeType()
*/
protected String getContainerNodeType() {
@@ -571,7 +562,7 @@
*/
protected void loadJobs() {
try {
- final QueryManager qManager = this.writerSession.getWorkspace().getQueryManager();
+ final QueryManager qManager = this.backgroundSession.getWorkspace().getQueryManager();
final StringBuffer buffer = new StringBuffer("/jcr:root");
buffer.append(this.repositoryPath);
buffer.append("//element(*, ");