Allow configuration of ExecutionStrategy
eg -Dorg.eclipse.jetty.io.ManagedSelector.ExecutionStrategy=org.eclipse.jetty.util.thread.ExecutionStrategy$ExecuteProduceRun
This commit is contained in:
parent
3af9b145a3
commit
beacb948b1
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<? extends ExecutionStrategy> c = Loader.loadClass(producer.getClass(),strategy);
|
||||
Constructor<? extends ExecutionStrategy> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>A strategy where the caller thread iterates over task production, submitting each
|
||||
* task to an {@link Executor} for execution.</p>
|
||||
|
|
Loading…
Reference in New Issue