From 7df281bb1697eff6d21f06bef004313ea5a2a87f Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 3 Aug 2012 12:47:33 +1000 Subject: [PATCH] jetty-9 renamed ReadInterest to fillInterest --- .../eclipse/jetty/io/ByteArrayEndPoint.java | 12 ++++----- .../{ReadInterest.java => FillInterest.java} | 4 +-- .../jetty/io/SelectChannelEndPoint.java | 14 +++++----- .../org/eclipse/jetty/io/WriteFlusher.java | 12 ++++++--- .../eclipse/jetty/io/ssl/SslConnection.java | 26 +++++++++---------- 5 files changed, 36 insertions(+), 32 deletions(-) rename jetty-io/src/main/java/org/eclipse/jetty/io/{ReadInterest.java => FillInterest.java} (98%) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java index 8605c7870d7..4366e27024f 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java @@ -51,7 +51,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint protected boolean _growOutput; - private final ReadInterest _readInterest = new ReadInterest() + private final FillInterest _fillInterest = new FillInterest() { @Override protected boolean needsFill() throws IOException @@ -150,7 +150,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint { _in = in; if (in == null || BufferUtil.hasContent(in)) - _readInterest.readable(); + _fillInterest.readable(); } /* ------------------------------------------------------------ */ @@ -356,7 +356,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint */ public void reset() { - _readInterest.close(); + _fillInterest.close(); _writeFlusher.onClose(); _ishut=false; _oshut=false; @@ -426,7 +426,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint long idleElapsed = System.currentTimeMillis() - idleTimestamp; long idleLeft = idleTimeout - idleElapsed; - if (isOutputShutdown() || _readInterest.isInterested() || _writeFlusher.isInProgress()) + if (isOutputShutdown() || _fillInterest.isInterested() || _writeFlusher.isInProgress()) { if (idleTimestamp != 0 && idleTimeout > 0) { @@ -435,7 +435,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint LOG.debug("{} idle timeout expired", this); TimeoutException timeout = new TimeoutException("Idle timeout expired: " + idleElapsed + "/" + idleTimeout + " ms"); - _readInterest.failed(timeout); + _fillInterest.failed(timeout); _writeFlusher.onFail(timeout); if (isOutputShutdown()) @@ -454,7 +454,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint @Override public void fillInterested(C context, Callback callback) throws IllegalStateException { - _readInterest.register(context, callback); + _fillInterest.register(context, callback); } /* ------------------------------------------------------------ */ diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ReadInterest.java b/jetty-io/src/main/java/org/eclipse/jetty/io/FillInterest.java similarity index 98% rename from jetty-io/src/main/java/org/eclipse/jetty/io/ReadInterest.java rename to jetty-io/src/main/java/org/eclipse/jetty/io/FillInterest.java index c7edac3181e..d0718930aa1 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ReadInterest.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/FillInterest.java @@ -14,14 +14,14 @@ import org.eclipse.jetty.util.Callback; * by keeping state and calling the context and callback objects. * */ -public abstract class ReadInterest +public abstract class FillInterest { private final AtomicBoolean _interested = new AtomicBoolean(false); private volatile Callback _callback; private Object _context; /* ------------------------------------------------------------ */ - protected ReadInterest() + protected FillInterest() { } diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/SelectChannelEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/SelectChannelEndPoint.java index 6386c3db953..a0a3541932c 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/SelectChannelEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/SelectChannelEndPoint.java @@ -79,7 +79,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements SelectorMa * true if {@link ManagedSelector#destroyEndPoint(EndPoint)} has not been called */ private final AtomicBoolean _open = new AtomicBoolean(); - private final ReadInterest _readInterest = new ReadInterest() + private final FillInterest _fillInterest = new FillInterest() { @Override protected boolean needsFill() @@ -150,7 +150,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements SelectorMa @Override public void fillInterested(C context, Callback callback) throws IllegalStateException { - _readInterest.register(context, callback); + _fillInterest.register(context, callback); } @Override @@ -178,7 +178,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements SelectorMa setKeyInterests(oldInterestOps, newInterestOps); updateLocalInterests(readyOps, false); if (_key.isReadable()) - _readInterest.readable(); + _fillInterest.readable(); if (_key.isWritable()) _writeFlusher.completeWrite(); } @@ -194,7 +194,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements SelectorMa LOG.debug("{} idle timeout check, elapsed: {} ms, remaining: {} ms", this, idleElapsed, idleLeft); - if (isOutputShutdown() || _readInterest.isInterested() || _writeFlusher.isInProgress()) + if (isOutputShutdown() || _fillInterest.isInterested() || _writeFlusher.isInProgress()) { if (idleTimestamp != 0 && idleTimeout > 0) { @@ -203,7 +203,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements SelectorMa LOG.debug("{} idle timeout expired", this); TimeoutException timeout = new TimeoutException("Idle timeout expired: " + idleElapsed + "/" + idleTimeout + " ms"); - _readInterest.failed(timeout); + _fillInterest.failed(timeout); _writeFlusher.onFail(timeout); if (isOutputShutdown()) @@ -269,7 +269,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements SelectorMa { super.onClose(); _writeFlusher.onClose(); - _readInterest.close(); + _fillInterest.close(); } @Override @@ -292,6 +292,6 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements SelectorMa } return String.format("SCEP@%x{l(%s)<->r(%s),open=%b,ishut=%b,oshut=%b,i=%d%s,r=%s,w=%s}-{%s}", hashCode(), getRemoteAddress(), getLocalAddress(), isOpen(), isInputShutdown(), - isOutputShutdown(), _interestOps, keyString, _readInterest, _writeFlusher, getConnection()); + isOutputShutdown(), _interestOps, keyString, _fillInterest, _writeFlusher, getConnection()); } } diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java b/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java index 903901dd02a..587c80448e4 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java @@ -67,10 +67,14 @@ abstract public class WriteFlusher // will discover the failure and call the callbacks before returning to IDLE // Thus the possible paths for a failure are: // - // IDLE--(fail)-->IDLE - // IDLE-->WRITING--(fail)-->FAILED-->IDLE - // IDLE-->WRITING-->PENDING--(fail)-->IDLE - // IDLE-->WRITING-->PENDING-->COMPLETING--(fail)-->FAILED-->IDLE + // IDLE--(fail)-->IDLE + // IDLE-->WRITING--(fail)-->FAILED-->IDLE + // IDLE-->WRITING-->PENDING--(fail)-->IDLE + // IDLE-->WRITING-->PENDING-->COMPLETING--(fail)-->FAILED-->IDLE + // + // So a call to fail in the PENDING state will be directly handled and the state changed to IDLE + // A call to fail in the WRITING or COMPLETING states will just set the state to FAILED and the failure will be + // handled with the write or completeWrite methods try to move the state from what they thought it was. // protected WriteFlusher(EndPoint endPoint) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java index 4822624ee8b..85e516f91f0 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java @@ -30,7 +30,7 @@ import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EofException; -import org.eclipse.jetty.io.ReadInterest; +import org.eclipse.jetty.io.FillInterest; import org.eclipse.jetty.io.RuntimeIOException; import org.eclipse.jetty.io.SelectChannelEndPoint; import org.eclipse.jetty.io.WriteFlusher; @@ -138,8 +138,8 @@ public class SslConnection extends AbstractConnection { // wake up whoever is doing the fill or the flush so they can // do all the filling, unwrapping ,wrapping and flushing - if (_decryptedEndPoint._readInterest.isInterested()) - _decryptedEndPoint._readInterest.readable(); + if (_decryptedEndPoint._fillInterest.isInterested()) + _decryptedEndPoint._fillInterest.readable(); // If we are handshaking, then wake up any waiting write as well as it may have been blocked on the read if ( _decryptedEndPoint._flushRequiresFillToProgress) @@ -164,8 +164,8 @@ public class SslConnection extends AbstractConnection synchronized(_decryptedEndPoint) { - if (_decryptedEndPoint._readInterest.isInterested()) - _decryptedEndPoint._readInterest.failed(cause); + if (_decryptedEndPoint._fillInterest.isInterested()) + _decryptedEndPoint._fillInterest.failed(cause); if (_decryptedEndPoint._flushRequiresFillToProgress) { @@ -182,12 +182,12 @@ public class SslConnection extends AbstractConnection return String.format("SslConnection@%x{%s,%s%s}", hashCode(), _sslEngine.getHandshakeStatus(), - _decryptedEndPoint._readInterest.isInterested() ? "R" : "", + _decryptedEndPoint._fillInterest.isInterested() ? "R" : "", _decryptedEndPoint._writeFlusher.isInProgress() ? "W" : ""); } /* ------------------------------------------------------------ */ - public class DecryptedEndPoint extends AbstractEndPoint implements EndPoint + public class DecryptedEndPoint extends AbstractEndPoint { private boolean _fillRequiresFlushToProgress; private boolean _flushRequiresFillToProgress; @@ -215,7 +215,7 @@ public class SslConnection extends AbstractConnection if (_fillRequiresFlushToProgress) { _fillRequiresFlushToProgress = false; - _readInterest.readable(); + _fillInterest.readable(); } if (_writeFlusher.isInProgress()) @@ -241,7 +241,7 @@ public class SslConnection extends AbstractConnection if (_fillRequiresFlushToProgress) { _fillRequiresFlushToProgress = false; - _readInterest.failed(x); + _fillInterest.failed(x); } if (_writeFlusher.isInProgress()) @@ -252,7 +252,7 @@ public class SslConnection extends AbstractConnection } }; - private final ReadInterest _readInterest = new ReadInterest() + private final FillInterest _fillInterest = new FillInterest() { @Override protected boolean needsFill() throws IOException @@ -350,7 +350,7 @@ public class SslConnection extends AbstractConnection @Override public void fillInterested(C context, Callback callback) throws IllegalStateException { - _readInterest.register(context, callback); + _fillInterest.register(context, callback); } @Override @@ -619,7 +619,7 @@ public class SslConnection extends AbstractConnection case NEED_UNWRAP: // Ah we need to fill some data so we can write. // So if we were not called from fill and the app is not reading anyway - if (!_fillRequiresFlushToProgress && !_readInterest.isInterested()) + if (!_fillRequiresFlushToProgress && !_fillInterest.isInterested()) { // Tell the onFillable method that there might be a write to complete // TODO move this to the writeFlusher? @@ -706,7 +706,7 @@ public class SslConnection extends AbstractConnection @Override public String toString() { - return String.format("%s{%s%s%s}", super.toString(), _readInterest.isInterested() ? "R" : "", _writeFlusher.isInProgress() ? "W" : "", _cannotAcceptMoreAppDataToFlush ? "w" : ""); + return String.format("%s{%s%s%s}", super.toString(), _fillInterest.isInterested() ? "R" : "", _writeFlusher.isInProgress() ? "W" : "", _cannotAcceptMoreAppDataToFlush ? "w" : ""); } }