Mercurial Hosting > luan
changeset 960:3cd4c706a61f
simplify ChannelEndPoint
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 13 Oct 2016 21:29:19 -0600 |
parents | 7b94f5b33c64 |
children | 790c01734386 |
files | src/org/eclipse/jetty/io/nio/ChannelEndPoint.java src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java src/org/eclipse/jetty/io/nio/SelectorManager.java src/org/eclipse/jetty/io/nio/SslConnection.java src/org/eclipse/jetty/server/AbstractHttpConnection.java |
diffstat | 5 files changed, 37 insertions(+), 95 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/io/nio/ChannelEndPoint.java Thu Oct 13 18:53:26 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/ChannelEndPoint.java Thu Oct 13 21:29:19 2016 -0600 @@ -52,68 +52,49 @@ private volatile boolean _ishut; private volatile boolean _oshut; - public ChannelEndPoint(ByteChannel channel) throws IOException - { - super(); - this._channel = channel; - _socket=(channel instanceof SocketChannel)?((SocketChannel)channel).socket():null; - if (_socket!=null) - { - _local=(InetSocketAddress)_socket.getLocalSocketAddress(); - _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); - _maxIdleTime=_socket.getSoTimeout(); - } - else - { - _local=_remote=null; - } - } - protected ChannelEndPoint(ByteChannel channel, int maxIdleTime) throws IOException { this._channel = channel; - _maxIdleTime=maxIdleTime; - _socket=(channel instanceof SocketChannel)?((SocketChannel)channel).socket():null; + _maxIdleTime = maxIdleTime; + _socket = (channel instanceof SocketChannel)?((SocketChannel)channel).socket():null; if (_socket!=null) { - _local=(InetSocketAddress)_socket.getLocalSocketAddress(); - _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); + _local = (InetSocketAddress)_socket.getLocalSocketAddress(); + _remote = (InetSocketAddress)_socket.getRemoteSocketAddress(); _socket.setSoTimeout(_maxIdleTime); } else { - _local=_remote=null; + _local = _remote = null; } } - public boolean isBlocking() + @Override + public final boolean isBlocking() { return !(_channel instanceof SelectableChannel) || ((SelectableChannel)_channel).isBlocking(); } + @Override public boolean blockReadable(long millisecs) throws IOException { return true; } + @Override public boolean blockWritable(long millisecs) throws IOException { return true; } - /* - * @see org.eclipse.io.EndPoint#isOpen() - */ - public boolean isOpen() + @Override + public final boolean isOpen() { return _channel.isOpen(); } - /** Shutdown the channel Input. - * Cannot be overridden. To override, see {@link #shutdownInput()} - * @throws IOException - */ - protected final void shutdownChannelInput() throws IOException + @Override + public final void shutdownInput() throws IOException { LOG.debug("ishut {}", this); _ishut = true; @@ -144,15 +125,8 @@ } } - /* (non-Javadoc) - * @see org.eclipse.io.EndPoint#close() - */ - public void shutdownInput() throws IOException - { - shutdownChannelInput(); - } - - protected final void shutdownChannelOutput() throws IOException + @Override + public final void shutdownOutput() throws IOException { LOG.debug("oshut {}",this); _oshut = true; @@ -183,27 +157,19 @@ } } - /* (non-Javadoc) - * @see org.eclipse.io.EndPoint#close() - */ - public void shutdownOutput() throws IOException - { - shutdownChannelOutput(); - } - - public boolean isOutputShutdown() + @Override + public final boolean isOutputShutdown() { return _oshut || !_channel.isOpen() || _socket != null && _socket.isOutputShutdown(); } - public boolean isInputShutdown() + @Override + public final boolean isInputShutdown() { return _ishut || !_channel.isOpen() || _socket != null && _socket.isInputShutdown(); } - /* (non-Javadoc) - * @see org.eclipse.io.EndPoint#close() - */ + @Override public void close() throws IOException { LOG.debug("close {}",this);
--- a/src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java Thu Oct 13 18:53:26 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java Thu Oct 13 21:29:19 2016 -0600 @@ -172,19 +172,6 @@ } } - /* ------------------------------------------------------------ */ - /** - * Called when a dispatched thread is no longer handling the endpoint. - * The selection key operations are updated. - * @return If false is returned, the endpoint has been redispatched and - * thread must keep handling the endpoint. - */ - private synchronized void undispatch() - { - _state = STATE_UNDISPATCHED; - updateKey(); - } - @Override public int fill(Buffer buffer) throws IOException { @@ -432,7 +419,6 @@ private void handle() { - boolean dispatched = true; try { try @@ -440,13 +426,10 @@ while(true) { final AsyncConnection next = (AsyncConnection)_connection.handle(); - if (next!=_connection) - { - LOG.debug("{} replaced {}",next,_connection); - _connection=next; - continue; - } - break; + if (next==_connection) + break; + LOG.debug("{} replaced {}",next,_connection); + _connection=next; } } catch (ClosedChannelException e) @@ -486,21 +469,13 @@ try{close();} catch(IOException e2){LOG.trace("",e2);} } - finally - { - updateKey(); - } } - undispatch(); - dispatched = false; } } finally { - if (dispatched) - { - undispatch(); - } + _state = STATE_UNDISPATCHED; + updateKey(); } }
--- a/src/org/eclipse/jetty/io/nio/SelectorManager.java Thu Oct 13 18:53:26 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/SelectorManager.java Thu Oct 13 21:29:19 2016 -0600 @@ -161,7 +161,6 @@ } - /* ------------------------------------------------------------------------------- */ @Override protected void doStop() throws Exception { @@ -176,11 +175,13 @@ public abstract AsyncConnection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint); + @Override public String dump() { return AggregateLifeCycle.dump(this); } + @Override public void dump(Appendable out, String indent) throws IOException { AggregateLifeCycle.dumpObject(out,this); @@ -295,7 +296,7 @@ return _selector; } - synchronized void stop() throws Exception + private synchronized void stop() throws Exception { // close endpoints and selector for (SelectionKey key : _selector.keys()) @@ -321,17 +322,20 @@ } } + @Override public String dump() { return AggregateLifeCycle.dump(this); } + @Override public void dump(Appendable out, String indent) throws IOException { out.append(String.valueOf(this)).append("\n"); AggregateLifeCycle.dump(out,indent,Collections.emptyList()); } + @Override public String toString() { SaneSelector selector=_selector;
--- a/src/org/eclipse/jetty/io/nio/SslConnection.java Thu Oct 13 18:53:26 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/SslConnection.java Thu Oct 13 21:29:19 2016 -0600 @@ -45,7 +45,7 @@ * it's source/sink of encrypted data. It then provides {@link #getSslEndPoint()} to * expose a source/sink of unencrypted data to another connection (eg HttpConnection). */ -public class SslConnection extends AbstractConnection implements AsyncConnection +public final class SslConnection extends AbstractConnection implements AsyncConnection { private final Logger _logger = LoggerFactory.getLogger("org.eclipse.jetty.io.nio.ssl"); @@ -167,7 +167,7 @@ } } - /* ------------------------------------------------------------ */ + @Override public Connection handle() throws IOException { try @@ -188,8 +188,8 @@ AsyncConnection next = (AsyncConnection)_connection.handle(); if (next!=_connection && next!=null) { - _connection=next; - progress=true; + _connection = next; + progress = true; } _logger.debug("{} handle {} progress={}", _session, this, progress); @@ -575,7 +575,6 @@ } - /* ------------------------------------------------------------ */ private ByteBuffer extractByteBuffer(Buffer buffer) { if (buffer.buffer() instanceof NIOBuffer) @@ -588,7 +587,6 @@ return _sslEndPoint; } - /* ------------------------------------------------------------ */ public String toString() { return String.format("%s %s", super.toString(), _sslEndPoint); @@ -777,7 +775,7 @@ public void setConnection(Connection connection) { - _connection=(AsyncConnection)connection; + _connection = (AsyncConnection)connection; } public String toString()
--- a/src/org/eclipse/jetty/server/AbstractHttpConnection.java Thu Oct 13 18:53:26 2016 -0600 +++ b/src/org/eclipse/jetty/server/AbstractHttpConnection.java Thu Oct 13 21:29:19 2016 -0600 @@ -512,7 +512,6 @@ } } - /* ------------------------------------------------------------ */ public abstract Connection handle() throws IOException; /* ------------------------------------------------------------ */