jetty-9 better dispatching of events to SSL

This commit is contained in:
Greg Wilkins 2012-08-10 14:39:51 +10:00
parent 97ff08b3be
commit 54ea5a7de2
5 changed files with 56 additions and 11 deletions

View File

@ -36,6 +36,7 @@ public abstract class AbstractConnection implements Connection
private final AtomicBoolean _readInterested = new AtomicBoolean();
private final EndPoint _endp;
private final Callback<Void> _readCallback;
private final Executor _executor;
public AbstractConnection(EndPoint endp, Executor executor)
{
@ -46,7 +47,7 @@ public abstract class AbstractConnection implements Connection
{
if (executor == null)
throw new IllegalArgumentException("Executor must not be null!");
_executor=executor;
_endp = endp;
_readCallback = new ExecutorCallback<Void>(executor)
{
@ -77,6 +78,12 @@ public abstract class AbstractConnection implements Connection
};
}
public Executor getExecutor()
{
return _executor;
}
/**
* <p>Utility method to be called to register read interest.</p>
* <p>After a call to this method, {@link #onFillable()} or {@link #onFillInterestedFailed(Throwable)}

View File

@ -154,6 +154,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
*/
protected void endPointOpened(EndPoint endpoint)
{
// TODO should this be dispatched
endpoint.onOpen();
}
@ -164,6 +165,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
*/
protected void endPointClosed(EndPoint endpoint)
{
// TODO should this be dispatched
endpoint.onClose();
}
@ -172,9 +174,16 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
*
* @param connection the connection just opened
*/
public void connectionOpened(Connection connection)
public void connectionOpened(final Connection connection)
{
connection.onOpen();
execute(new Runnable()
{
@Override
public void run()
{
connection.onOpen();
}
});
}
/**
@ -182,9 +191,16 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
*
* @param connection the connection just closed
*/
public void connectionClosed(Connection connection)
public void connectionClosed(final Connection connection)
{
connection.onClose();
execute(new Runnable()
{
@Override
public void run()
{
connection.onClose();
}
});
}
/**
@ -334,7 +350,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
String name = _thread.getName();
try
{
_thread.setName(name + " Selector" + _id);
_thread.setName(name + "-selector-" + _id);
LOG.debug("Starting {} on {}", _thread, this);
while (isRunning())
select();

View File

@ -80,7 +80,16 @@ public class SslConnection extends AbstractConnection
private ByteBuffer _encryptedOutput;
private final boolean _encryptedDirectBuffers = false;
private final boolean _decryptedDirectBuffers = false;
private final Runnable _runCompletWrite = new Runnable()
{
@Override
public void run()
{
_decryptedEndPoint.getWriteFlusher().completeWrite();
}
};
public SslConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, SSLEngine sslEngine)
{
super(endPoint, executor, true);
@ -139,9 +148,11 @@ public class SslConnection extends AbstractConnection
// If we are handshaking, then wake up any waiting write as well as it may have been blocked on the read
if (_decryptedEndPoint._flushRequiresFillToProgress)
{
_decryptedEndPoint._flushRequiresFillToProgress = false;
_decryptedEndPoint.getWriteFlusher().completeWrite();
getExecutor().execute(_runCompletWrite);
}
}
LOG.debug("{} onFilled", this);
}
@ -211,7 +222,7 @@ public class SslConnection extends AbstractConnection
getFillInterest().fillable();
}
getWriteFlusher().completeWrite();
getExecutor().execute(_runCompletWrite);
}
}
@ -349,6 +360,10 @@ public class SslConnection extends AbstractConnection
@Override
public synchronized int fill(ByteBuffer buffer) throws IOException
{
// TODO remove this when we are certain it is OK
if (Thread.currentThread().getName().indexOf("selector")>=0)
new Throwable().printStackTrace();
LOG.debug("{} fill enter", SslConnection.this);
try
{
@ -524,6 +539,10 @@ public class SslConnection extends AbstractConnection
@Override
public synchronized int flush(ByteBuffer... appOuts) throws IOException
{
// TODO remove this when we are certain it is OK
if (Thread.currentThread().getName().indexOf("selector")>=0)
new Throwable().printStackTrace();
// The contract for flush does not require that all appOuts bytes are written
// or even that any appOut bytes are written! If the connection is write block
// or busy handshaking, then zero bytes may be taken from appOuts and this method

View File

@ -24,6 +24,7 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.After;
@ -214,9 +215,10 @@ public class SslConnectionTest
@Test
public void testWriteOnConnect() throws Exception
{
//Log.getRootLogger().setDebugEnabled(true);
_testFill=false;
for (int i=0;i<10;i++)
for (int i=0;i<1;i++)
{
_writeCallback = new FutureCallback<>();
Socket client = newClient();

View File

@ -39,6 +39,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.ssl.SslConnection;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
@ -135,7 +136,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
catch(SocketException e)
{
// TODO looks like a close is overtaking the 413 in SSL
System.err.println("Investigate this "+e);
Log.getLogger(SslConnection.class).warn("Investigate this!!!",e);
}
finally
{