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/13 18:39:59 UTC
svn commit: r627546 - in
/incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event:
EventUtil.java impl/JobEventHandler.java
Author: cziegeler
Date: Wed Feb 13 09:39:54 2008
New Revision: 627546
URL: http://svn.apache.org/viewvc?rev=627546&view=rev
Log:
No need to pass lock token around.
Modified:
incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/EventUtil.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/EventUtil.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/EventUtil.java?rev=627546&r1=627545&r2=627546&view=diff
==============================================================================
--- incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/EventUtil.java (original)
+++ incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/EventUtil.java Wed Feb 13 09:39:54 2008
@@ -149,7 +149,7 @@
if ( ctx == null ) {
throw new NullPointerException("JobStatusNotifier context is not available in event properties.");
}
- ctx.notifier.finishedJob(job, ctx.eventNodePath, ctx.lockToken, false);
+ ctx.notifier.finishedJob(job, ctx.eventNodePath, false);
}
/**
@@ -165,7 +165,7 @@
if ( ctx == null ) {
throw new NullPointerException("JobStatusNotifier context is not available in event properties.");
}
- return ctx.notifier.finishedJob(job, ctx.eventNodePath, ctx.lockToken, true);
+ return ctx.notifier.finishedJob(job, ctx.eventNodePath, true);
}
/**
@@ -204,12 +204,10 @@
public static final class NotifierContext {
public final JobStatusNotifier notifier;
public final String eventNodePath;
- public final String lockToken;
- public NotifierContext(JobStatusNotifier n, String path, String token) {
+ public NotifierContext(JobStatusNotifier n, String path) {
this.notifier = n;
this.eventNodePath = path;
- this.lockToken = token;
}
}
@@ -225,6 +223,6 @@
* @param reschedule Should the event be rescheduled?
* @return <code>true</code> if everything went fine, <code>false</code> otherwise.
*/
- boolean finishedJob(Event job, String eventNodePath, String lockToken, boolean reschedule);
+ boolean finishedJob(Event job, String eventNodePath, boolean reschedule);
}
}
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=627546&r1=627545&r2=627546&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 Wed Feb 13 09:39:54 2008
@@ -34,7 +34,6 @@
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import javax.jcr.lock.Lock;
import javax.jcr.observation.EventIterator;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
@@ -241,16 +240,15 @@
final Node eventNode = (Node) this.backgroundSession.getItem(info.nodePath);
if ( !eventNode.isLocked() ) {
// lock node
- Lock lock = null;
try {
- lock = eventNode.lock(false, true);
+ eventNode.lock(false, true);
} catch (RepositoryException re) {
// lock failed which means that the node is locked by someone else, so we don't have to requeue
process = false;
}
if ( process ) {
unlock = false;
- this.processJob(info.event, eventNode, lock.getLockToken());
+ this.processJob(info.event, eventNode);
}
}
} catch (RepositoryException e) {
@@ -438,12 +436,12 @@
* @param event The original event.
* @param eventNode The node in the repository where the job is stored.
*/
- protected void processJob(Event event, Node eventNode, String lockToken) {
+ protected void processJob(Event event, Node eventNode) {
final boolean parallelProcessing = event.getProperty(EventUtil.PROPERTY_JOB_PARALLEL) != null;
final String jobTopic = (String)event.getProperty(EventUtil.PROPERTY_JOB_TOPIC);
boolean unlock = true;
try {
- final Event jobEvent = this.getJobEvent(event, eventNode, lockToken);
+ final Event jobEvent = this.getJobEvent(event, eventNode);
eventNode.setProperty(EventHelper.NODE_PROPERTY_PROCESSOR, this.applicationId);
eventNode.save();
final EventAdmin localEA = this.eventAdmin;
@@ -480,7 +478,7 @@
* @param e
* @return
*/
- protected Event getJobEvent(Event e, Node eventNode, String lockToken)
+ protected Event getJobEvent(Event e, Node eventNode)
throws RepositoryException {
final String eventTopic = (String)e.getProperty(EventUtil.PROPERTY_JOB_TOPIC);
final Dictionary<String, Object> properties = new Hashtable<String, Object>();
@@ -489,7 +487,7 @@
properties.put(propertyNames[i], e.getProperty(propertyNames[i]));
}
// put properties for finished job callback
- properties.put(EventUtil.JobStatusNotifier.CONTEXT_PROPERTY_NAME, new EventUtil.JobStatusNotifier.NotifierContext(this, eventNode.getPath(), lockToken));
+ properties.put(EventUtil.JobStatusNotifier.CONTEXT_PROPERTY_NAME, new EventUtil.JobStatusNotifier.NotifierContext(this, eventNode.getPath()));
return new Event(eventTopic, properties);
}
@@ -613,9 +611,9 @@
}
/**
- * @see org.apache.sling.event.EventUtil.JobStatusNotifier#finishedJob(org.osgi.service.event.Event, String, String, boolean)
+ * @see org.apache.sling.event.EventUtil.JobStatusNotifier#finishedJob(org.osgi.service.event.Event, String, boolean)
*/
- public boolean finishedJob(Event job, String eventNodePath, String lockToken, boolean shouldReschedule) {
+ public boolean finishedJob(Event job, String eventNodePath, boolean shouldReschedule) {
boolean reschedule = shouldReschedule;
if ( shouldReschedule ) {
// check if we exceeded the number of retries
@@ -646,6 +644,7 @@
// TODO - we have to bring the session into the same thread!
try {
final Node eventNode = (Node) this.backgroundSession.getItem(eventNodePath);
+ boolean unlock = true;
try {
if ( !reschedule ) {
synchronized ( this.deletedJobs ) {
@@ -658,11 +657,11 @@
// if unlock fails, we silently ignore this
this.ignoreException(e);
}
+ unlock = false;
// remove node from repository
final Node parentNode = eventNode.getParent();
eventNode.remove();
parentNode.save();
- lockToken = null;
}
} catch (RepositoryException re) {
// if an exception occurs, we just log
@@ -674,7 +673,7 @@
this.processingMap.put(jobTopic, Boolean.FALSE);
}
}
- if ( lockToken != null ) {
+ if ( unlock ) {
synchronized ( this.deletedJobs ) {
this.deletedJobs.add(eventNodePath);
}