diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java b/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java index fcd5c3da826..638f6a9b073 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java @@ -39,7 +39,6 @@ import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; - /** * The Selector Manager manages and number of SelectSets to allow * NIO scheduling to scale to large numbers of connections. @@ -49,8 +48,8 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa { public static final Logger LOG = Log.getLogger(SelectorManager.class); - private final ManagedSelector[] _selectSets; - private long _selectSetIndex; + private final ManagedSelector[] _selectors; + private long _selectorIndex; private volatile long _maxIdleTime; protected SelectorManager() @@ -60,7 +59,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa protected SelectorManager(@Name("selectors") int selectors) { - this._selectSets = new ManagedSelector[selectors]; + this._selectors = new ManagedSelector[selectors]; } /** @@ -81,19 +80,19 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa /** * @return the number of select sets in use */ - public int getSelectSets() + public int getSelectorCount() { - return _selectSets.length; + return _selectors.length; } - private ManagedSelector chooseSelectSet() + private ManagedSelector chooseSelector() { // The ++ increment here is not atomic, but it does not matter. // so long as the value changes sometimes, then connections will // be distributed over the available sets. - long s = _selectSetIndex++; - int index = (int)(s % getSelectSets()); - return _selectSets[index]; + long s = _selectorIndex++; + int index = (int)(s % getSelectorCount()); + return _selectors[index]; } /** @@ -103,7 +102,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa */ public void connect(SocketChannel channel, Object attachment) { - ManagedSelector set = chooseSelectSet(); + ManagedSelector set = chooseSelector(); set.submit(set.new Connect(channel, attachment)); } @@ -113,7 +112,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa */ public void accept(final SocketChannel channel) { - final ManagedSelector set = chooseSelectSet(); + final ManagedSelector set = chooseSelector(); set.submit(set.new Accept(channel)); } @@ -121,17 +120,17 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa protected void doStart() throws Exception { super.doStart(); - for (int i=0;i< _selectSets.length;i++) + for (int i=0;i< _selectors.length;i++) { - ManagedSelector selectSet = newSelectSet(i); - _selectSets[i] = selectSet; + ManagedSelector selectSet = newSelector(i); + _selectors[i] = selectSet; selectSet.start(); execute(selectSet); execute(new Expirer()); } } - protected ManagedSelector newSelectSet(int id) + protected ManagedSelector newSelector(int id) { return new ManagedSelector(id); } @@ -139,7 +138,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa @Override protected void doStop() throws Exception { - for (ManagedSelector set : _selectSets) + for (ManagedSelector set : _selectors) set.stop(); super.doStop(); } @@ -149,6 +148,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa */ protected void endPointOpened(AsyncEndPoint endpoint) { + endpoint.onOpen(); endpoint.getAsyncConnection().onOpen(); } @@ -200,7 +200,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa public void dump(Appendable out, String indent) throws IOException { AggregateLifeCycle.dumpObject(out,this); - AggregateLifeCycle.dump(out, indent, TypeUtil.asList(_selectSets)); + AggregateLifeCycle.dump(out, indent, TypeUtil.asList(_selectors)); } private class Expirer implements Runnable @@ -210,7 +210,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa { while (isRunning()) { - for (ManagedSelector selector : _selectSets) + for (ManagedSelector selector : _selectors) if (selector!=null) selector.timeoutCheck(); sleep(1000); @@ -452,14 +452,14 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa private AsyncEndPoint createEndPoint(SocketChannel channel, SelectionKey sKey) throws IOException { - Selectable endp = newEndPoint(channel, this, sKey); - _endPoints.put(endp, this); - LOG.debug("Created {}", endp); - endPointOpened(endp); - return endp; + Selectable asyncEndPoint = newEndPoint(channel, this, sKey); + asyncEndPoint.setAsyncConnection(newConnection(channel, asyncEndPoint, sKey.attachment())); + _endPoints.put(asyncEndPoint, this); + LOG.debug("Created {}", asyncEndPoint); + endPointOpened(asyncEndPoint); + return asyncEndPoint; } - public void destroyEndPoint(Selectable endp) { LOG.debug("Destroyed {}", endp); diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java index a8a6967c865..73635f5b7e7 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java @@ -53,7 +53,6 @@ public class SelectChannelEndPointTest protected SelectChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key) throws IOException { SelectChannelEndPoint endp = new SelectChannelEndPoint(channel,selectSet,key,getMaxIdleTime()); - endp.setAsyncConnection(selectSet.getManager().newConnection(channel,endp, key.attachment())); _lastEndp=endp; return endp; } diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java index 24798feb5cc..1afa79cd47b 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java @@ -58,7 +58,6 @@ public class SslConnectionTest protected SelectChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key) throws IOException { SelectChannelEndPoint endp = new SelectChannelEndPoint(channel,selectSet,key,getMaxIdleTime()); - endp.setAsyncConnection(selectSet.getManager().newConnection(channel,endp, key.attachment())); _lastEndp=endp; // System.err.println("newEndPoint "+endp); return endp; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java index 1dc74c80365..aca3ce7625c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java @@ -202,9 +202,7 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto /* ------------------------------------------------------------ */ protected SelectChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key) throws IOException { - SelectChannelEndPoint endp= new SelectChannelEndPoint(channel,selectSet,key, SelectChannelConnector.this._maxIdleTime); - endp.setAsyncConnection(selectSet.getManager().newConnection(channel,endp, key.attachment())); - return endp; + return new SelectChannelEndPoint(channel,selectSet,key, this._maxIdleTime); } /* ------------------------------------------------------------------------------- */ diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/nio/NetworkTrafficSelectChannelConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/nio/NetworkTrafficSelectChannelConnector.java index 66ec2d41a72..b085ca7b722 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/nio/NetworkTrafficSelectChannelConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/nio/NetworkTrafficSelectChannelConnector.java @@ -56,7 +56,6 @@ public class NetworkTrafficSelectChannelConnector extends SelectChannelConnector protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.ManagedSelector selectSet, SelectionKey key) throws IOException { NetworkTrafficSelectChannelEndPoint endPoint = new NetworkTrafficSelectChannelEndPoint(channel, selectSet, key, _maxIdleTime, listeners); - endPoint.setAsyncConnection(selectSet.getManager().newConnection(channel,endPoint, key.attachment())); endPoint.notifyOpened(); return endPoint; } diff --git a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYClient.java b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYClient.java index 4a2c5daba48..4e86ea744b5 100644 --- a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYClient.java +++ b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYClient.java @@ -279,12 +279,8 @@ public class SPDYClient long maxIdleTime = attachment.client.getMaxIdleTime(); if (maxIdleTime < 0) maxIdleTime = getMaxIdleTime(); - SelectChannelEndPoint result = new SelectChannelEndPoint(channel, selectSet, key, (int)maxIdleTime); - AsyncConnection connection = newConnection(channel, result, attachment); - result.setAsyncConnection(connection); - - return result; + return new SelectChannelEndPoint(channel, selectSet, key, maxIdleTime); } @Override diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/WebSocketClientSelectorManager.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/WebSocketClientSelectorManager.java index 9add9441c32..e5536060a89 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/WebSocketClientSelectorManager.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/WebSocketClientSelectorManager.java @@ -133,9 +133,7 @@ public class WebSocketClientSelectorManager extends SelectorManager @Override protected SelectChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key) throws IOException { - SelectChannelEndPoint endp = new SelectChannelEndPoint(channel,selectSet,key,getMaxIdleTime()); - endp.setAsyncConnection(selectSet.getManager().newConnection(channel,endp,key.attachment())); - return endp; + return new SelectChannelEndPoint(channel,selectSet,key,getMaxIdleTime()); } public SSLEngine newSSLEngine(SslContextFactory sslContextFactory, SocketChannel channel)