Mercurial Hosting > luan
changeset 948:f5aefdc4a81a
simplify SelectChannelConnector
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 11 Oct 2016 22:16:29 -0600 |
parents | 64f3d8dae31d |
children | e9088af3787f |
files | src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java src/org/eclipse/jetty/io/nio/SelectorManager.java src/org/eclipse/jetty/server/Connector.java src/org/eclipse/jetty/server/nio/SelectChannelConnector.java |
diffstat | 4 files changed, 10 insertions(+), 95 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java Tue Oct 11 21:33:40 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java Tue Oct 11 22:16:29 2016 -0600 @@ -719,12 +719,6 @@ } /* ------------------------------------------------------------ */ - public SelectSet getSelectSet() - { - return _selectSet; - } - - /* ------------------------------------------------------------ */ /** * Don't set the SoTimeout * @see org.eclipse.jetty.io.nio.ChannelEndPoint#setMaxIdleTime(int)
--- a/src/org/eclipse/jetty/io/nio/SelectorManager.java Tue Oct 11 21:33:40 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/SelectorManager.java Tue Oct 11 22:16:29 2016 -0600 @@ -92,34 +92,6 @@ } /* ------------------------------------------------------------ */ - /** - * @return the max idle time - */ - public long getMaxIdleTime() - { - return _maxIdleTime; - } - - /* ------------------------------------------------------------ */ - /** - * @return the number of select sets in use - */ - public int getSelectSets() - { - return _selectSets; - } - - /* ------------------------------------------------------------ */ - /** - * @param i - * @return The select set - */ - public SelectSet getSelectSet(int i) - { - return _selectSet[i]; - } - - /* ------------------------------------------------------------ */ /** Register a channel * @param channel */ @@ -129,11 +101,11 @@ // so long as the value changes sometimes, then connections will // be distributed over the available sets. - int s=_set++; + int s = _set++; if (s<0) s=-s; s=s%_selectSets; - SelectSet[] sets=_selectSet; + SelectSet[] sets = _selectSet; if (sets!=null) { SelectSet set=sets[s]; @@ -196,7 +168,7 @@ super.doStart(); // start a thread to Select - for (int i=0;i<getSelectSets();i++) + for (int i=0;i<_selectSets;i++) { final int id=i; execute(new Runnable() @@ -258,40 +230,14 @@ super.doStop(); } - /* ------------------------------------------------------------ */ - /** - * @param endpoint - */ - protected abstract void endPointClosed(SelectChannelEndPoint endpoint); - /* ------------------------------------------------------------------------------- */ public abstract AsyncConnection newConnection(SocketChannel channel, AsyncEndPoint endpoint, Object attachment); - /* ------------------------------------------------------------ */ - /** - * Create a new end point - * @param channel - * @param selectSet - * @param sKey the selection key - * @return the new endpoint {@link SelectChannelEndPoint} - * @throws IOException - */ - protected abstract SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey sKey) throws IOException; - - /* ------------------------------------------------------------------------------- */ - protected void connectionFailed(SocketChannel channel,Throwable ex,Object attachment) - { - LOG.warn(ex+","+channel+","+attachment); - LOG.debug("",ex); - } - - /* ------------------------------------------------------------ */ public String dump() { return AggregateLifeCycle.dump(this); } - /* ------------------------------------------------------------ */ public void dump(Appendable out, String indent) throws IOException { AggregateLifeCycle.dumpObject(out,this); @@ -299,9 +245,6 @@ } - /* ------------------------------------------------------------------------------- */ - /* ------------------------------------------------------------------------------- */ - /* ------------------------------------------------------------------------------- */ public class SelectSet implements Dumpable { private final int _setID; @@ -500,7 +443,8 @@ } catch(Exception e) { - connectionFailed(channel,e,att); + LOG.warn(e+","+channel+","+att); + LOG.debug("",e); } finally { @@ -628,7 +572,8 @@ private SelectChannelEndPoint createEndPoint(SocketChannel channel, SelectionKey sKey) throws IOException { - SelectChannelEndPoint endp = newEndPoint(channel,this,sKey); + SelectChannelEndPoint endp = new SelectChannelEndPoint(channel,this,sKey, _maxIdleTime); + endp.setConnection(getManager().newConnection(channel,endp, sKey.attachment())); LOG.debug("created {}",endp); _endPoints.put(endp,this); return endp; @@ -638,7 +583,7 @@ { LOG.debug("destroyEndPoint {}",endp); _endPoints.remove(endp); - endPointClosed(endp); + endp.getConnection().onClose(); } Selector getSelector()
--- a/src/org/eclipse/jetty/server/Connector.java Tue Oct 11 21:33:40 2016 -0600 +++ b/src/org/eclipse/jetty/server/Connector.java Tue Oct 11 22:16:29 2016 -0600 @@ -65,7 +65,7 @@ public final int port; private int _acceptors = 1; - protected int _maxIdleTime = 200000; + protected final int _maxIdleTime = 200000; protected int _soLingerTime = -1; protected final HttpBuffersImpl _buffers = new HttpBuffersImpl();
--- a/src/org/eclipse/jetty/server/nio/SelectChannelConnector.java Tue Oct 11 21:33:40 2016 -0600 +++ b/src/org/eclipse/jetty/server/nio/SelectChannelConnector.java Tue Oct 11 22:16:29 2016 -0600 @@ -100,7 +100,7 @@ protected synchronized void doStart() throws Exception { _manager.setSelectSets(getAcceptors()); - _manager.setMaxIdleTime(getMaxIdleTime()); +// _manager.setMaxIdleTime(getMaxIdleTime()); _manager.setLowResourcesConnections(0); if (_acceptChannel == null) @@ -121,18 +121,6 @@ super.doStart(); } - protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException - { - SelectChannelEndPoint endp= new SelectChannelEndPoint(channel,selectSet,key, SelectChannelConnector.this._maxIdleTime); - endp.setConnection(selectSet.getManager().newConnection(channel,endp, key.attachment())); - return endp; - } - - protected void endPointClosed(SelectChannelEndPoint endpoint) - { - endpoint.getConnection().onClose(); - } - protected AsyncConnection newConnection(SocketChannel channel,final AsyncEndPoint endpoint) { return new AsyncHttpConnection(SelectChannelConnector.this,endpoint,server); @@ -148,21 +136,9 @@ } @Override - protected void endPointClosed(final SelectChannelEndPoint endpoint) - { - SelectChannelConnector.this.endPointClosed(endpoint); - } - - @Override public AsyncConnection newConnection(SocketChannel channel,AsyncEndPoint endpoint, Object attachment) { return SelectChannelConnector.this.newConnection(channel,endpoint); } - - @Override - protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey sKey) throws IOException - { - return SelectChannelConnector.this.newEndPoint(channel,selectSet,sKey); - } } }