Mercurial Hosting > luan
changeset 914:54308d65265a
simplify SelectorManager
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 09 Oct 2016 01:22:55 -0600 |
parents | 17f4fe8271de |
children | 65e0fba5861a |
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, 7 insertions(+), 122 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java Sat Oct 08 23:57:11 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java Sun Oct 09 01:22:55 2016 -0600 @@ -133,10 +133,7 @@ /* ------------------------------------------------------------ */ public void setConnection(Connection connection) { - Connection old=_connection; _connection=(AsyncConnection)connection; - if (old!=null && old!=_connection) - _manager.endPointUpgraded(this,old); } /* ------------------------------------------------------------ */ @@ -197,10 +194,6 @@ { // other wise do the dispatch dispatch(); - if (_state>=STATE_DISPATCHED && !_selectSet.getManager().isDeferringInterestedOps0()) - { - _key.interestOps(0); - } } } } @@ -698,9 +691,7 @@ if (next!=_connection) { LOG.debug("{} replaced {}",next,_connection); - Connection old=_connection; _connection=next; - _manager.endPointUpgraded(this,old); continue; } break;
--- a/src/org/eclipse/jetty/io/nio/SelectorManager.java Sat Oct 08 23:57:11 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/SelectorManager.java Sun Oct 09 01:22:55 2016 -0600 @@ -66,13 +66,10 @@ private static final int __IDLE_TICK=Integer.getInteger("org.eclipse.jetty.io.nio.IDLE_TICK",400).intValue(); private int _maxIdleTime; - private int _lowResourcesMaxIdleTime; private long _lowResourcesConnections; private SelectSet[] _selectSet; private int _selectSets=1; private volatile int _set=0; - private boolean _deferringInterestedOps0=true; - private int _selectorPriorityDelta=0; /* ------------------------------------------------------------ */ /** @@ -186,24 +183,6 @@ set.wakeup(); } - /* ------------------------------------------------------------ */ - /** - * @return delta The value to add to the selector thread priority. - */ - public int getSelectorPriorityDelta() - { - return _selectorPriorityDelta; - } - - /* ------------------------------------------------------------ */ - /** Set the selector thread priorty delta. - * @param delta The value to add to the selector thread priority. - */ - public void setSelectorPriorityDelta(int delta) - { - _selectorPriorityDelta=delta; - } - /* ------------------------------------------------------------ */ /** @@ -226,27 +205,7 @@ _lowResourcesConnections=(lowResourcesConnections+_selectSets-1)/_selectSets; } - /* ------------------------------------------------------------ */ - /** - * @return the lowResourcesMaxIdleTime - */ - public long getLowResourcesMaxIdleTime() - { - return _lowResourcesMaxIdleTime; - } - /* ------------------------------------------------------------ */ - /** - * @param lowResourcesMaxIdleTime the period in ms that a connection is allowed to be idle when this SelectSet has more connections than {@link #getLowResourcesConnections()} - * @see #setMaxIdleTime(long) - */ - public void setLowResourcesMaxIdleTime(long lowResourcesMaxIdleTime) - { - _lowResourcesMaxIdleTime=(int)lowResourcesMaxIdleTime; - } - - - /* ------------------------------------------------------------------------------- */ public abstract void execute(Runnable task); /* ------------------------------------------------------------ */ @@ -271,7 +230,6 @@ public void run() { String name=Thread.currentThread().getName(); - int priority=Thread.currentThread().getPriority(); try { SelectSet[] sets=_selectSet; @@ -280,8 +238,6 @@ SelectSet set=sets[id]; Thread.currentThread().setName(name+" Selector"+id); - if (getSelectorPriorityDelta()!=0) - Thread.currentThread().setPriority(Thread.currentThread().getPriority()+getSelectorPriorityDelta()); LOG.debug("Starting {} on {}",Thread.currentThread(),this); while (isRunning()) { @@ -303,8 +259,6 @@ { LOG.debug("Stopped {} on {}",Thread.currentThread(),this); Thread.currentThread().setName(name); - if (getSelectorPriorityDelta()!=0) - Thread.currentThread().setPriority(priority); } } @@ -336,15 +290,6 @@ */ protected abstract void endPointClosed(SelectChannelEndPoint endpoint); - /* ------------------------------------------------------------ */ - /** - * @param endpoint - */ - protected abstract void endPointOpened(SelectChannelEndPoint endpoint); - - /* ------------------------------------------------------------ */ - protected abstract void endPointUpgraded(ConnectedEndPoint endpoint,Connection oldConnection); - /* ------------------------------------------------------------------------------- */ public abstract AsyncConnection newConnection(SocketChannel channel, AsyncEndPoint endpoint, Object attachment); @@ -700,7 +645,7 @@ _idleTick=now; final long idle_now=((_lowResourcesConnections>0 && selector.keys().size()>_lowResourcesConnections)) - ?(now+_maxIdleTime-_lowResourcesMaxIdleTime) + ?(now+_maxIdleTime) :now; execute(new Runnable() @@ -744,7 +689,6 @@ } - /* ------------------------------------------------------------ */ private void renewSelector() { try @@ -778,13 +722,11 @@ } } - /* ------------------------------------------------------------ */ public SelectorManager getManager() { return SelectorManager.this; } - /* ------------------------------------------------------------ */ public long getNow() { return _timeout.getNow(); @@ -804,13 +746,11 @@ _timeout.schedule(task, timeoutMs); } - /* ------------------------------------------------------------ */ public void cancelTimeout(Timeout.Task task) { task.cancel(); } - /* ------------------------------------------------------------ */ public void wakeup() { try @@ -833,17 +773,14 @@ } } - /* ------------------------------------------------------------ */ private SelectChannelEndPoint createEndPoint(SocketChannel channel, SelectionKey sKey) throws IOException { SelectChannelEndPoint endp = newEndPoint(channel,this,sKey); LOG.debug("created {}",endp); - endPointOpened(endp); _endPoints.put(endp,this); return endp; } - /* ------------------------------------------------------------ */ public void destroyEndPoint(SelectChannelEndPoint endp) { LOG.debug("destroyEndPoint {}",endp); @@ -851,13 +788,11 @@ endPointClosed(endp); } - /* ------------------------------------------------------------ */ Selector getSelector() { return _selector; } - /* ------------------------------------------------------------ */ void stop() throws Exception { // Spin for a while waiting for selector to complete @@ -914,13 +849,11 @@ } } - /* ------------------------------------------------------------ */ public String dump() { return AggregateLifeCycle.dump(this); } - /* ------------------------------------------------------------ */ public void dump(Appendable out, String indent) throws IOException { out.append(String.valueOf(this)).append(" id=").append(String.valueOf(_setID)).append("\n"); @@ -969,7 +902,6 @@ } } - /* ------------------------------------------------------------ */ public void dumpKeyState(List<Object> dumpto) { Selector selector=_selector; @@ -984,7 +916,6 @@ } } - /* ------------------------------------------------------------ */ public String toString() { Selector selector=_selector; @@ -995,7 +926,6 @@ } } - /* ------------------------------------------------------------ */ private static class ChannelAndAttachment { final SelectableChannel _channel; @@ -1009,22 +939,7 @@ } } - /* ------------------------------------------------------------ */ - public boolean isDeferringInterestedOps0() - { - return _deferringInterestedOps0; - } - /* ------------------------------------------------------------ */ - public void setDeferringInterestedOps0(boolean deferringInterestedOps0) - { - _deferringInterestedOps0 = deferringInterestedOps0; - } - - - /* ------------------------------------------------------------ */ - /* ------------------------------------------------------------ */ - /* ------------------------------------------------------------ */ private interface ChangeTask extends Runnable {}
--- a/src/org/eclipse/jetty/server/Connector.java Sat Oct 08 23:57:11 2016 -0600 +++ b/src/org/eclipse/jetty/server/Connector.java Sun Oct 09 01:22:55 2016 -0600 @@ -181,7 +181,6 @@ LOG.info("Started {}",this); } - /* ------------------------------------------------------------ */ @Override protected synchronized void doStop() throws Exception { @@ -200,21 +199,13 @@ } - /* ------------------------------------------------------------ */ - protected void configure(Socket socket) throws IOException + protected final void configure(Socket socket) throws IOException { - try - { - socket.setTcpNoDelay(true); - if (_soLingerTime >= 0) - socket.setSoLinger(true,_soLingerTime / 1000); - else - socket.setSoLinger(false,0); - } - catch (Exception e) - { - LOG.trace("",e); - } + socket.setTcpNoDelay(true); + if (_soLingerTime >= 0) + socket.setSoLinger(true,_soLingerTime / 1000); + else + socket.setSoLinger(false,0); } public void customize(EndPoint endpoint, Request request) throws IOException
--- a/src/org/eclipse/jetty/server/nio/SelectChannelConnector.java Sat Oct 08 23:57:11 2016 -0600 +++ b/src/org/eclipse/jetty/server/nio/SelectChannelConnector.java Sun Oct 09 01:22:55 2016 -0600 @@ -114,7 +114,6 @@ _manager.setSelectSets(getAcceptors()); _manager.setMaxIdleTime(getMaxIdleTime()); _manager.setLowResourcesConnections(0); - _manager.setLowResourcesMaxIdleTime(0); if (_acceptChannel == null) { @@ -127,7 +126,6 @@ _acceptChannel.socket().setReuseAddress(true); InetSocketAddress addr = getHost()==null?new InetSocketAddress(port):new InetSocketAddress(getHost(),port); _acceptChannel.bind(addr); - if( _acceptChannel.socket().getLocalPort() != port) throw new IOException("Server channel not bound"); } @@ -168,16 +166,6 @@ } @Override - protected void endPointOpened(SelectChannelEndPoint endpoint) - { - } - - @Override - protected void endPointUpgraded(ConnectedEndPoint endpoint, Connection oldConnection) - { - } - - @Override public AsyncConnection newConnection(SocketChannel channel,AsyncEndPoint endpoint, Object attachment) { return SelectChannelConnector.this.newConnection(channel,endpoint);