From beacb948b1e78ca3d32f6dfc2fddc687d41ce151 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 1 Jan 2015 17:04:00 +0100 Subject: [PATCH] Allow configuration of ExecutionStrategy eg -Dorg.eclipse.jetty.io.ManagedSelector.ExecutionStrategy=org.eclipse.jetty.util.thread.ExecutionStrategy$ExecuteProduceRun --- .../eclipse/jetty/http2/HTTP2Connection.java | 2 +- .../org/eclipse/jetty/io/ManagedSelector.java | 2 +- .../jetty/util/thread/ExecutionStrategy.java | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java index 0b97cb53e18..33fe41ae481 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java @@ -51,7 +51,7 @@ public class HTTP2Connection extends AbstractConnection this.parser = parser; this.session = session; this.bufferSize = bufferSize; - this.executionStrategy = new ExecutionStrategy.ExecuteProduceRun(new HTTP2Producer(), executor); + this.executionStrategy = ExecutionStrategy.Factory.instanceFor(new HTTP2Producer(), executor); } protected ISession getSession() diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java index 31ce76ab766..d473ac858dd 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java @@ -68,7 +68,7 @@ public class ManagedSelector extends AbstractLifeCycle implements Runnable, Dump public ManagedSelector(SelectorManager selectorManager, int id) { _selectorManager = selectorManager; - _strategy = new ExecutionStrategy.ExecuteProduceRun(this, selectorManager.getExecutor()); + _strategy = ExecutionStrategy.Factory.instanceFor(this, selectorManager.getExecutor()); _id = id; setStopTimeout(5000); } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java index f98079ce065..88e0392894a 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java @@ -18,9 +18,12 @@ package org.eclipse.jetty.util.thread; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicReference; +import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -56,6 +59,33 @@ public interface ExecutionStrategy Runnable produce(); } + public static class Factory + { + private static final Logger LOG = Log.getLogger(Factory.class); + + public static ExecutionStrategy instanceFor(Producer producer, Executor executor) + { + // TODO remove this mechanism before release + String strategy = System.getProperty(producer.getClass().getName()+".ExecutionStrategy"); + if (strategy!=null) + { + try + { + Class c = Loader.loadClass(producer.getClass(),strategy); + Constructor m = c.getConstructor(Producer.class,Executor.class); + LOG.info("Use {} for {}",c.getSimpleName(),producer.getClass().getName()); + return m.newInstance(producer,executor); + } + catch(Exception e) + { + LOG.warn(e); + } + } + + return new ExecuteProduceRun(producer,executor); + } + } + /** *

A strategy where the caller thread iterates over task production, submitting each * task to an {@link Executor} for execution.