Author: cziegeler
Date: Wed Sep 3 09:19:45 2008
New Revision: 691654
URL: http://svn.apache.org/viewvc?rev=691654&view=rev
Log:
SLING-640 : Fix search query.
Modified:
incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/TimedEventStatusProvider.java
incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java
Modified:
incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/TimedEventStatusProvider.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/TimedEventStatusProvider.java?rev=691654&r1=691653&r2=691654&view=diff
==============================================================================
---
incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/TimedEventStatusProvider.java
(original)
+++
incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/TimedEventStatusProvider.java
Wed Sep 3 09:19:45 2008
@@ -29,6 +29,11 @@
public interface TimedEventStatusProvider {
/**
+ * This is a unique identifer which can be used to cancel the job.
+ */
+ String PROPERTY_EVENT_ID = "slingevent:eventId";
+
+ /**
* Return a list of currently schedulded events.
* @param topic Topic can be used as a filter, if it is non-null, only
jobs with this topic will be returned.
* @param filterProps A list of filter property maps. Each map acts like a
template. The searched event
@@ -42,5 +47,11 @@
* Return the scheduled event with the given id.
* @return The scheduled event or null.
*/
- Event getScheduledEvent(String topic, String eventId);
+ Event getScheduledEvent(String topic, String eventId, String jobId);
+
+ /**
+ * Cancel this timed event.
+ * @param jobId The unique identifer as found in the property [EMAIL
PROTECTED] #PROPERTY_EVENT_ID}.
+ */
+ void cancelTimedEvent(String jobId);
}
Modified:
incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java?rev=691654&r1=691653&r2=691654&view=diff
==============================================================================
---
incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java
(original)
+++
incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java
Wed Sep 3 09:19:45 2008
@@ -58,7 +58,7 @@
* An event handler for timed events.
*
* @scr.component metatype="no"
- * @scr.interface interface="TimedEventStatusProvider"
+ * @scr.service interface="TimedEventStatusProvider"
* @scr.property name="event.topics" refValues="EventUtil.TOPIC_TIMED_EVENT"
* values.updated="org/osgi/framework/BundleEvent/UPDATED"
* values.started="org/osgi/framework/BundleEvent/STARTED"
@@ -151,39 +151,41 @@
this.ignoreException(e);
}
if ( info != null && this.running ) {
- ScheduleInfo scheduleInfo = null;
- try {
- scheduleInfo = new ScheduleInfo(info.event);
- } catch (IllegalArgumentException iae) {
- this.logger.error(iae.getMessage());
- }
- if ( scheduleInfo != null ) {
+ synchronized ( this.writerSession ) {
+ ScheduleInfo scheduleInfo = null;
try {
- this.writerSession.refresh(true);
- final Node eventNode = (Node)
this.writerSession.getItem(info.nodePath);
- if ( !eventNode.isLocked() ) {
- // lock node
- Lock lock = null;
- try {
- lock = 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
- }
- if ( lock != null ) {
- // if something went wrong, we reschedule
- if ( !this.processEvent(info.event,
scheduleInfo) ) {
- try {
- this.queue.put(info);
- } catch (InterruptedException e) {
- // this should never happen, so we
ignore it
- this.ignoreException(e);
+ scheduleInfo = new ScheduleInfo(info.event);
+ } catch (IllegalArgumentException iae) {
+ this.logger.error(iae.getMessage());
+ }
+ if ( scheduleInfo != null ) {
+ try {
+ this.writerSession.refresh(true);
+ final Node eventNode = (Node)
this.writerSession.getItem(info.nodePath);
+ if ( !eventNode.isLocked() ) {
+ // lock node
+ Lock lock = null;
+ try {
+ lock = 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
+ }
+ if ( lock != null ) {
+ // if something went wrong, we reschedule
+ if ( !this.processEvent(info.event,
scheduleInfo) ) {
+ try {
+ this.queue.put(info);
+ } catch (InterruptedException e) {
+ // this should never happen, so we
ignore it
+ this.ignoreException(e);
+ }
}
}
}
+ } catch (RepositoryException e) {
+ // ignore
+ this.ignoreException(e);
}
- } catch (RepositoryException e) {
- // ignore
- this.ignoreException(e);
}
}
}
@@ -623,14 +625,14 @@
}
/**
- * @see
org.apache.sling.event.TimedEventStatusProvider#getScheduledEvent(java.lang.String,
java.lang.String)
+ * @see
org.apache.sling.event.TimedEventStatusProvider#getScheduledEvent(java.lang.String,
java.lang.String, java.lang.String)
*/
- public Event getScheduledEvent(String topic, String eventId) {
+ public Event getScheduledEvent(String topic, String eventId, String jobId)
{
Session s = null;
try {
s = this.createSession();
final Node parentNode = (Node)s.getItem(this.repositoryPath);
- final String nodeName =
this.getNodeName(ScheduleInfo.getJobId(topic, eventId, null));
+ final String nodeName =
this.getNodeName(ScheduleInfo.getJobId(topic, eventId, jobId));
final Node eventNode = parentNode.hasNode(nodeName) ?
parentNode.getNode(nodeName) : null;
if ( eventNode != null ) {
return this.readEvent(eventNode);
@@ -659,10 +661,6 @@
final QueryManager qManager = s.getWorkspace().getQueryManager();
final StringBuffer buffer = new StringBuffer("/jcr:root");
buffer.append(this.repositoryPath);
- if ( topic != null ) {
- buffer.append('/');
- buffer.append(topic.replace('/', '.'));
- }
buffer.append("//element(*, ");
buffer.append(this.getEventNodeType());
buffer.append(") [");
@@ -670,6 +668,7 @@
buffer.append('@');
buffer.append(EventHelper.NODE_PROPERTY_TOPIC);
buffer.append("='");
+ buffer.append(topic);
buffer.append("'");
}
if ( filterProps != null && filterProps.length > 0 ) {
@@ -734,4 +733,45 @@
}
return jobs;
}
+
+ /**
+ * @see
org.apache.sling.event.TimedEventStatusProvider#cancelTimedEvent(java.lang.String)
+ */
+ public void cancelTimedEvent(String jobId) {
+ synchronized ( this.writerSession ) {
+ try {
+ // get parent node
+ final Node parentNode =
(Node)this.writerSession.getItem(this.repositoryPath);
+ final String nodeName = jobId;
+
+ // is there a node?
+ final Node foundNode = parentNode.hasNode(nodeName) ?
parentNode.getNode(nodeName) : null;
+ // we should remove the node from the repository
+ // if there is no node someone else was faster and we can
ignore this
+ if ( foundNode != null ) {
+ try {
+ foundNode.remove();
+ parentNode.save();
+ } catch (LockException le) {
+ // if someone else has the lock this is fine
+ }
+ }
+ } catch ( RepositoryException re) {
+ this.logger.error("Unable to cancel timed event: " + jobId,
re);
+ }
+ // stop the scheduler
+ if ( this.logger.isDebugEnabled() ) {
+ this.logger.debug("Stopping timed event " + jobId);
+ }
+ final Scheduler localScheduler = this.scheduler;
+ if ( localScheduler != null ) {
+ try {
+ localScheduler.removeJob(jobId);
+ } catch (NoSuchElementException nsee) {
+ // this can happen if the job is scheduled on another node
+ // so we can just ignore this
+ }
+ }
+ }
+ }
}