[jboss-cvs] JBossAS SVN: r86482 - in projects/jboss-threads/trunk: main/src/main/java/org/jboss/threads and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 30 15:26:43 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-03-30 15:26:43 -0400 (Mon, 30 Mar 2009)
New Revision: 86482

Added:
   projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ProtectedScheduledExecutorService.java
Modified:
   projects/jboss-threads/trunk/jbossmc/src/main/resources/schema/jboss-threads_1_0.xsd
   projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java
Log:
add a protected scheduled executor service implementation (JBTHR-4)

Modified: projects/jboss-threads/trunk/jbossmc/src/main/resources/schema/jboss-threads_1_0.xsd
===================================================================
--- projects/jboss-threads/trunk/jbossmc/src/main/resources/schema/jboss-threads_1_0.xsd	2009-03-30 19:11:05 UTC (rev 86481)
+++ projects/jboss-threads/trunk/jbossmc/src/main/resources/schema/jboss-threads_1_0.xsd	2009-03-30 19:26:43 UTC (rev 86482)
@@ -21,6 +21,7 @@
                 <xsd:element name="thread-group" type="thread-group"/>
                 <xsd:element name="thread-factory" type="thread-factory"/>
                 <xsd:element name="thread-pool-executor" type="thread-pool-executor"/>
+                <xsd:element name="scheduled-thread-pool-executor" type="scheduled-thread-pool-executor"/>
                 <xsd:element name="direct-executor" type="direct-executor"/>
                 <xsd:element name="notating-executor" type="notating-executor"/>
             </xsd:choice>
@@ -95,9 +96,8 @@
                 threads.  The nested "core-pool-size" element may be used to specify the core thread pool size.
                 The nested "max-pool-size" element may be used to specify the maximum thread pool size.  The nested
                 "keepalive-time" is used to specify the amount of time that threads beyond the core pool size should
-                be kept running when idle.  One of the "unbounded-queue", "bounded-queue", or "direct-queue" nested
-                elements may be specified to control the type of queue to use for tasks.  The nested "reject-policy"
-                element may be used to specify how rejected tasks are handled.
+                be kept running when idle.  The nested "reject-policy" element may be used to specify how rejected tasks
+                are handled.
             </xsd:documentation>
         </xsd:annotation>
         <xsd:sequence>
@@ -112,6 +112,26 @@
         <xsd:attribute name="queue-length" use="optional" type="xsd:integer"/>
     </xsd:complexType>
 
+    <xsd:complexType name="scheduled-thread-pool-executor">
+        <xsd:annotation>
+            <xsd:documentation>
+                A scheduled thread pool executor.  The "name" attribute is the bean name of the created executor.  The
+                "thread-factory" attribute specifies the bean name of the thread factory to use to create worker
+                threads.  The nested "pool-size" element may be used to specify the thread pool size.  The nested
+                "keepalive-time" element is used to specify the amount of time that threads should be kept running when idle.
+                The "executor-name" element may be used to specify an executor which should run tasks that are dequeued.
+                If it is not specified, then this executor's threads will run the tasks directly.
+            </xsd:documentation>
+        </xsd:annotation>
+        <xsd:sequence>
+            <xsd:element name="pool-size" type="pool-size" minOccurs="0" maxOccurs="1"/>
+            <xsd:element name="keepalive-time" type="time" minOccurs="0" maxOccurs="1"/>
+            <xsd:element name="executor-name" type="xsd:string" minOccurs="0" maxOccurs="1"/>
+        </xsd:sequence>
+        <xsd:attribute name="name" use="required" type="xsd:string"/>
+        <xsd:attribute name="thread-factory" use="required" type="xsd:string"/>
+    </xsd:complexType>
+
     <xsd:complexType name="direct-executor">
         <xsd:annotation>
             <xsd:documentation>

Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java	2009-03-30 19:11:05 UTC (rev 86481)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java	2009-03-30 19:26:43 UTC (rev 86482)
@@ -28,6 +28,7 @@
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.RejectedExecutionHandler;
 import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ScheduledExecutorService;
 import java.security.PrivilegedAction;
 import java.security.AccessController;
 import java.security.AccessControlContext;
@@ -335,7 +336,7 @@
     }
 
     /**
-     * Wrap an executor with an {@code ExecutorService} instance, which supports all the features of {@code ExecutorService}
+     * Wrap an executor with an {@code ExecutorService} instance which supports all the features of {@code ExecutorService}
      * except for shutting down the executor.
      *
      * @param target the target executor
@@ -346,7 +347,7 @@
     }
 
     /**
-     * Wrap a direct executor with an {@code DirectExecutorService} instance, which supports all the features of {@code ExecutorService}
+     * Wrap a direct executor with an {@code DirectExecutorService} instance which supports all the features of {@code ExecutorService}
      * except for shutting down the executor.
      *
      * @param target the target executor
@@ -355,4 +356,15 @@
     public static DirectExecutorService protectedDirectExecutorService(final DirectExecutor target) {
         return new ProtectedDirectExecutorService(target);
     }
+
+    /**
+     * Wrap a scheduled executor with a {@code ScheduledExecutorService} instance which supports all the features of
+     * {@code ScheduledExecutorService} except for shutting down the executor.
+     *
+     * @param target the target executor
+     * @return the executor service
+     */
+    public static ScheduledExecutorService protectedScheduledExecutorService(final ScheduledExecutorService target) {
+        return new ProtectedScheduledExecutorService(target);
+    }
 }

Copied: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ProtectedScheduledExecutorService.java (from rev 85129, projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ProtectedExecutorService.java)
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ProtectedScheduledExecutorService.java	                        (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ProtectedScheduledExecutorService.java	2009-03-30 19:26:43 UTC (rev 86482)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.threads;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.Callable;
+
+/**
+ * An implementation of {@code ScheduledExecutorService} that delegates to the real executor, while disallowing termination.
+ */
+public class ProtectedScheduledExecutorService extends ProtectedExecutorService implements ScheduledExecutorService {
+    private final ScheduledExecutorService delegate;
+
+    public ProtectedScheduledExecutorService(final ScheduledExecutorService delegate) {
+        super(delegate);
+        this.delegate = delegate;
+    }
+
+    public ScheduledFuture<?> schedule(final Runnable command, final long delay, final TimeUnit unit) {
+        return delegate.schedule(command, delay, unit);
+    }
+
+    public <V> ScheduledFuture<V> schedule(final Callable<V> callable, final long delay, final TimeUnit unit) {
+        return delegate.schedule(callable, delay, unit);
+    }
+
+    public ScheduledFuture<?> scheduleAtFixedRate(final Runnable command, final long initialDelay, final long period, final TimeUnit unit) {
+        return delegate.scheduleAtFixedRate(command, initialDelay, period, unit);
+    }
+
+    public ScheduledFuture<?> scheduleWithFixedDelay(final Runnable command, final long initialDelay, final long delay, final TimeUnit unit) {
+        return delegate.scheduleWithFixedDelay(command, initialDelay, delay, unit);
+    }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list