[infinispan-commits] Infinispan SVN: r2594 - in trunk/core/src/main/java/org/infinispan: executors and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Mon Oct 25 10:09:40 EDT 2010


Author: manik.surtani at jboss.com
Date: 2010-10-25 10:09:40 -0400 (Mon, 25 Oct 2010)
New Revision: 2594

Added:
   trunk/core/src/main/java/org/infinispan/executors/AbstractSharedExecutorFactory.java
   trunk/core/src/main/java/org/infinispan/executors/DefaultSharedExecutorFactory.java
   trunk/core/src/main/java/org/infinispan/executors/DefaultSharedScheduledExecutorFactory.java
Modified:
   trunk/core/src/main/java/org/infinispan/config/GlobalConfiguration.java
Log:
ISPN-730 - A DefaultSharedExecutorFactory is needed (merged from branch 4.2.x, r2593)

Modified: trunk/core/src/main/java/org/infinispan/config/GlobalConfiguration.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/GlobalConfiguration.java	2010-10-25 14:03:27 UTC (rev 2593)
+++ trunk/core/src/main/java/org/infinispan/config/GlobalConfiguration.java	2010-10-25 14:09:40 UTC (rev 2594)
@@ -4,6 +4,8 @@
 import org.infinispan.Version;
 import org.infinispan.executors.DefaultExecutorFactory;
 import org.infinispan.executors.DefaultScheduledExecutorFactory;
+import org.infinispan.executors.DefaultSharedExecutorFactory;
+import org.infinispan.executors.DefaultSharedScheduledExecutorFactory;
 import org.infinispan.factories.GlobalComponentRegistry;
 import org.infinispan.factories.annotations.Inject;
 import org.infinispan.factories.annotations.SurvivesRestarts;
@@ -523,7 +525,7 @@
        * implement org.infinispan.executors.ExecutorFactory"
        */
       @XmlAttribute
-      protected String factory = DefaultExecutorFactory.class.getName();
+      protected String factory = DefaultSharedExecutorFactory.class.getName();
 
       public ExecutorFactoryType(String factory) {
          this.factory = factory;
@@ -563,7 +565,7 @@
        * implement org.infinispan.executors.ScheduledExecutorFactory"
        */
       @XmlAttribute
-      protected String factory = DefaultScheduledExecutorFactory.class.getName();
+      protected String factory = DefaultSharedScheduledExecutorFactory.class.getName();
 
       public ScheduledExecutorFactoryType(String factory) {
          this.factory = factory;

Copied: trunk/core/src/main/java/org/infinispan/executors/AbstractSharedExecutorFactory.java (from rev 2593, branches/4.2.x/core/src/main/java/org/infinispan/executors/AbstractSharedExecutorFactory.java)
===================================================================
--- trunk/core/src/main/java/org/infinispan/executors/AbstractSharedExecutorFactory.java	                        (rev 0)
+++ trunk/core/src/main/java/org/infinispan/executors/AbstractSharedExecutorFactory.java	2010-10-25 14:09:40 UTC (rev 2594)
@@ -0,0 +1,33 @@
+package org.infinispan.executors;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * An abstract class that encapsulates the logic of sharing an {@link ExecutorService} or a {@link ScheduledExecutorService}.
+ *
+ * @author Manik Surtani
+ * @version 4.2
+ *
+ * @see DefaultSharedExecutorFactory
+ * @see DefaultSharedScheduledExecutorFactory
+ */
+public abstract class AbstractSharedExecutorFactory<E extends ExecutorService> {
+
+   private final Map<Properties, E> executors = new HashMap<Properties, E>(2, 0.9f);
+
+   protected abstract E createService(Properties p);
+
+   protected E getOrCreateService(Properties p) {
+      synchronized (executors) {
+         E e = executors.get(p);
+         if (e == null) {
+            e = createService(p);
+            executors.put(p, e);
+         }
+         return e;
+      }
+   }
+}

Copied: trunk/core/src/main/java/org/infinispan/executors/DefaultSharedExecutorFactory.java (from rev 2593, branches/4.2.x/core/src/main/java/org/infinispan/executors/DefaultSharedExecutorFactory.java)
===================================================================
--- trunk/core/src/main/java/org/infinispan/executors/DefaultSharedExecutorFactory.java	                        (rev 0)
+++ trunk/core/src/main/java/org/infinispan/executors/DefaultSharedExecutorFactory.java	2010-10-25 14:09:40 UTC (rev 2594)
@@ -0,0 +1,41 @@
+package org.infinispan.executors;
+
+import org.infinispan.util.TypedProperties;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Default executor factory that creates a single executor and reuses it for subsequent calls to {@link #getExecutor(java.util.Properties)}.
+ * <p />
+ * Note that the executor is only shared amongst equivalent configurations (by checking that the Properties passed in are
+ * equal).  What this means is two calls to {@link #getExecutor(java.util.Properties)} with 2 inequal 
+ * properties parameters will result in 2 separate executors being created.
+ * <p />
+ * The executors created are standard JDK executors, identical to those created by {@link DefaultExecutorFactory}.
+ *
+ * @author Manik Surtani
+ * @since 4.2
+ */
+public class DefaultSharedExecutorFactory extends AbstractSharedExecutorFactory<ExecutorService> implements ExecutorFactory {
+   private final ExecutorFactory delegate = new DefaultExecutorFactory();
+
+   @Override
+   protected ExecutorService createService(Properties p) {
+      return delegate.getExecutor(p);
+   }
+
+   @Override
+   public ExecutorService getExecutor(Properties p) {
+      return getOrCreateService(p);
+   }
+}

Copied: trunk/core/src/main/java/org/infinispan/executors/DefaultSharedScheduledExecutorFactory.java (from rev 2593, branches/4.2.x/core/src/main/java/org/infinispan/executors/DefaultSharedScheduledExecutorFactory.java)
===================================================================
--- trunk/core/src/main/java/org/infinispan/executors/DefaultSharedScheduledExecutorFactory.java	                        (rev 0)
+++ trunk/core/src/main/java/org/infinispan/executors/DefaultSharedScheduledExecutorFactory.java	2010-10-25 14:09:40 UTC (rev 2594)
@@ -0,0 +1,38 @@
+package org.infinispan.executors;
+
+import org.infinispan.util.TypedProperties;
+
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Default executor factory that creates a single scheduled executor and reuses it for subsequent calls to {@link #getScheduledExecutor(java.util.Properties)}.
+ * <p />
+ * Note that the executor is only shared amongst equivalent configurations (by checking that the Properties passed in are
+ * equal).  What this means is two calls to {@link #getScheduledExecutor(java.util.Properties)} with 2 inequal
+ * properties parameters will result in 2 separate executors being created.
+ * <p />
+ * The executors created are standard JDK executors, identical to those created by {@link DefaultExecutorFactory}.
+ *
+ *
+ * @author Manik Surtani
+ * @since 4.2
+ */
+public class DefaultSharedScheduledExecutorFactory extends AbstractSharedExecutorFactory<ScheduledExecutorService> implements ScheduledExecutorFactory {
+
+   private final ScheduledExecutorFactory delegate = new DefaultScheduledExecutorFactory();
+
+   @Override
+   protected ScheduledExecutorService createService(Properties p) {
+      return delegate.getScheduledExecutor(p);
+   }
+
+   @Override
+   public ScheduledExecutorService getScheduledExecutor(Properties p) {
+      return getOrCreateService(p);
+   }
+}



More information about the infinispan-commits mailing list