[infinispan-commits] Infinispan SVN: r2593 - in branches/4.2.x/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:03:27 EDT 2010
Author: manik.surtani at jboss.com
Date: 2010-10-25 10:03:27 -0400 (Mon, 25 Oct 2010)
New Revision: 2593
Added:
branches/4.2.x/core/src/main/java/org/infinispan/executors/AbstractSharedExecutorFactory.java
branches/4.2.x/core/src/main/java/org/infinispan/executors/DefaultSharedExecutorFactory.java
branches/4.2.x/core/src/main/java/org/infinispan/executors/DefaultSharedScheduledExecutorFactory.java
Modified:
branches/4.2.x/core/src/main/java/org/infinispan/config/GlobalConfiguration.java
Log:
ISPN-730 - A DefaultSharedExecutorFactory is needed
Modified: branches/4.2.x/core/src/main/java/org/infinispan/config/GlobalConfiguration.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/config/GlobalConfiguration.java 2010-10-25 13:20:55 UTC (rev 2592)
+++ branches/4.2.x/core/src/main/java/org/infinispan/config/GlobalConfiguration.java 2010-10-25 14:03:27 UTC (rev 2593)
@@ -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;
@@ -585,7 +587,7 @@
@XmlAttribute
@ConfigurationDoc(name="factory", desc="Fully qualified class name of the ExecutorFactory to use. Must implement org.infinispan.executors.ExecutorFactory")
- protected String factory = DefaultExecutorFactory.class.getName();
+ protected String factory = DefaultSharedExecutorFactory.class.getName();
public ExecutorFactoryType(String factory) {
this.factory = factory;
@@ -623,7 +625,7 @@
@XmlAttribute
@ConfigurationDoc(name="factory",desc="Fully qualified class name of the ScheduledExecutorFactory to use. Must implement org.infinispan.executors.ScheduledExecutorFactory")
- protected String factory = DefaultScheduledExecutorFactory.class.getName();
+ protected String factory = DefaultSharedScheduledExecutorFactory.class.getName();
public ScheduledExecutorFactoryType(String factory) {
this.factory = factory;
Added: branches/4.2.x/core/src/main/java/org/infinispan/executors/AbstractSharedExecutorFactory.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/executors/AbstractSharedExecutorFactory.java (rev 0)
+++ branches/4.2.x/core/src/main/java/org/infinispan/executors/AbstractSharedExecutorFactory.java 2010-10-25 14:03:27 UTC (rev 2593)
@@ -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: branches/4.2.x/core/src/main/java/org/infinispan/executors/DefaultSharedExecutorFactory.java (from rev 2590, branches/4.2.x/core/src/main/java/org/infinispan/executors/DefaultExecutorFactory.java)
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/executors/DefaultSharedExecutorFactory.java (rev 0)
+++ branches/4.2.x/core/src/main/java/org/infinispan/executors/DefaultSharedExecutorFactory.java 2010-10-25 14:03:27 UTC (rev 2593)
@@ -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: branches/4.2.x/core/src/main/java/org/infinispan/executors/DefaultSharedScheduledExecutorFactory.java (from rev 2590, branches/4.2.x/core/src/main/java/org/infinispan/executors/DefaultScheduledExecutorFactory.java)
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/executors/DefaultSharedScheduledExecutorFactory.java (rev 0)
+++ branches/4.2.x/core/src/main/java/org/infinispan/executors/DefaultSharedScheduledExecutorFactory.java 2010-10-25 14:03:27 UTC (rev 2593)
@@ -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