incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r931518 - in /sling/trunk/bundles/extensions/event: pom.xml src/main/java/org/apache/sling/event/EventUtil.java src/main/java/org/apache/sling/event/impl/EventingThreadPool.java src/main/resources/OSGI-INF/metatype/metatype.properties
Date Wed, 07 Apr 2010 12:21:20 GMT
Author: cziegeler
Date: Wed Apr  7 12:21:19 2010
New Revision: 931518

URL: http://svn.apache.org/viewvc?rev=931518&view=rev
Log:
SLING-1474 : Allow to change the priority for jobs

Modified:
    sling/trunk/bundles/extensions/event/pom.xml
    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/impl/EventingThreadPool.java
    sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: sling/trunk/bundles/extensions/event/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/pom.xml?rev=931518&r1=931517&r2=931518&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/pom.xml (original)
+++ sling/trunk/bundles/extensions/event/pom.xml Wed Apr  7 12:21:19 2010
@@ -29,7 +29,7 @@
 
     <artifactId>org.apache.sling.event</artifactId>
     <packaging>bundle</packaging>
-    <version>2.3.1-SNAPSHOT</version>
+    <version>2.4.0-SNAPSHOT</version>
 
     <name>Apache Sling Event Support</name>
     <description>
@@ -60,7 +60,7 @@
                             javax.jcr.*;version=1.0,*
                         </Import-Package>
                         <Export-Package>
-                            org.apache.sling.event;version=2.3.0
+                            org.apache.sling.event;version=2.4.0
                         </Export-Package>
                         <Private-Package>
                             org.apache.sling.event.impl,

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=931518&r1=931517&r2=931518&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
Wed Apr  7 12:21:19 2010
@@ -91,6 +91,25 @@ public abstract class EventUtil {
      */
     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.
+     * 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
+     */
+    public static final String PROPERTY_JOB_PRIORITY = "event.job.priority";
+
+    /**
+     * The priority for jobs.
+     * @since 2.4
+     */
+    public enum JobPriority {
+        NORM,
+        MIN,
+        MAX
+    };
+
     /** The topic for jobs. */
     public static final String TOPIC_JOB = "org/apache/sling/event/job";
 
@@ -302,6 +321,7 @@ public abstract class EventUtil {
                 notify = false;
             }
         }
+        final JobPriority priority = (JobPriority) job.getProperty(PROPERTY_JOB_PRIORITY);
         final boolean notifyResult = notify;
 
         final Runnable task = new Runnable() {
@@ -310,6 +330,18 @@ public abstract class EventUtil {
              * @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);
@@ -318,6 +350,7 @@ public abstract class EventUtil {
                     // we don't reschedule if an exception occurs
                     result = true;
                 } finally {
+                    Thread.currentThread().setPriority(oldPriority);
                     if ( notifyResult ) {
                         if ( result ) {
                             EventUtil.finishedJob(job);

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=931518&r1=931517&r2=931518&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
Wed Apr  7 12:21:19 2010
@@ -20,12 +20,14 @@ package org.apache.sling.event.impl;
 
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyOption;
 import org.apache.felix.scr.annotations.Reference;
 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.ThreadPoolConfig;
 import org.apache.sling.commons.threads.ThreadPoolManager;
+import org.apache.sling.commons.threads.ThreadPoolConfig.ThreadPriority;
 import org.osgi.service.component.ComponentContext;
 
 
@@ -55,6 +57,11 @@ public class EventingThreadPool implemen
     @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
@@ -65,6 +72,7 @@ public class EventingThreadPool implemen
         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.setShutdownGraceful(true);
+        config.setPriority(ThreadPriority.valueOf(OsgiUtil.toString(ctx.getProperties().get(PROPERTY_PRIORITY),
"NORM")));
         this.threadPool = threadPoolManager.create(config);
     }
 

Modified: sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=931518&r1=931517&r2=931518&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties
Wed Apr  7 12:21:19 2010
@@ -111,6 +111,9 @@ maxPoolSize.description = The maximum po
 queueSize.name = Queue Size
 queueSize.description = The maximum size of the thread queue if the pool is exhausted.
 
+priority.name = Priority
+priority.description = The priority for the threads from this pool. Default is norm.
+
 #
 # Shared labels
 scheduler.period.name = Event Cleanup Internal



Mime
View raw message