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 2010/10/15 16:02:25 UTC
svn commit: r1022923 [1/2] - in /sling/trunk/bundles/extensions/event: ./
src/main/java/org/apache/sling/event/
src/main/java/org/apache/sling/event/impl/
src/main/java/org/apache/sling/event/impl/job/
src/main/java/org/apache/sling/event/impl/jobs/ sr...
Author: cziegeler
Date: Fri Oct 15 14:02:23 2010
New Revision: 1022923
URL: http://svn.apache.org/viewvc?rev=1022923&view=rev
Log:
Move code from 3.0 branch to trunk
Added:
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/EnvironmentComponent.java
- copied unchanged from r1021250, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/EnvironmentComponent.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java
- copied unchanged from r1022421, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobEvent.java
- copied unchanged from r1021250, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/JobEvent.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobStatusNotifier.java
- copied unchanged from r1022914, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/JobStatusNotifier.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobsIteratorImpl.java
- copied unchanged from r1021250, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/JobsIteratorImpl.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/StatisticsImpl.java
- copied unchanged from r1022421, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/StatisticsImpl.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/TopicStatisticsImpl.java
- copied unchanged from r1022421, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/TopicStatisticsImpl.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/Utility.java
- copied unchanged from r1022914, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/Utility.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/ConfigurationConstants.java
- copied unchanged from r1021250, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/config/ConfigurationConstants.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfiguration.java
- copied unchanged from r1022914, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfiguration.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/config/QueueConfigurationManager.java
- copied unchanged from r1021250, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/config/QueueConfigurationManager.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java
- copied unchanged from r1022833, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/JCRHelper.java
- copied unchanged from r1022108, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/jcr/JCRHelper.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/JCRJobEvent.java
- copied unchanged from r1021250, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/jcr/JCRJobEvent.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/JobStatusProviderImpl.java
- copied unchanged from r1021250, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/jcr/JobStatusProviderImpl.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/JobsIteratorImpl.java
- copied unchanged from r1021250, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/jcr/JobsIteratorImpl.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/PersistenceHandler.java
- copied unchanged from r1022914, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/impl/jobs/jcr/PersistenceHandler.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractJobQueue.java (with props)
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractParallelJobQueue.java (with props)
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/OrderedJobQueue.java (with props)
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/ParallelJobQueue.java (with props)
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/TopicRoundRobinJobQueue.java (with props)
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/Environment.java (with props)
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobManager.java
- copied unchanged from r1022421, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/jobs/JobManager.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobProcessor.java
- copied unchanged from r1021250, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/jobs/JobProcessor.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobUtil.java
- copied unchanged from r1022914, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/jobs/JobUtil.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobsIterator.java
- copied unchanged from r1021250, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/jobs/JobsIterator.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/Queue.java
- copied unchanged from r1022833, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/jobs/Queue.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/QueueConfiguration.java
- copied unchanged from r1021250, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/jobs/QueueConfiguration.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/Statistics.java
- copied unchanged from r1022391, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/jobs/Statistics.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/TopicStatistics.java
- copied unchanged from r1022421, sling/branches/eventing-3.0/src/main/java/org/apache/sling/event/jobs/TopicStatistics.java
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractTest.java
- copied unchanged from r1021250, sling/branches/eventing-3.0/src/test/java/org/apache/sling/event/impl/AbstractTest.java
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/AbstractJobEventHandlerTest.java
- copied unchanged from r1022840, sling/branches/eventing-3.0/src/test/java/org/apache/sling/event/impl/jobs/AbstractJobEventHandlerTest.java
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/JobEventHandlerTest.java
- copied unchanged from r1022391, sling/branches/eventing-3.0/src/test/java/org/apache/sling/event/impl/jobs/JobEventHandlerTest.java
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/OrderedJobQueueTest.java
- copied unchanged from r1022914, sling/branches/eventing-3.0/src/test/java/org/apache/sling/event/impl/jobs/OrderedJobQueueTest.java
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/RoundRobinQueueTest.java
- copied unchanged from r1022870, sling/branches/eventing-3.0/src/test/java/org/apache/sling/event/impl/jobs/RoundRobinQueueTest.java
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/StatisticsImplTest.java
- copied unchanged from r1022421, sling/branches/eventing-3.0/src/test/java/org/apache/sling/event/impl/jobs/StatisticsImplTest.java
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/config/
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java (with props)
Removed:
sling/trunk/bundles/extensions/event/README.txt
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/ThreadPool.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/job/
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/JobEventHandlerTest.java
Modified:
sling/trunk/bundles/extensions/event/pom.xml
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventPropertiesMap.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobProcessor.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobsIterator.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java
sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties
sling/trunk/bundles/extensions/event/src/main/resources/SLING-INF/nodetypes/event.cnd
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/EventUtilTest.java
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/DistributingEventHandlerTest.java
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/SimpleEventAdmin.java
Modified: sling/trunk/bundles/extensions/event/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/pom.xml?rev=1022923&r1=1022922&r2=1022923&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/pom.xml (original)
+++ sling/trunk/bundles/extensions/event/pom.xml Fri Oct 15 14:02:23 2010
@@ -29,7 +29,7 @@
<artifactId>org.apache.sling.event</artifactId>
<packaging>bundle</packaging>
- <version>2.4.3-SNAPSHOT</version>
+ <version>3.0.0-SNAPSHOT</version>
<name>Apache Sling Event Support</name>
<description>
@@ -45,8 +45,13 @@
<build>
<plugins>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+ <plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
+ <version>1.4.5-SNAPSHOT</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
@@ -54,12 +59,15 @@
<extensions>true</extensions>
<configuration>
<instructions>
+ <Import-Package>
+ javax.servlet;javax.servlet.http;resolution:=optional,*
+ </Import-Package>
<Export-Package>
- org.apache.sling.event;version=2.4.0
+ org.apache.sling.event;version=2.4.0,
+ org.apache.sling.event.jobs;version=1.0.0
</Export-Package>
<Private-Package>
- org.apache.sling.event.impl,
- org.apache.sling.event.impl.job
+ org.apache.sling.event.impl.*
</Private-Package>
<Sling-Nodetypes>
SLING-INF/nodetypes/event.cnd
@@ -83,7 +91,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<excludePackageNames>
- org.apache.sling.event.impl,org.apache.sling.event.impl.job
+ org.apache.sling.event.impl,org.apache.sling.event.impl.job,org.apache.sling.event.impl.jobs,org.apache.sling.event.impl.jobs.console,org.apache.sling.event.impl.jobs.queue
</excludePackageNames>
</configuration>
</plugin>
@@ -101,7 +109,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
- <version>1.3.0</version>
+ <version>1.3.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -149,7 +157,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.threads</artifactId>
- <version>3.0.0</version>
+ <version>3.0.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -164,6 +172,11 @@
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
+ <!-- Webconsole -->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
<!-- Testing -->
<dependency>
<groupId>org.apache.sling</groupId>
@@ -176,6 +189,12 @@
<artifactId>junit</artifactId>
</dependency>
<dependency>
+ <groupId>junit-addons</groupId>
+ <artifactId>junit-addons</artifactId>
+ <version>1.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
</dependency>
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventPropertiesMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventPropertiesMap.java?rev=1022923&r1=1022922&r2=1022923&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventPropertiesMap.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventPropertiesMap.java Fri Oct 15 14:02:23 2010
@@ -40,6 +40,7 @@ public class EventPropertiesMap
private static final long serialVersionUID = 835179638502569708L;
+ /** The delegatee map. */
private final Map<String, Object> delegatee;
/**
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java?rev=1022923&r1=1022922&r2=1022923&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java Fri Oct 15 14:02:23 2010
@@ -18,15 +18,14 @@
*/
package org.apache.sling.event;
+import java.util.Calendar;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
-import org.apache.sling.event.impl.AbstractRepositoryEventHandler;
-import org.apache.sling.event.impl.JobEventHandler;
-import org.apache.sling.event.impl.job.JobStatusNotifier;
+import org.apache.sling.event.impl.support.Environment;
+import org.apache.sling.event.jobs.JobUtil;
import org.osgi.service.event.Event;
-import org.slf4j.LoggerFactory;
/**
* The <code>EventUtil</code> class is an utility class for
@@ -44,10 +43,16 @@ public abstract class EventUtil {
* Job Handling
*/
- /** The job topic property. */
+ /** The job topic property.
+ * @deprecated Use {@link JobUtil#PROPERTY_JOB_TOPIC}
+ */
+ @Deprecated
public static final String PROPERTY_JOB_TOPIC = "event.job.topic";
- /** The property for the unique event id. Value is of type String (This is optional). */
+ /** The property for the unique event id. Value is of type String (This is optional).
+ * @deprecated Use {@link JobUtil#PROPERTY_JOB_NAME}
+ * */
+ @Deprecated
public static final String PROPERTY_JOB_ID = "event.job.id";
/** The property to set if a job can be run parallel to any other job.
@@ -58,59 +63,93 @@ public abstract class EventUtil {
* parallel but never more than the specified number.
*
* We might want to use different values in the future for enhanced
- * parallel job handling. */
+ * parallel job handling.
+ *
+ * This value is only used, if {@link JobUtil#PROPERTY_JOB_QUEUE_NAME} is
+ * specified and the referenced queue is not started yet.
+ * @deprecated Use {@link JobUtil#PROPERTY_JOB_PARALLEL}
+ */
+ @Deprecated
public static final String PROPERTY_JOB_PARALLEL = "event.job.parallel";
- /** The property to set if a job should only be run on the same app it has been created. */
+ /**
+ * The property to set if a job should only be run on the same app it has been created.
+ * @deprecated Use {@link JobUtil#PROPERTY_JOB_RUN_LOCAL}
+ */
+ @Deprecated
public static final String PROPERTY_JOB_RUN_LOCAL = "event.job.run.local";
- /** The property to track the retry count for jobs. Value is of type Integer. */
+ /**
+ * The property to track the retry count for jobs. Value is of type Integer.
+ * @deprecated Use {@link JobUtil#PROPERTY_JOB_RETRY_COUNT}
+ */
+ @Deprecated
public static final String PROPERTY_JOB_RETRY_COUNT = "event.job.retrycount";
- /** The property for setting the maximum number of retries. Value is of type Integer. */
+ /**
+ * The property for setting the maximum number of retries. Value is of type Integer.
+ * @deprecated Use {@link JobUtil#PROPERTY_JOB_RETRIES}
+ */
+ @Deprecated
public static final String PROPERTY_JOB_RETRIES = "event.job.retries";
- /** The property to set a retry delay. Value is of type Long and specifies milliseconds. */
+ /**
+ * The property to set a retry delay. Value is of type Long and specifies milliseconds.
+ * @deprecated Use {@link JobUtil#PROPERTY_JOB_RETRY_DELAY}
+ */
+ @Deprecated
public static final String PROPERTY_JOB_RETRY_DELAY = "event.job.retrydelay";
/** The property to set to put the jobs into a separate job queue. This property
* specifies the name of the job queue. If the job queue does not exists yet
* a new queue is created.
* If a ordered job queue is used, the jobs are never executed in parallel
- * from this queue! For non ordered queues the {@link #PROPERTY_JOB_PARALLEL}
+ * from this queue! For non ordered queues the {@link JobUtil#PROPERTY_JOB_PARALLEL}
* with an integer value higher than 1 can be used to specify the maximum number
* of parallel jobs for this queue.
+ * @deprecated Use {@link JobUtil#PROPERTY_JOB_QUEUE_NAME}
*/
+ @Deprecated
public static final String PROPERTY_JOB_QUEUE_NAME = "event.job.queuename";
- /** If this property is set with any value, the queue processes the jobs in the same
+ /**
+ * If this property is set with any value, the queue processes the jobs in the same
* order as they have arrived.
* This property has only an effect if {@link #PROPERTY_JOB_QUEUE_NAME} is specified
- * and starting with version 2.2 this value is only checked in the first job for this
- * queue.
+ * and the job queue has not been started yet.
+ * @deprecated Use {@link JobUtil#PROPERTY_JOB_QUEUE_ORDERED}
*/
+ @Deprecated
public static final String PROPERTY_JOB_QUEUE_ORDERED = "event.job.queueordered";
- /** This property allows to override the priority for the thread used to start this job.
- * The property is evaluated by the {@link #processJob(Event, JobProcessor)} method.
+ /**
+ * This property allows to override the priority for the thread used to start this job.
+ * The property is evaluated by the {@link JobUtil#processJob(Event, org.apache.sling.event.jobs.JobProcessor)} method.
* If another way of executing the job is used, it is up to the client to ensure
* the job priority.
* For possible values see {@link JobPriority}.
* @since 2.4
+ * @deprecated Use {@link JobUtil#PROPERTY_JOB_PRIORITY}
*/
+ @Deprecated
public static final String PROPERTY_JOB_PRIORITY = "event.job.priority";
/**
* The priority for jobs.
* @since 2.4
+ * @deprecated Use {@link JobUtil.JobPriority}
*/
public enum JobPriority {
NORM,
MIN,
MAX
- };
+ }
- /** The topic for jobs. */
+ /**
+ * The topic for jobs.
+ * @deprecated Use {@link JobUtil#TOPIC_JOB}
+ */
+ @Deprecated
public static final String TOPIC_JOB = "org/apache/sling/event/job";
/**
@@ -143,14 +182,20 @@ public abstract class EventUtil {
* The property {@link #PROPERTY_NOTIFICATION_JOB} contains the job event and the
* property {@link org.osgi.service.event.EventConstants#TIMESTAMP} contains the
* timestamp of the event (as a Long).
- * @since 2.2 */
+ * @since 2.2
+ * @deprecated Use {@link JobUtil#TOPIC_JOB_STARTED}
+ */
+ @Deprecated
public static final String TOPIC_JOB_STARTED = "org/apache/sling/event/notification/job/START";
/** Asynchronous notification event when a job is finished.
* The property {@link #PROPERTY_NOTIFICATION_JOB} contains the job event and the
* property {@link org.osgi.service.event.EventConstants#TIMESTAMP} contains the
* timestamp of the event (as a Long).
- * @since 2.2 */
+ * @since 2.2
+ * @deprecated Use {@link JobUtil#TOPIC_JOB_FINISHED}
+ */
+ @Deprecated
public static final String TOPIC_JOB_FINISHED = "org/apache/sling/event/notification/job/FINISHED";
/** Asynchronous notification event when a job failed.
@@ -158,7 +203,10 @@ public abstract class EventUtil {
* The property {@link #PROPERTY_NOTIFICATION_JOB} contains the job event and the
* property {@link org.osgi.service.event.EventConstants#TIMESTAMP} contains the
* timestamp of the event (as a Long).
- * @since 2.2 */
+ * @since 2.2
+ * @deprecated Use {@link JobUtil#TOPIC_JOB_FAILED}
+ */
+ @Deprecated
public static final String TOPIC_JOB_FAILED = "org/apache/sling/event/notification/job/FAILED";
/** Asynchronous notification event when a job is cancelled.
@@ -166,11 +214,17 @@ public abstract class EventUtil {
* The property {@link #PROPERTY_NOTIFICATION_JOB} contains the job event and the
* property {@link org.osgi.service.event.EventConstants#TIMESTAMP} contains the
* timestamp of the event (as a Long).
- * @since 2.2 */
+ * @since 2.2
+ * @deprecated Use {@link JobUtil#TOPIC_JOB_CANCELLED}
+ */
+ @Deprecated
public static final String TOPIC_JOB_CANCELLED = "org/apache/sling/event/notification/job/CANCELLED";
/** Property containing the job event.
- * @since 2.2 */
+ * @since 2.2
+ * @deprecated Use {@link JobUtil#PROPERTY_NOTIFICATION_JOB}
+ */
+ @Deprecated
public static final String PROPERTY_NOTIFICATION_JOB = "event.notification.job";
/**
@@ -217,7 +271,7 @@ public abstract class EventUtil {
*/
public static boolean isLocal(final Event event) {
final String appId = getApplicationId(event);
- return appId == null || appId.equals(AbstractRepositoryEventHandler.APPLICATION_ID);
+ return appId == null || appId.equals(Environment.APPLICATION_ID);
}
/**
@@ -230,30 +284,56 @@ public abstract class EventUtil {
}
/**
+ * Improved toString method for an Event.
+ * This method prints out the event topic and all of the properties.
+ */
+ public static String toString(final Event e) {
+ if ( e == null ) {
+ return "<null>";
+ }
+ final StringBuilder buffer = new StringBuilder(e.getClass().getName());
+ buffer.append('(');
+ buffer.append(e.hashCode());
+ buffer.append(") [topic=");
+ buffer.append(e.getTopic());
+ buffer.append(", properties=");
+ final String[] names = e.getPropertyNames();
+ if ( names != null ) {
+ for(int i=0;i<names.length;i++) {
+ if ( i>0) {
+ buffer.append(",");
+ }
+ buffer.append(names[i]);
+ buffer.append('=');
+ final Object value = e.getProperty(names[i]);
+ // the toString() method of Calendar is very verbose
+ // therefore we do a toString for these objects based
+ // on a date
+ if ( value instanceof Calendar ) {
+ buffer.append(value.getClass().getName());
+ buffer.append('(');
+ buffer.append(((Calendar)value).getTime());
+ buffer.append(')');
+ } else {
+ buffer.append(value);
+ }
+ }
+ }
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
* Is this a job event?
* This method checks if the event contains the {@link #PROPERTY_JOB_TOPIC}
* property.
* @param event The event to check.
* @return <code>true></code> if this is a job event.
+ * @deprecated Use {@link JobUtil#isJobEvent(Event)}
*/
+ @Deprecated
public static boolean isJobEvent(final Event event) {
- return event.getProperty(PROPERTY_JOB_TOPIC) != null;
- }
-
- /**
- * Check if this a job event and return the notifier context.
- * @throws IllegalArgumentException If the event is a job event but does not have a notifier context.
- */
- private static JobStatusNotifier.NotifierContext getNotifierContext(final Event job) {
- // check if this is a job event
- if ( !isJobEvent(job) ) {
- return null;
- }
- final JobStatusNotifier.NotifierContext ctx = (JobStatusNotifier.NotifierContext) job.getProperty(JobStatusNotifier.CONTEXT_PROPERTY_NAME);
- if ( ctx == null ) {
- throw new IllegalArgumentException("JobStatusNotifier context is not available in event properties.");
- }
- return ctx;
+ return JobUtil.isJobEvent(event);
}
/**
@@ -265,140 +345,42 @@ public abstract class EventUtil {
* @return Returns <code>true</code> if the acknowledge could be sent
* @throws IllegalArgumentException If the event is a job event but does not have a notifier context.
* @since 2.3
+ * @deprecated Use {@link JobUtil#acknowledgeJob(Event)}
*/
+ @Deprecated
public static boolean acknowledgeJob(final Event job) {
- final JobStatusNotifier.NotifierContext ctx = getNotifierContext(job);
- if ( ctx != null ) {
- if ( !ctx.notifier.sendAcknowledge(job, ctx.eventNodePath) ) {
- // if we don't get an ack, someone else is already processing this job.
- // we process but do not notify the job event handler.
- LoggerFactory.getLogger(EventUtil.class).info("Someone else is already processing job {}.", job);
- return false;
- }
- return true;
- }
- return false;
+ return JobUtil.acknowledgeJob(job);
}
/**
* Notify a finished job.
* @throws IllegalArgumentException If the event is a job event but does not have a notifier context.
+ * @deprecated Use {link {@link JobUtil#finishedJob(Event)}
*/
+ @Deprecated
public static void finishedJob(final Event job) {
- final JobStatusNotifier.NotifierContext ctx = getNotifierContext(job);
- if ( ctx != null ) {
- ctx.notifier.finishedJob(job, ctx.eventNodePath, false);
- }
+ JobUtil.finishedJob(job);
}
/**
* Notify a failed job.
* @return <code>true</code> if the job has been rescheduled, <code>false</code> otherwise.
* @throws IllegalArgumentException If the event is a job event but does not have a notifier context.
+ * @deprecated Use {@link JobUtil#rescheduleJob(Event)}
*/
+ @Deprecated
public static boolean rescheduleJob(final Event job) {
- final JobStatusNotifier.NotifierContext ctx = getNotifierContext(job);
- if ( ctx != null ) {
- return ctx.notifier.finishedJob(job, ctx.eventNodePath, true);
- }
- return false;
+ return JobUtil.rescheduleJob(job);
}
/**
* Process a job in the background and notify its success.
* This method also sends an acknowledge message to the job event handler.
* @throws IllegalArgumentException If the event is a job event but does not have a notifier context.
+ * @deprecated Use {@link JobUtil#processJob(Event, org.apache.sling.event.jobs.JobProcessor)}
*/
+ @Deprecated
public static void processJob(final Event job, final JobProcessor processor) {
- // first check for a notifier context to send an acknowledge
- boolean notify = true;
- final JobStatusNotifier.NotifierContext ctx = getNotifierContext(job);
- if ( ctx != null ) {
- if ( !ctx.notifier.sendAcknowledge(job, ctx.eventNodePath) ) {
- // if we don't get an ack, someone else is already processing this job.
- // we process but do not notify the job event handler.
- LoggerFactory.getLogger(EventUtil.class).info("Someone else is already processing job {}.", job);
- notify = false;
- }
- }
- final JobPriority priority = (JobPriority) job.getProperty(PROPERTY_JOB_PRIORITY);
- final boolean notifyResult = notify;
-
- final Runnable task = new Runnable() {
-
- /**
- * @see java.lang.Runnable#run()
- */
- public void run() {
- // update priority
- final int oldPriority = Thread.currentThread().getPriority();
- if ( priority != null ) {
- switch ( priority ) {
- case NORM : Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
- break;
- case MIN : Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
- break;
- case MAX : Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
- break;
- }
- }
- boolean result = false;
- try {
- result = processor.process(job);
- } catch (Throwable t) { //NOSONAR
- LoggerFactory.getLogger(EventUtil.class).error("Unhandled error occured in job processor " + t.getMessage() + " while processing job " + job, t);
- // we don't reschedule if an exception occurs
- result = true;
- } finally {
- Thread.currentThread().setPriority(oldPriority);
- if ( notifyResult ) {
- if ( result ) {
- EventUtil.finishedJob(job);
- } else {
- EventUtil.rescheduleJob(job);
- }
- }
- }
- }
-
- };
- // check if the job handler thread pool is available
- if ( JobEventHandler.JOB_THREAD_POOL != null ) {
- JobEventHandler.JOB_THREAD_POOL.execute(task);
- } else {
- // if we don't have a thread pool, we create the thread directly
- // (this should never happen for jobs, but is a safe fallback and
- // allows to call this method for other background processing.
- new Thread(task).start();
- }
- }
-
- /**
- * Improved toString method for an Event.
- * This method prints out the event topic and all of the properties.
- */
- public static String toString(final Event e) {
- if ( e == null ) {
- return "<null>";
- }
- final StringBuilder buffer = new StringBuilder(e.getClass().getName());
- buffer.append('(');
- buffer.append(e.hashCode());
- buffer.append(") [topic=");
- buffer.append(e.getTopic());
- buffer.append(", properties=");
- final String[] names = e.getPropertyNames();
- if ( names != null ) {
- for(int i=0;i<names.length;i++) {
- if ( i>0) {
- buffer.append(",");
- }
- buffer.append(names[i]);
- buffer.append('=');
- buffer.append(e.getProperty(names[i]));
- }
- }
- buffer.append("]");
- return buffer.toString();
+ JobUtil.processJob(job, processor);
}
}
\ No newline at end of file
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobProcessor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobProcessor.java?rev=1022923&r1=1022922&r2=1022923&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobProcessor.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobProcessor.java Fri Oct 15 14:02:23 2010
@@ -23,16 +23,10 @@ import org.osgi.service.event.Event;
/**
* A job processor processes a job in the background.
* It is used by {@link EventUtil#processJob(Event, JobProcessor)}.
+ * @deprecated Use org.apache.sling.event.jobs.JobProcessor
*/
-public interface JobProcessor {
+@Deprecated
+public interface JobProcessor extends org.apache.sling.event.jobs.JobProcessor {
- /**
- * Execute the job.
- * If the job fails with a thrown exception/throwable, the process will not be rescheduled.
- *
- * @param job The event containing the job description.
- * @return True if the job could be finished (either successful or by an error).
- * Return false if the job should be rescheduled.
- */
- boolean process(Event job);
+ // just for compatibility
}
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java?rev=1022923&r1=1022922&r2=1022923&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java Fri Oct 15 14:02:23 2010
@@ -25,12 +25,104 @@ import org.osgi.service.event.Event;
/**
* This service provides the current job processing status.
+ * @deprecated
*/
+@Deprecated
public interface JobStatusProvider {
/**
+ * Cancel this job.
+ * Cancelling a job might fail if the job is currently in processing.
+ * @param jobId The unique identifer as found in the property {@link #PROPERTY_EVENT_ID}.
+ * @return <code>true</code> if the job could be cancelled or does not exist anymore.
+ * <code>false</code> otherwise.
+ * @since 2.4.0
+ */
+ boolean removeJob(String jobId);
+
+ /**
+ * Cancel this job.
+ * Cancelling a job might fail if the job is currently in processing.
+ * This method can be used if the topic and the provided job id is known.
+ * @param topic The job topic as put into the property {@link org.apache.sling.event.jobs.JobUtil#PROPERTY_JOB_TOPIC}.
+ * @param jobId The unique identifer as put into the property {@link org.apache.sling.event.jobs.JobUtil#PROPERTY_JOB_NAME}.
+ * @return <code>true</code> if the job could be cancelled or does not exist anymore.
+ * <code>false</code> otherwise.
+ * @since 2.4.0
+ */
+ boolean removeJob(String topic, String jobId);
+
+ /**
+ * Cancel this job.
+ * This method acts like {@link #removeJob(String)} with the exception that it waits
+ * for a job to finish. The job will be removed when this method returns - however
+ * this method blocks until the job is finished!
+ * @param jobId The unique identifer as found in the property {@link #PROPERTY_EVENT_ID}.
+ * @since 2.4.0
+ */
+ void forceRemoveJob(String jobId);
+
+ /**
+ * Cancel this job.
+ * This method acts like {@link #removeJob(String, String)} with the exception that it waits
+ * for a job to finish. The job will be removed when this method returns - however
+ * this method blocks until the job is finished!
+ * This method can be used if the topic and the provided job id is known.
+ * @param topic The job topic as put into the property {@link org.apache.sling.event.jobs.JobUtil#PROPERTY_JOB_TOPIC}.
+ * @param jobId The unique identifer as put into the property {@link org.apache.sling.event.jobs.JobUtil#PROPERTY_JOB_NAME}.
+ * @since 2.4.0
+ */
+ void forceRemoveJob(String topic, String jobId);
+
+ /**
+ * Wake up the named job queue.
+ * If a job failed, the job queue waits (sleeps) for a configured time. By calling this
+ * method, the job queue can be woken up and force an immediate reprocessing.
+ * @param jobQueueName The name of the queue.
+ */
+ void wakeUpJobQueue(final String jobQueueName);
+
+ /**
+ * Return a list of currently scheduled jobs.
+ * @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 job
+ * must match the template (AND query). By providing several maps, different filters
+ * are possible (OR query).
+ * @return A non null collection.
+ * @since 2.4
+ */
+ JobsIterator queryScheduledJobs(String topic, Map<String, Object>... filterProps);
+
+ /**
+ * Return the jobs which are currently in processing. If there are several application nodes
+ * in the cluster, there could be more than one job in processing
+ * @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 job
+ * must match the template (AND query). By providing several maps, different filters
+ * are possible (OR query).
+ * @return A non null collection.
+ * @since 2.4
+ */
+ JobsIterator queryCurrentJobs(String topic, Map<String, Object>... filterProps);
+
+ /**
+ * Return all jobs either running or scheduled.
+ * This is actually a convenience method and collects the results from {@link #queryScheduledJobs(String, Map...)}
+ * and {@link #queryCurrentJobs(String, Map...)}
+ * @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 job
+ * must match the template (AND query). By providing several maps, different filters
+ * are possible (OR query).
+ * @return A non null collection.
+ * @since 2.4
+ */
+ JobsIterator queryAllJobs(String topic, Map<String, Object>... filterProps);
+
+ /**
* This is a unique identifer which can be used to cancel the job.
+ * @deprecated Use {@link org.apache.sling.event.jobs.JobUtil#JOB_ID}
*/
+ @Deprecated
String PROPERTY_EVENT_ID = "slingevent:eventId";
/**
@@ -110,92 +202,4 @@ public interface JobStatusProvider {
*/
@Deprecated
void cancelJob(String topic, String jobId);
-
- /**
- * Cancel this job.
- * Cancelling a job might fail if the job is currently in processing.
- * @param jobId The unique identifer as found in the property {@link #PROPERTY_EVENT_ID}.
- * @return <code>true</code> if the job could be cancelled or does not exist anymore.
- * <code>false</code> otherwise.
- * @since 2.4.0
- */
- boolean removeJob(String jobId);
-
- /**
- * Cancel this job.
- * Cancelling a job might fail if the job is currently in processing.
- * This method can be used if the topic and the provided job id is known.
- * @param topic The job topic as put into the property {@link EventUtil#PROPERTY_JOB_TOPIC}.
- * @param jobId The unique identifer as put into the property {@link EventUtil#PROPERTY_JOB_ID}.
- * @return <code>true</code> if the job could be cancelled or does not exist anymore.
- * <code>false</code> otherwise.
- * @since 2.4.0
- */
- boolean removeJob(String topic, String jobId);
-
- /**
- * Cancel this job.
- * This method acts like {@link #removeJob(String)} with the exception that it waits
- * for a job to finish. The job will be removed when this method returns - however
- * this method blocks until the job is finished!
- * @param jobId The unique identifer as found in the property {@link #PROPERTY_EVENT_ID}.
- * @since 2.4.0
- */
- void forceRemoveJob(String jobId);
-
- /**
- * Cancel this job.
- * This method acts like {@link #removeJob(String, String)} with the exception that it waits
- * for a job to finish. The job will be removed when this method returns - however
- * this method blocks until the job is finished!
- * This method can be used if the topic and the provided job id is known.
- * @param topic The job topic as put into the property {@link EventUtil#PROPERTY_JOB_TOPIC}.
- * @param jobId The unique identifer as put into the property {@link EventUtil#PROPERTY_JOB_ID}.
- * @since 2.4.0
- */
- void forceRemoveJob(String topic, String jobId);
-
- /**
- * Wake up the named job queue.
- * If a job failed, the job queue waits (sleeps) for a configured time. By calling this
- * method, the job queue can be woken up and force an immediate reprocessing.
- * @param jobQueueName The name of the queue.
- */
- void wakeUpJobQueue(final String jobQueueName);
-
- /**
- * Return a list of currently scheduled jobs.
- * @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 job
- * must match the template (AND query). By providing several maps, different filters
- * are possible (OR query).
- * @return A non null collection.
- * @since 2.4
- */
- JobsIterator queryScheduledJobs(String topic, Map<String, Object>... filterProps);
-
- /**
- * Return the jobs which are currently in processing. If there are several application nodes
- * in the cluster, there could be more than one job in processing
- * @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 job
- * must match the template (AND query). By providing several maps, different filters
- * are possible (OR query).
- * @return A non null collection.
- * @since 2.4
- */
- JobsIterator queryCurrentJobs(String topic, Map<String, Object>... filterProps);
-
- /**
- * Return all jobs either running or scheduled.
- * This is actually a convenience method and collects the results from {@link #getScheduledJobs(String, Map...)}
- * and {@link #getCurrentJobs(String, Map...)}
- * @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 job
- * must match the template (AND query). By providing several maps, different filters
- * are possible (OR query).
- * @return A non null collection.
- * @since 2.4
- */
- JobsIterator queryAllJobs(String topic, Map<String, Object>... filterProps);
}
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobsIterator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobsIterator.java?rev=1022923&r1=1022922&r2=1022923&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobsIterator.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/JobsIterator.java Fri Oct 15 14:02:23 2010
@@ -18,8 +18,6 @@
*/
package org.apache.sling.event;
-import java.util.Iterator;
-
import org.osgi.service.event.Event;
/**
@@ -29,28 +27,10 @@ import org.osgi.service.event.Event;
* If the iterator is not used to iterate through the whole collection
* of jobs, the {@link #close()} method must be called in order to
* free resources!
+ * @deprecated
*/
-public interface JobsIterator extends Iterator<Event> {
-
- /**
- * Skip a number of jobs.
- * @param skipNum the non-negative number of elements to skip
- * @throws java.util.NoSuchElementException
- * if skipped past the last job in the iterator.
- */
- void skip(long skipNum);
-
- /**
- * Returns the total number of jobs. In some cases a precise information
- * is not available. In these cases -1 is returned.
- */
- long getSize();
-
- /**
- * Returns the current position within the iterator. The number returned is
- * the 0-based index of the next job.
- */
- long getPosition();
+@Deprecated
+public interface JobsIterator extends org.apache.sling.event.jobs.JobsIterator {
/**
* Releases this iterators resources immediately instead of waiting for this
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java?rev=1022923&r1=1022922&r2=1022923&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java Fri Oct 15 14:02:23 2010
@@ -32,16 +32,13 @@ import javax.jcr.observation.EventListen
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
-import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.apache.sling.commons.osgi.OsgiUtil;
-import org.apache.sling.event.JobStatusProvider;
-import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.settings.SlingSettingsService;
+import org.apache.sling.event.impl.jobs.jcr.JCRHelper;
+import org.apache.sling.event.impl.support.Environment;
+import org.apache.sling.event.jobs.JobUtil;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.event.Event;
-import org.osgi.service.event.EventAdmin;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -64,15 +61,6 @@ public abstract class AbstractRepository
@Property(value=DEFAULT_PROPERTY_REPO_PATH)
protected static final String CONFIG_PROPERTY_REPO_PATH = "repository.path";
- @Reference
- protected SlingRepository repository;
-
- @Reference
- protected EventAdmin eventAdmin;
-
- /** Our application id. */
- protected String applicationId;
-
/** The repository session to write into the repository. */
protected Session writerSession;
@@ -91,38 +79,26 @@ public abstract class AbstractRepository
/** A local queue for writing received events into the repository. */
protected final BlockingQueue<Event> writeQueue = new LinkedBlockingQueue<Event>();
- @Reference(policy=ReferencePolicy.DYNAMIC)
- protected DynamicClassLoaderManager classLoaderManager;
-
/**
- * Our thread pool.
+ * Environment component.
*/
@Reference
- protected ThreadPool threadPool;
-
- /** Sling settings service. */
- @Reference
- protected SlingSettingsService settingsService;
+ protected EnvironmentComponent environment;
/** The root node for writing. */
private Node writeRootNode;
- public static String APPLICATION_ID;
-
/**
* Activate this component.
* @param context
- * @throws RepositoryException
*/
protected void activate(final ComponentContext context) {
- this.applicationId = this.settingsService.getSlingId();
- APPLICATION_ID = this.applicationId;
this.repositoryPath = OsgiUtil.toString(context.getProperties().get(
CONFIG_PROPERTY_REPO_PATH), DEFAULT_PROPERTY_REPO_PATH);
this.running = true;
// start writer thread
- this.threadPool.execute(new Runnable() {
+ final Thread writerThread = new Thread(new Runnable() {
public void run() {
try {
synchronized ( writeLock ) {
@@ -144,7 +120,8 @@ public abstract class AbstractRepository
}
}
});
- this.threadPool.execute(new Runnable() {
+ writerThread.start();
+ final Thread backgroundThread = new Thread(new Runnable() {
public void run() {
try {
runInBackground();
@@ -154,21 +131,13 @@ public abstract class AbstractRepository
}
}
});
+ backgroundThread.start();
}
protected abstract void runInBackground() throws RepositoryException;
protected abstract void processWriteQueue();
- protected ClassLoader getDynamicClassLoader() {
- final DynamicClassLoaderManager dclm = this.classLoaderManager;
- if ( dclm != null ) {
- return dclm.getDynamicClassLoader();
- }
- // if we don't have a dynamic classloader, we return our classloader
- return this.getClass().getClassLoader();
- }
-
/**
* Deactivate this component.
* @param context
@@ -190,29 +159,15 @@ public abstract class AbstractRepository
}
/**
- * Create a new session.
- * @return
- * @throws RepositoryException
- */
- protected Session createSession()
- throws RepositoryException {
- final SlingRepository repo = this.repository;
- if ( repo == null ) {
- throw new RepositoryException("Repository is currently not available.");
- }
- return repo.loginAdministrative(null);
- }
-
- /**
* 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 {
- this.writerSession = this.createSession();
+ this.writerSession = this.environment.createAdminSession();
this.writeRootNode = this.createPath(this.writerSession.getRootNode(),
this.repositoryPath.substring(1),
- EventHelper.NODETYPE_ORDERED_FOLDER);
+ JCRHelper.NODETYPE_ORDERED_FOLDER);
this.writerSession.save();
}
@@ -236,7 +191,7 @@ public abstract class AbstractRepository
* Return the node type for the event.
*/
protected String getEventNodeType() {
- return EventHelper.EVENT_NODE_TYPE;
+ return JCRHelper.EVENT_NODE_TYPE;
}
/**
@@ -264,17 +219,17 @@ public abstract class AbstractRepository
} else {
final Calendar now = Calendar.getInstance();
final int sepPos = nodeType.indexOf(':');
- nodeName = nodeType.substring(sepPos+1) + "-" + this.applicationId + "-" + now.getTime().getTime();
+ nodeName = nodeType.substring(sepPos+1) + "-" + Environment.APPLICATION_ID + "-" + now.getTime().getTime();
}
final Node eventNode = this.createPath(rootNode,
nodeName,
nodeType);
- eventNode.setProperty(EventHelper.NODE_PROPERTY_CREATED, Calendar.getInstance());
- eventNode.setProperty(EventHelper.NODE_PROPERTY_TOPIC, e.getTopic());
- eventNode.setProperty(EventHelper.NODE_PROPERTY_APPLICATION, this.applicationId);
+ eventNode.setProperty(JCRHelper.NODE_PROPERTY_CREATED, Calendar.getInstance());
+ eventNode.setProperty(JCRHelper.NODE_PROPERTY_TOPIC, e.getTopic());
+ eventNode.setProperty(JCRHelper.NODE_PROPERTY_APPLICATION, Environment.APPLICATION_ID);
- EventHelper.writeEventProperties(eventNode, e);
+ JCRHelper.writeEventProperties(eventNode, e);
this.addNodeProperties(eventNode, e);
writerSession.save();
@@ -289,22 +244,11 @@ public abstract class AbstractRepository
*/
protected Event readEvent(Node eventNode)
throws RepositoryException, ClassNotFoundException {
- return this.readEvent(eventNode, false);
- }
-
- /**
- * Read an event from the repository.
- * @return
- * @throws RepositoryException
- * @throws ClassNotFoundException
- */
- protected Event readEvent(Node eventNode, final boolean forceLoad)
- throws RepositoryException, ClassNotFoundException {
- final String topic = eventNode.getProperty(EventHelper.NODE_PROPERTY_TOPIC).getString();
- final ClassLoader cl = this.getDynamicClassLoader();
- final Dictionary<String, Object> eventProps = EventHelper.readEventProperties(eventNode, cl, forceLoad);
+ final String topic = eventNode.getProperty(JCRHelper.NODE_PROPERTY_TOPIC).getString();
+ final ClassLoader cl = this.environment.getDynamicClassLoader();
+ final Dictionary<String, Object> eventProps = JCRHelper.readEventProperties(eventNode, cl, false);
- eventProps.put(JobStatusProvider.PROPERTY_EVENT_ID, eventNode.getPath());
+ eventProps.put(JobUtil.JOB_ID, eventNode.getPath());
this.addEventProperties(eventNode, eventProps);
try {
final Event event = new Event(topic, eventProps);
@@ -376,7 +320,7 @@ public abstract class AbstractRepository
final String token = st.nextToken();
if ( !node.hasNode(token) ) {
try {
- node.addNode(token, EventHelper.NODETYPE_FOLDER);
+ node.addNode(token, JCRHelper.NODETYPE_FOLDER);
node.getSession().save();
} catch (RepositoryException re) {
// we ignore this as this folder might be created from a different task
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java?rev=1022923&r1=1022922&r2=1022923&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java Fri Oct 15 14:02:23 2010
@@ -36,6 +36,7 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.event.EventUtil;
+import org.apache.sling.event.impl.jobs.jcr.JCRHelper;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
@@ -64,13 +65,13 @@ public class DistributingEventHandler
implements Runnable {
/** Default clean up time is 15 minutes. */
- protected static final int DEFAULT_CLEANUP_PERIOD = 15;
+ private static final int DEFAULT_CLEANUP_PERIOD = 15;
@Property(intValue=DEFAULT_CLEANUP_PERIOD)
- protected static final String CONFIG_PROPERTY_CLEANUP_PERIOD = "cleanup.period";
+ private static final String CONFIG_PROPERTY_CLEANUP_PERIOD = "cleanup.period";
/** We remove everything which is older than 15min by default. */
- protected int cleanupPeriod = DEFAULT_CLEANUP_PERIOD;
+ private int cleanupPeriod = DEFAULT_CLEANUP_PERIOD;
/**
* @see org.apache.sling.event.impl.AbstractRepositoryEventHandler#activate(org.osgi.service.component.ComponentContext)
@@ -96,7 +97,7 @@ public class DistributingEventHandler
final Query q = qomf.createQuery(
qomf.selector(getEventNodeType(), selectorName),
qomf.and(qomf.descendantNode(selectorName, this.repositoryPath),
- qomf.comparison(qomf.propertyValue(selectorName, EventHelper.NODE_PROPERTY_CREATED),
+ qomf.comparison(qomf.propertyValue(selectorName, JCRHelper.NODE_PROPERTY_CREATED),
QueryObjectModelFactory.JCR_OPERATOR_LESS_THAN,
qomf.literal(s.getValueFactory().createValue(deleteBefore)))),
null,
@@ -116,7 +117,7 @@ public class DistributingEventHandler
// we create an own session for concurrency issues
Session s = null;
try {
- s = this.createSession();
+ s = this.environment.createAdminSession();
final Query q = this.getCleanUpQuery(s);
if ( logger.isDebugEnabled() ) {
logger.debug("Executing query {}", q.getStatement());
@@ -182,10 +183,10 @@ public class DistributingEventHandler
if ( info.nodePath != null) {
Session session = null;
try {
- session = this.createSession();
+ session = this.environment.createAdminSession();
final Node eventNode = (Node)session.getItem(info.nodePath);
if ( eventNode.isNodeType(this.getEventNodeType()) ) {
- final EventAdmin localEA = this.eventAdmin;
+ final EventAdmin localEA = this.environment.getEventAdmin();
if ( localEA != null ) {
localEA.postEvent(this.readEvent(eventNode));
} else {
@@ -241,7 +242,7 @@ public class DistributingEventHandler
protected void addEventProperties(Node eventNode, Dictionary<String, Object> properties)
throws RepositoryException {
super.addEventProperties(eventNode, properties);
- properties.put(EventUtil.PROPERTY_APPLICATION, eventNode.getProperty(EventHelper.NODE_PROPERTY_APPLICATION).getString());
+ properties.put(EventUtil.PROPERTY_APPLICATION, eventNode.getProperty(JCRHelper.NODE_PROPERTY_APPLICATION).getString());
}
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java?rev=1022923&r1=1022922&r2=1022923&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java Fri Oct 15 14:02:23 2010
@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.commons.threads.ModifiableThreadPoolConfig;
+import org.apache.sling.commons.threads.ThreadPool;
import org.apache.sling.commons.threads.ThreadPoolConfig;
import org.apache.sling.commons.threads.ThreadPoolConfig.ThreadPriority;
import org.apache.sling.commons.threads.ThreadPoolManager;
@@ -37,31 +38,29 @@ import org.osgi.service.component.Compon
@Component(label="%event.pool.name",
description="%event.pool.description",
metatype=true)
-@Service(value=ThreadPool.class)
+@Service(value=EventingThreadPool.class)
public class EventingThreadPool implements ThreadPool {
@Reference
- protected ThreadPoolManager threadPoolManager;
+ private ThreadPoolManager threadPoolManager;
/** The real thread pool used. */
private org.apache.sling.commons.threads.ThreadPool threadPool;
private static final int DEFAULT_MIN_POOL_SIZE = 35; // this is sufficient for all threads + approx 25 job queues
private static final int DEFAULT_MAX_POOL_SIZE = 50;
- private static final int DEFAULT_QUEUE_SIZE = -1; // infinite
@Property(intValue=DEFAULT_MIN_POOL_SIZE)
private static final String PROPERTY_MIN_POOL_SIZE = "minPoolSize";
@Property(intValue=DEFAULT_MAX_POOL_SIZE)
private static final String PROPERTY_MAX_POOL_SIZE = "maxPoolSize";
- @Property(intValue=DEFAULT_QUEUE_SIZE)
- private static final String PROPERTY_QUEUE_SIZE = "queueSize";
@Property(value="NORM",
options={@PropertyOption(name="NORM",value="Norm"),
@PropertyOption(name="MIN",value="Min"),
@PropertyOption(name="MAX",value="Max")})
private static final String PROPERTY_PRIORITY = "priority";
+
/**
* Activate this component.
* @param context
@@ -70,11 +69,11 @@ public class EventingThreadPool implemen
final ModifiableThreadPoolConfig config = new ModifiableThreadPoolConfig();
config.setMinPoolSize(OsgiUtil.toInteger(ctx.getProperties().get(PROPERTY_MIN_POOL_SIZE), DEFAULT_MIN_POOL_SIZE));
config.setMaxPoolSize(OsgiUtil.toInteger(ctx.getProperties().get(PROPERTY_MAX_POOL_SIZE), DEFAULT_MAX_POOL_SIZE));
- config.setQueueSize(OsgiUtil.toInteger(ctx.getProperties().get(PROPERTY_QUEUE_SIZE), DEFAULT_QUEUE_SIZE));
+ config.setQueueSize(-1); // unlimited
config.setShutdownGraceful(true);
config.setPriority(ThreadPriority.valueOf(OsgiUtil.toString(ctx.getProperties().get(PROPERTY_PRIORITY), "NORM")));
config.setDaemon(true);
- this.threadPool = threadPoolManager.create(config);
+ this.threadPool = threadPoolManager.create(config, "Apache Sling Eventing Thread Pool");
}
/**
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java?rev=1022923&r1=1022922&r2=1022923&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java Fri Oct 15 14:02:23 2010
@@ -58,6 +58,10 @@ import org.apache.sling.commons.schedule
import org.apache.sling.commons.scheduler.Scheduler;
import org.apache.sling.event.EventUtil;
import org.apache.sling.event.TimedEventStatusProvider;
+import org.apache.sling.event.impl.jobs.Utility;
+import org.apache.sling.event.impl.jobs.jcr.JCRHelper;
+import org.apache.sling.event.impl.support.Environment;
+import org.apache.sling.event.jobs.JobUtil;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
@@ -79,17 +83,17 @@ public class TimedJobHandler
extends AbstractRepositoryEventHandler
implements Job, TimedEventStatusProvider {
- protected static final String JOB_TOPIC = "topic";
+ private static final String JOB_TOPIC = "topic";
- protected static final String JOB_CONFIG = "config";
+ private static final String JOB_CONFIG = "config";
- protected static final String JOB_SCHEDULE_INFO = "info";
+ private static final String JOB_SCHEDULE_INFO = "info";
@Reference
- protected Scheduler scheduler;
+ private Scheduler scheduler;
/** Unloaded events. */
- protected Set<String>unloadedEvents = new HashSet<String>();
+ private Set<String>unloadedEvents = new HashSet<String>();
/**
* @see org.apache.sling.event.impl.AbstractRepositoryEventHandler#startWriterSession()
@@ -346,7 +350,7 @@ public class TimedJobHandler
if ( "jcr:lockOwner".equals(propertyName) ) {
try {
if ( s == null ) {
- s = this.createSession();
+ s = this.environment.createAdminSession();
}
final Node eventNode = (Node) s.getItem(nodePath);
if ( !eventNode.isLocked() ) {
@@ -412,7 +416,7 @@ public class TimedJobHandler
final Set<String> newUnloadedEvents = new HashSet<String>();
newUnloadedEvents.addAll(unloadedEvents);
try {
- s = createSession();
+ s = environment.createAdminSession();
for(String path : unloadedEvents ) {
newUnloadedEvents.remove(path);
try {
@@ -455,7 +459,7 @@ public class TimedJobHandler
}
};
- this.threadPool.execute(t);
+ Environment.THREAD_POOL.execute(t);
}
}
}
@@ -467,7 +471,7 @@ public class TimedJobHandler
final String topic = (String) context.getConfiguration().get(JOB_TOPIC);
@SuppressWarnings("unchecked")
final Dictionary<Object, Object> properties = (Dictionary<Object, Object>) context.getConfiguration().get(JOB_CONFIG);
- final EventAdmin ea = this.eventAdmin;
+ final EventAdmin ea = this.environment.getEventAdmin();
if ( ea != null ) {
try {
ea.postEvent(new Event(topic, properties));
@@ -484,7 +488,7 @@ public class TimedJobHandler
// we create an own session here
Session s = null;
try {
- s = this.createSession();
+ s = this.environment.createAdminSession();
if ( s.itemExists(this.repositoryPath) ) {
final Node parentNode = (Node)s.getItem(this.repositoryPath);
final String nodeName = info.jobId;
@@ -565,18 +569,18 @@ public class TimedJobHandler
protected void addNodeProperties(Node eventNode, Event event)
throws RepositoryException {
super.addNodeProperties(eventNode, event);
- eventNode.setProperty(EventHelper.NODE_PROPERTY_TOPIC, (String)event.getProperty(EventUtil.PROPERTY_TIMED_EVENT_TOPIC));
+ eventNode.setProperty(JCRHelper.NODE_PROPERTY_TOPIC, (String)event.getProperty(EventUtil.PROPERTY_TIMED_EVENT_TOPIC));
final ScheduleInfo info = new ScheduleInfo(event);
if ( info.date != null ) {
final Calendar c = Calendar.getInstance();
c.setTime(info.date);
- eventNode.setProperty(EventHelper.NODE_PROPERTY_TE_DATE, c);
+ eventNode.setProperty(JCRHelper.NODE_PROPERTY_TE_DATE, c);
}
if ( info.expression != null ) {
- eventNode.setProperty(EventHelper.NODE_PROPERTY_TE_EXPRESSION, info.expression);
+ eventNode.setProperty(JCRHelper.NODE_PROPERTY_TE_EXPRESSION, info.expression);
}
if ( info.period != null ) {
- eventNode.setProperty(EventHelper.NODE_PROPERTY_TE_PERIOD, info.period.longValue());
+ eventNode.setProperty(JCRHelper.NODE_PROPERTY_TE_PERIOD, info.period.longValue());
}
}
@@ -584,7 +588,7 @@ public class TimedJobHandler
* @see org.apache.sling.event.impl.AbstractRepositoryEventHandler#getEventNodeType()
*/
protected String getEventNodeType() {
- return EventHelper.TIMED_EVENT_NODE_TYPE;
+ return JCRHelper.TIMED_EVENT_NODE_TYPE;
}
protected static final class ScheduleInfo implements Serializable {
@@ -624,7 +628,7 @@ public class TimedJobHandler
throw new IllegalArgumentException("Timed event does not contain required property " + EventUtil.PROPERTY_TIMED_EVENT_TOPIC);
}
String id = (String)event.getProperty(EventUtil.PROPERTY_TIMED_EVENT_ID);
- String jId = (String)event.getProperty(EventUtil.PROPERTY_JOB_ID);
+ String jId = (String)event.getProperty(JobUtil.PROPERTY_JOB_NAME);
//this.jobId = getJobId(topic, id, jId);
this.jobId = getJobId(topic, id, jId);
@@ -646,7 +650,7 @@ public class TimedJobHandler
}
public static String getJobId(String topic, String timedEventId, String jobId) {
- return topic.replace('/', '.') + "/TimedEvent " + (timedEventId != null ? EventHelper.filter(timedEventId) : "") + '_' + (jobId != null ? EventHelper.filter(jobId) : "");
+ return topic.replace('/', '.') + "/TimedEvent " + (timedEventId != null ? Utility.filter(timedEventId) : "") + '_' + (jobId != null ? Utility.filter(jobId) : "");
}
}
@@ -656,7 +660,7 @@ public class TimedJobHandler
public Event getScheduledEvent(String topic, String eventId, String jobId) {
Session s = null;
try {
- s = this.createSession();
+ s = this.environment.createAdminSession();
if ( s.itemExists(this.repositoryPath) ) {
final Node parentNode = (Node)s.getItem(this.repositoryPath);
final String nodeName = ScheduleInfo.getJobId(topic, eventId, jobId);
@@ -685,7 +689,7 @@ public class TimedJobHandler
Session s = null;
final List<Event> jobs = new ArrayList<Event>();
try {
- s = this.createSession();
+ s = this.environment.createAdminSession();
final QueryManager qManager = s.getWorkspace().getQueryManager();
final String selectorName = "nodetype";
@@ -706,10 +710,10 @@ public class TimedJobHandler
while ( i.hasNext() ) {
final Map.Entry<String, Object> current = i.next();
// check prop name first
- final String propName = EventHelper.getNodePropertyName(current.getKey());
+ final String propName = JCRHelper.getNodePropertyName(current.getKey());
if ( propName != null ) {
// check value
- final Value value = EventHelper.getNodePropertyValue(s.getValueFactory(), current.getValue());
+ final Value value = JCRHelper.getNodePropertyValue(s.getValueFactory(), current.getValue());
if ( value != null ) {
final Comparison newComp = qomf.comparison(qomf.propertyValue(selectorName, propName),
QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO,