Skip to content

Commit

Permalink
Fixes #547 (ExecuteProduceConsume (EWYK) does not exit low threads mode)
Browse files Browse the repository at this point in the history
Exposed getters/setters for ExecutionStrategy.Factory in
ServerConnector and SelectorManager, to allow explicit configuration
and testing.

Added test to verify that EPC exits low threads mode.
  • Loading branch information
sbordet committed May 6, 2016
1 parent 8bb6d4d commit caa4528
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 195 deletions.
Expand Up @@ -79,11 +79,17 @@ public ManagedSelector(SelectorManager selectorManager, int id, ExecutionStrateg
setStopTimeout(5000);
}

public ExecutionStrategy getExecutionStrategy()
{
return _strategy;
}

@Override
protected void doStart() throws Exception
{
super.doStart();
_selector = newSelector();
_selectorManager.execute(this);
}

protected Selector newSelector() throws IOException
Expand Down
48 changes: 26 additions & 22 deletions jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java
Expand Up @@ -27,12 +27,11 @@
import java.nio.channels.SocketChannel;
import java.util.concurrent.Executor;

import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.ExecutionStrategy;
import org.eclipse.jetty.util.thread.Scheduler;

/**
Expand All @@ -41,7 +40,7 @@
* <p>{@link SelectorManager} subclasses implement methods to return protocol-specific
* {@link EndPoint}s and {@link Connection}s.</p>
*/
public abstract class SelectorManager extends AbstractLifeCycle implements Dumpable
public abstract class SelectorManager extends ContainerLifeCycle implements Dumpable
{
public static final int DEFAULT_CONNECT_TIMEOUT = 15000;
protected static final Logger LOG = Log.getLogger(SelectorManager.class);
Expand All @@ -50,6 +49,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
private final Scheduler scheduler;
private final ManagedSelector[] _selectors;
private long _connectTimeout = DEFAULT_CONNECT_TIMEOUT;
private ExecutionStrategy.Factory _executionFactory = ExecutionStrategy.Factory.getDefault();
private long _selectorIndex;

protected SelectorManager(Executor executor, Scheduler scheduler)
Expand Down Expand Up @@ -96,6 +96,24 @@ public void setConnectTimeout(long milliseconds)
_connectTimeout = milliseconds;
}

/**
* @return the {@link ExecutionStrategy.Factory} used by {@link ManagedSelector}
*/
public ExecutionStrategy.Factory getExecutionStrategyFactory()
{
return _executionFactory;
}

/**
* @param _executionFactory the {@link ExecutionStrategy.Factory} used by {@link ManagedSelector}
*/
public void setExecutionStrategyFactory(ExecutionStrategy.Factory _executionFactory)
{
if (isRunning())
throw new IllegalStateException("Cannot change " + ExecutionStrategy.Factory.class.getSimpleName() + " after start()");
this._executionFactory = _executionFactory;
}

/**
* @return the selector priority delta
* @deprecated not implemented
Expand Down Expand Up @@ -246,14 +264,13 @@ protected void accepted(SocketChannel channel) throws IOException
@Override
protected void doStart() throws Exception
{
super.doStart();
for (int i = 0; i < _selectors.length; i++)
{
ManagedSelector selector = newSelector(i);
_selectors[i] = selector;
selector.start();
execute(selector);
addBean(selector);
}
super.doStart();
}

/**
Expand All @@ -264,15 +281,15 @@ protected void doStart() throws Exception
*/
protected ManagedSelector newSelector(int id)
{
return new ManagedSelector(this, id);
return new ManagedSelector(this, id, getExecutionStrategyFactory());
}

@Override
protected void doStop() throws Exception
{
for (ManagedSelector selector : _selectors)
selector.stop();
super.doStop();
for (ManagedSelector selector : _selectors)
removeBean(selector);
}

/**
Expand Down Expand Up @@ -376,17 +393,4 @@ protected void connectionFailed(SocketChannel channel, Throwable ex, Object atta
* @see #newEndPoint(SocketChannel, ManagedSelector, SelectionKey)
*/
public abstract Connection newConnection(SocketChannel channel, EndPoint endpoint, Object attachment) throws IOException;

@Override
public String dump()
{
return ContainerLifeCycle.dump(this);
}

@Override
public void dump(Appendable out, String indent) throws IOException
{
ContainerLifeCycle.dumpObject(out, this);
ContainerLifeCycle.dump(out, indent, TypeUtil.asList(_selectors));
}
}
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.Name;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.ExecutionStrategy;
import org.eclipse.jetty.util.thread.Scheduler;

/**
Expand Down Expand Up @@ -475,6 +476,22 @@ public void setReuseAddress(boolean reuseAddress)
_reuseAddress = reuseAddress;
}

/**
* @return the ExecutionStrategy factory to use for SelectorManager
*/
public ExecutionStrategy.Factory getExecutionStrategyFactory()
{
return _manager.getExecutionStrategyFactory();
}

/**
* @param executionFactory the ExecutionStrategy factory to use for SelectorManager
*/
public void setExecutionStrategyFactory(ExecutionStrategy.Factory executionFactory)
{
_manager.setExecutionStrategyFactory(executionFactory);
}

protected class ServerConnectorManager extends SelectorManager
{
public ServerConnectorManager(Executor executor, Scheduler scheduler, int selectors)
Expand Down

0 comments on commit caa4528

Please sign in to comment.