Mercurial Hosting > luan
changeset 949:e9088af3787f
remove SelectSet._changes
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 11 Oct 2016 23:18:13 -0600 |
parents | f5aefdc4a81a |
children | a778413aefc0 |
files | src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java src/org/eclipse/jetty/io/nio/SelectorManager.java |
diffstat | 2 files changed, 57 insertions(+), 125 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java Tue Oct 11 22:16:29 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java Tue Oct 11 23:18:13 2016 -0600 @@ -501,7 +501,7 @@ if(changed) { - _selectSet.addChange(this); + doUpdateKey(); _selectSet.wakeup(); } } @@ -511,69 +511,66 @@ /** * Synchronize the interestOps with the actual key. Call is scheduled by a call to updateKey */ - void doUpdateKey() + synchronized void doUpdateKey() { - synchronized (this) + if (getChannel().isOpen()) { - if (getChannel().isOpen()) + if (_interestOps>0) { - if (_interestOps>0) + if (_key==null || !_key.isValid()) { - if (_key==null || !_key.isValid()) + SelectableChannel sc = (SelectableChannel)getChannel(); + if (sc.isRegistered()) { - SelectableChannel sc = (SelectableChannel)getChannel(); - if (sc.isRegistered()) - { - updateKey(); - } - else - { - try - { - _key=((SelectableChannel)getChannel()).register(_selectSet.getSelector(),_interestOps,this); - } - catch (Exception e) - { - LOG.trace("",e); - if (_key!=null && _key.isValid()) - { - _key.cancel(); - } - - if (_open) - { - _selectSet.destroyEndPoint(this); - } - _open=false; - _key = null; - } - } + updateKey(); } else { - _key.interestOps(_interestOps); + try + { + _key=((SelectableChannel)getChannel()).register(_selectSet.getSelector(),_interestOps,this); + } + catch (Exception e) + { + LOG.trace("",e); + if (_key!=null && _key.isValid()) + { + _key.cancel(); + } + + if (_open) + { + _selectSet.destroyEndPoint(this); + } + _open=false; + _key = null; + } } } else { - if (_key!=null && _key.isValid()) - _key.interestOps(0); - else - _key=null; + _key.interestOps(_interestOps); } } else { if (_key!=null && _key.isValid()) - _key.cancel(); + _key.interestOps(0); + else + _key=null; + } + } + else + { + if (_key!=null && _key.isValid()) + _key.cancel(); - if (_open) - { - _open=false; - _selectSet.destroyEndPoint(this); - } - _key = null; + if (_open) + { + _open=false; + _selectSet.destroyEndPoint(this); } + _key = null; } }
--- a/src/org/eclipse/jetty/io/nio/SelectorManager.java Tue Oct 11 22:16:29 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/SelectorManager.java Tue Oct 11 23:18:13 2016 -0600 @@ -115,22 +115,6 @@ } /* ------------------------------------------------------------ */ - /** Register a {@link ServerSocketChannel} - * @param acceptChannel - */ - public void register(ServerSocketChannel acceptChannel) - { - int s=_set++; - if (s<0) - s=-s; - s=s%_selectSets; - SelectSet set=_selectSet[s]; - set.addChange(acceptChannel); - set.wakeup(); - } - - - /* ------------------------------------------------------------ */ /** * @return the lowResourcesConnections */ @@ -250,8 +234,6 @@ private final int _setID; private volatile long _now = System.currentTimeMillis(); - private final ConcurrentLinkedQueue<Object> _changes = new ConcurrentLinkedQueue<Object>(); - private volatile Selector _selector; private volatile Thread _selecting; @@ -273,11 +255,22 @@ _monitorNext=System.currentTimeMillis()+__MONITOR_PERIOD; } - public void addChange(Object change) + private void addChange(SocketChannel channel) { - _changes.add(change); + try { + SelectionKey key = channel.register(_selector,SelectionKey.OP_READ,null); + SelectChannelEndPoint endpoint = createEndPoint(channel,key); + key.attach(endpoint); + endpoint.schedule(); + } catch(IOException e) { + LOG.warn("",e); + try { + channel.close(); + } catch(IOException e2) { + LOG.warn("",e2); + } + } } - /* ------------------------------------------------------------ */ /** * Select and dispatch tasks found from changes and the selector. @@ -294,64 +287,6 @@ if (selector == null) return; - // Make any key changes required - Object change; - int changes=_changes.size(); - while (changes-->0 && (change=_changes.poll())!=null) - { - Channel ch=null; - SelectionKey key=null; - - try - { - if (change instanceof EndPoint) - { - // Update the operations for a key. - SelectChannelEndPoint endpoint = (SelectChannelEndPoint)change; - ch=endpoint.getChannel(); - endpoint.doUpdateKey(); - } - else if (change instanceof SocketChannel) - { - // Newly registered channel - final SocketChannel channel=(SocketChannel)change; - ch=channel; - key = channel.register(selector,SelectionKey.OP_READ,null); - SelectChannelEndPoint endpoint = createEndPoint(channel,key); - key.attach(endpoint); - endpoint.schedule(); - } - else if (change instanceof Runnable) - { - execute((Runnable)change); - } - else - throw new IllegalArgumentException(change.toString()); - } - catch (CancelledKeyException e) - { - LOG.trace("",e); - } - catch (Throwable e) - { - if (isRunning()) - LOG.warn("",e); - else - LOG.debug("",e); - - try - { - if (ch!=null) - ch.close(); - } - catch(IOException e2) - { - LOG.debug("",e2); - } - } - } - - // Do and instant select to see if any connections can be handled. int selected=selector.selectNow(); @@ -375,7 +310,7 @@ } // workout how long to wait in select - long wait = _changes.size()==0?__IDLE_TICK:0L; + long wait = __IDLE_TICK; // If we should wait with a select if (wait>0)