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/11 18:28:30 UTC
svn commit: r620532 -
/incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
Author: cziegeler
Date: Mon Feb 11 09:28:25 2008
New Revision: 620532
URL: http://svn.apache.org/viewvc?rev=620532&view=rev
Log:
Fix lock token handling.
Modified:
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/JobEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=620532&r1=620531&r2=620532&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 Mon Feb 11 09:28:25 2008
@@ -71,6 +71,9 @@
/** We check every 20 secs by default. */
protected long sleepTime;
+ /** Background session. */
+ protected Session backgroundSession;
+
/**
* Activate this component.
* @param context
@@ -83,10 +86,22 @@
} else {
this.sleepTime = DEFAULT_SLEEP_TIME;
}
+ this.backgroundSession = this.createSession();
super.activate(context);
}
/**
+ * @see org.apache.sling.event.impl.AbstractRepositoryEventHandler#deactivate(org.osgi.service.component.ComponentContext)
+ */
+ protected void deactivate(final ComponentContext context) {
+ super.deactivate(context);
+ if ( this.backgroundSession != null ) {
+ this.backgroundSession.logout();
+ this.backgroundSession = null;
+ }
+ }
+
+ /**
* @see org.apache.sling.event.impl.AbstractRepositoryEventHandler#processWriteQueue()
*/
protected void processWriteQueue() {
@@ -226,10 +241,8 @@
}
if ( process ) {
boolean unlock = true;
- Session session = null;
try {
- session = this.createSession();
- final Node eventNode = (Node) session.getItem(info.nodePath);
+ final Node eventNode = (Node) this.backgroundSession.getItem(info.nodePath);
if ( !eventNode.isLocked() && eventNode.getProperty(EventHelper.NODE_PROPERTY_ACTIVE).getBoolean() ) {
// lock node
Lock lock = null;
@@ -259,16 +272,11 @@
this.processingMap.put(jobTopic, Boolean.FALSE);
}
}
- if ( session != null ) {
- session.logout();
- }
}
} else {
- Session session = null;
try {
- session = this.createSession();
// check if the node is in processing or already finished
- final Node eventNode = (Node) session.getItem(info.nodePath);
+ final Node eventNode = (Node) this.backgroundSession.getItem(info.nodePath);
if ( !eventNode.isLocked() && eventNode.getProperty(EventHelper.NODE_PROPERTY_ACTIVE).getBoolean() ) {
try {
this.queue.put(info);
@@ -289,10 +297,6 @@
} catch (RepositoryException e) {
// ignore
this.ignoreException(e);
- } finally {
- if ( session != null ) {
- session.logout();
- }
}
}
}
@@ -470,7 +474,7 @@
&& eventNode.getProperty(EventHelper.NODE_PROPERTY_ACTIVE).getBoolean() ) {
final EventInfo info = new EventInfo();
info.event = this.readEvent(eventNode);
- info.nodePath = event.getPath();
+ info.nodePath = nodePath;
try {
this.queue.put(info);
} catch (InterruptedException e) {
@@ -559,7 +563,7 @@
try {
s = this.createSession();
// remove lock token from shared session and add it to current session
- this.writerSession.removeLockToken(lockToken);
+ this.backgroundSession.removeLockToken(lockToken);
s.addLockToken(lockToken);
final Node eventNode = (Node) s.getItem(eventNodePath);
try {