jetty-9 work in progress on jetty-server

This commit is contained in:
Greg Wilkins 2012-05-09 08:30:09 +02:00
parent fa59ddcc4b
commit 0c81b36e04
24 changed files with 88 additions and 615 deletions

View File

@ -1,101 +0,0 @@
// ========================================================================
// Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.http;
import org.eclipse.jetty.io.Buffers;
/* ------------------------------------------------------------ */
/** Abstract Buffer pool.
*/
public interface HttpBuffers
{
/**
* @return the requestBufferSize
*/
public int getRequestBufferSize();
/**
* @param requestBufferSize the requestBufferSize to set
*/
public void setRequestBufferSize(int requestBufferSize);
/**
* @return the requestHeaderSize
*/
public int getRequestHeaderSize();
/**
* @param requestHeaderSize the requestHeaderSize to set
*/
public void setRequestHeaderSize(int requestHeaderSize);
/**
* @return the responseBufferSize
*/
public int getResponseBufferSize();
/**
* @param responseBufferSize the responseBufferSize to set
*/
public void setResponseBufferSize(int responseBufferSize);
/**
* @return the responseHeaderSize
*/
public int getResponseHeaderSize();
/**
* @param responseHeaderSize the responseHeaderSize to set
*/
public void setResponseHeaderSize(int responseHeaderSize);
/**
* @return the requestBufferType
*/
public Buffers.Type getRequestBufferType();
/**
* @return the requestHeaderType
*/
public Buffers.Type getRequestHeaderType();
/**
* @return the responseBufferType
*/
public Buffers.Type getResponseBufferType();
/**
* @return the responseHeaderType
*/
public Buffers.Type getResponseHeaderType();
/**
* @param requestBuffers the requestBuffers to set
*/
public void setRequestBuffers(Buffers requestBuffers);
/**
* @param responseBuffers the responseBuffers to set
*/
public void setResponseBuffers(Buffers responseBuffers);
public Buffers getRequestBuffers();
public Buffers getResponseBuffers();
public void setMaxBuffers(int maxBuffers);
public int getMaxBuffers();
}

View File

@ -1,252 +0,0 @@
// ========================================================================
// Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.http;
import org.eclipse.jetty.io.Buffers;
import org.eclipse.jetty.io.BuffersFactory;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
/* ------------------------------------------------------------ */
/** Abstract Buffer pool.
* simple unbounded pool of buffers for header, request and response sizes.
*
*/
public class HttpBuffersImpl extends AbstractLifeCycle implements HttpBuffers
{
private int _requestBufferSize=16*1024;
private int _requestHeaderSize=6*1024;
private int _responseBufferSize=32*1024;
private int _responseHeaderSize=6*1024;
private int _maxBuffers=1024;
private Buffers.Type _requestBufferType=Buffers.Type.INDIRECT;
private Buffers.Type _requestHeaderType=Buffers.Type.INDIRECT;
private Buffers.Type _responseBufferType=Buffers.Type.INDIRECT;
private Buffers.Type _responseHeaderType=Buffers.Type.INDIRECT;
private Buffers _requestBuffers;
private Buffers _responseBuffers;
public HttpBuffersImpl()
{
super();
}
/**
* @return the requestBufferSize
*/
@Override
public int getRequestBufferSize()
{
return _requestBufferSize;
}
/**
* @param requestBufferSize the requestBufferSize to set
*/
@Override
public void setRequestBufferSize(int requestBufferSize)
{
_requestBufferSize = requestBufferSize;
}
/**
* @return the requestHeaderSize
*/
@Override
public int getRequestHeaderSize()
{
return _requestHeaderSize;
}
/**
* @param requestHeaderSize the requestHeaderSize to set
*/
@Override
public void setRequestHeaderSize(int requestHeaderSize)
{
_requestHeaderSize = requestHeaderSize;
}
/**
* @return the responseBufferSize
*/
@Override
public int getResponseBufferSize()
{
return _responseBufferSize;
}
/**
* @param responseBufferSize the responseBufferSize to set
*/
@Override
public void setResponseBufferSize(int responseBufferSize)
{
_responseBufferSize = responseBufferSize;
}
/**
* @return the responseHeaderSize
*/
@Override
public int getResponseHeaderSize()
{
return _responseHeaderSize;
}
/**
* @param responseHeaderSize the responseHeaderSize to set
*/
@Override
public void setResponseHeaderSize(int responseHeaderSize)
{
_responseHeaderSize = responseHeaderSize;
}
/**
* @return the requestBufferType
*/
@Override
public Buffers.Type getRequestBufferType()
{
return _requestBufferType;
}
/**
* @param requestBufferType the requestBufferType to set
*/
public void setRequestBufferType(Buffers.Type requestBufferType)
{
_requestBufferType = requestBufferType;
}
/**
* @return the requestHeaderType
*/
@Override
public Buffers.Type getRequestHeaderType()
{
return _requestHeaderType;
}
/**
* @param requestHeaderType the requestHeaderType to set
*/
public void setRequestHeaderType(Buffers.Type requestHeaderType)
{
_requestHeaderType = requestHeaderType;
}
/**
* @return the responseBufferType
*/
@Override
public Buffers.Type getResponseBufferType()
{
return _responseBufferType;
}
/**
* @param responseBufferType the responseBufferType to set
*/
public void setResponseBufferType(Buffers.Type responseBufferType)
{
_responseBufferType = responseBufferType;
}
/**
* @return the responseHeaderType
*/
@Override
public Buffers.Type getResponseHeaderType()
{
return _responseHeaderType;
}
/**
* @param responseHeaderType the responseHeaderType to set
*/
public void setResponseHeaderType(Buffers.Type responseHeaderType)
{
_responseHeaderType = responseHeaderType;
}
/**
* @param requestBuffers the requestBuffers to set
*/
@Override
public void setRequestBuffers(Buffers requestBuffers)
{
_requestBuffers = requestBuffers;
}
/**
* @param responseBuffers the responseBuffers to set
*/
@Override
public void setResponseBuffers(Buffers responseBuffers)
{
_responseBuffers = responseBuffers;
}
@Override
protected void doStart()
throws Exception
{
_requestBuffers=BuffersFactory.newBuffers(_requestHeaderType,_requestHeaderSize,_requestBufferType,_requestBufferSize,_requestBufferType,getMaxBuffers());
_responseBuffers=BuffersFactory.newBuffers(_responseHeaderType,_responseHeaderSize,_responseBufferType,_responseBufferSize,_responseBufferType,getMaxBuffers());
super.doStart();
}
@Override
protected void doStop()
throws Exception
{
_requestBuffers=null;
_responseBuffers=null;
}
@Override
public Buffers getRequestBuffers()
{
return _requestBuffers;
}
@Override
public Buffers getResponseBuffers()
{
return _responseBuffers;
}
@Override
public void setMaxBuffers(int maxBuffers)
{
_maxBuffers = maxBuffers;
}
@Override
public int getMaxBuffers()
{
return _maxBuffers;
}
@Override
public String toString()
{
return _requestBuffers+"/"+_responseBuffers;
}
}

View File

@ -5,7 +5,7 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
public abstract class AbstractAsyncConnection
public abstract class AbstractAsyncConnection implements AsyncConnection
{
private static final Logger LOG = Log.getLogger(AbstractAsyncConnection.class);
private final AsyncEndPoint _endp;
@ -17,14 +17,29 @@ public abstract class AbstractAsyncConnection
}
public abstract void onReadable();
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.io.AsyncConnection#onClose()
*/
@Override
public abstract void onClose();
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.io.AsyncConnection#getEndPoint()
*/
@Override
public AsyncEndPoint getEndPoint()
{
return _endp;
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.io.AsyncConnection#onIdleExpired(long)
*/
@Override
public void onIdleExpired(long idleForMs)
{
LOG.debug("onIdleExpired {}ms {} {}",idleForMs,this,_endp);

View File

@ -18,7 +18,7 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
private final Lock _lock = new ReentrantLock();
private volatile boolean _idlecheck;
private volatile AbstractAsyncConnection _connection;
private volatile AsyncConnection _connection;
private DispatchingIOFuture _readFuture;
private DispatchingIOFuture _writeFuture;
@ -26,7 +26,7 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
private ByteBuffer[] _writeBuffers;
public AbstractAsyncConnection getAsyncConnection()
public AsyncConnection getAsyncConnection()
{
return _connection;
}
@ -36,7 +36,7 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
new Thread(task).start();
}
public void setAsyncConnection(AbstractAsyncConnection connection)
public void setAsyncConnection(AsyncConnection connection)
{
_connection=connection;
}

View File

@ -0,0 +1,12 @@
package org.eclipse.jetty.io;
public interface AsyncConnection
{
public abstract void onClose();
public abstract AsyncEndPoint getEndPoint();
public abstract void onIdleExpired(long idleForMs);
}

View File

@ -55,7 +55,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
private boolean _open;
private volatile boolean _idlecheck;
private volatile AbstractAsyncConnection _connection;
private volatile AsyncConnection _connection;
private ByteBuffer[] _writeBuffers;
@ -73,7 +73,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
}
/* ------------------------------------------------------------ */
public AbstractAsyncConnection getAsyncConnection()
public AsyncConnection getAsyncConnection()
{
return _connection;
}
@ -94,9 +94,9 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
}
/* ------------------------------------------------------------ */
public void setAsyncConnection(AbstractAsyncConnection connection)
public void setAsyncConnection(AsyncConnection connection)
{
AbstractAsyncConnection old = getAsyncConnection();
AsyncConnection old = getAsyncConnection();
_connection = connection;
if (old != null && old != connection)
_manager.endPointUpgraded(this,old);

View File

@ -337,10 +337,10 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
protected abstract void endPointOpened(SelectChannelEndPoint endpoint);
/* ------------------------------------------------------------ */
protected abstract void endPointUpgraded(SelectChannelEndPoint endpoint,AbstractAsyncConnection oldConnection);
protected abstract void endPointUpgraded(SelectChannelEndPoint endpoint,AsyncConnection oldConnection);
/* ------------------------------------------------------------------------------- */
public abstract AbstractAsyncConnection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint, Object attachment);
public abstract AsyncConnection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint, Object attachment);
/* ------------------------------------------------------------ */
/**
@ -838,7 +838,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
{
LOG.debug("destroyEndPoint {}",endp);
_endPoints.remove(endp);
AbstractAsyncConnection connection=endp.getAsyncConnection();
AsyncConnection connection=endp.getAsyncConnection();
if (connection!=null)
connection.onClose();
endPointClosed(endp);

View File

@ -52,7 +52,7 @@ public class SslConnection extends AbstractAsyncConnection
private final SSLEngine _engine;
private final SSLSession _session;
private AbstractAsyncConnection _appConnection;
private AsyncConnection _appConnection;
private final AppEndPoint _appEndPoint;
private int _allocations;
private SslBuffers _buffers;
@ -120,9 +120,8 @@ public class SslConnection extends AbstractAsyncConnection
_appEndPoint = newAppEndPoint();
}
/* ------------------------------------------------------------ */
public void setAppConnection(AbstractAsyncConnection connection)
public void setAppConnection(AsyncConnection connection)
{
_appConnection=connection;
}

View File

@ -22,6 +22,8 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import org.eclipse.jetty.util.BufferUtil;
public class StandardByteBufferPool implements ByteBufferPool
{
private final ConcurrentMap<Integer, Queue<ByteBuffer>> directBuffers = new ConcurrentHashMap<>();
@ -51,11 +53,10 @@ public class StandardByteBufferPool implements ByteBufferPool
if (result == null)
{
int capacity = bucket * factor;
result = direct ? ByteBuffer.allocateDirect(capacity) : ByteBuffer.allocate(capacity);
result = direct ? BufferUtil.allocateDirect(capacity) : BufferUtil.allocate(capacity);
}
result.clear();
result.limit(size);
else
BufferUtil.clear(result);
return result;
}

View File

@ -41,13 +41,13 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
}
@Override
protected AbstractAsyncConnection newConnection(SocketChannel channel, AsyncEndPoint endpoint)
protected AsyncConnection newConnection(SocketChannel channel, AsyncEndPoint endpoint)
{
SSLEngine engine = __sslCtxFactory.newSslEngine();
engine.setUseClientMode(false);
SslConnection connection = new SslConnection(engine,endpoint);
AbstractAsyncConnection delegate = super.newConnection(channel,connection.getAppEndPoint());
AsyncConnection delegate = super.newConnection(channel,connection.getAppEndPoint());
connection.setAppConnection(delegate);
return connection;
}

View File

@ -53,12 +53,12 @@ public class SelectChannelEndPointTest
}
@Override
protected void endPointUpgraded(SelectChannelEndPoint endpoint, AbstractAsyncConnection oldConnection)
protected void endPointUpgraded(SelectChannelEndPoint endpoint, AsyncConnection oldConnection)
{
}
@Override
public AbstractAsyncConnection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint, Object attachment)
public AsyncConnection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint, Object attachment)
{
return SelectChannelEndPointTest.this.newConnection(channel,endpoint);
}
@ -101,7 +101,7 @@ public class SelectChannelEndPointTest
return new Socket(_connector.socket().getInetAddress(),_connector.socket().getLocalPort());
}
protected AbstractAsyncConnection newConnection(SocketChannel channel, AsyncEndPoint endpoint)
protected AsyncConnection newConnection(SocketChannel channel, AsyncEndPoint endpoint)
{
AbstractAsyncConnection connection = new TestConnection(endpoint);
connection.scheduleOnReadable();

View File

@ -14,21 +14,16 @@
package org.eclipse.jetty.server;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.concurrent.atomic.AtomicLong;
import javax.servlet.ServletRequest;
import org.eclipse.jetty.http.HttpBuffers;
import org.eclipse.jetty.http.HttpBuffersImpl;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.io.Buffers;
import org.eclipse.jetty.io.Buffers.Type;
import org.eclipse.jetty.io.AsyncConnection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.util.component.AggregateLifeCycle;
@ -52,7 +47,7 @@ import org.eclipse.jetty.util.thread.ThreadPool;
*
*
*/
public abstract class AbstractConnector extends AggregateLifeCycle implements HttpBuffers, Connector, Dumpable
public abstract class AbstractConnector extends AggregateLifeCycle implements Connector, Dumpable
{
private static final Logger LOG = Log.getLogger(AbstractConnector.class);
@ -96,14 +91,12 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Ht
/** duration of a connection */
private final SampleStatistic _connectionDurationStats = new SampleStatistic();
protected final HttpBuffersImpl _buffers = new HttpBuffersImpl();
/* ------------------------------------------------------------ */
/**
*/
public AbstractConnector()
{
addBean(_buffers);
}
/* ------------------------------------------------------------ */
@ -776,114 +769,6 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Ht
_forwardedSslSessionIdHeader = forwardedSslSessionId;
}
@Override
public int getRequestBufferSize()
{
return _buffers.getRequestBufferSize();
}
@Override
public void setRequestBufferSize(int requestBufferSize)
{
_buffers.setRequestBufferSize(requestBufferSize);
}
@Override
public int getRequestHeaderSize()
{
return _buffers.getRequestHeaderSize();
}
@Override
public void setRequestHeaderSize(int requestHeaderSize)
{
_buffers.setRequestHeaderSize(requestHeaderSize);
}
@Override
public int getResponseBufferSize()
{
return _buffers.getResponseBufferSize();
}
@Override
public void setResponseBufferSize(int responseBufferSize)
{
_buffers.setResponseBufferSize(responseBufferSize);
}
@Override
public int getResponseHeaderSize()
{
return _buffers.getResponseHeaderSize();
}
@Override
public void setResponseHeaderSize(int responseHeaderSize)
{
_buffers.setResponseHeaderSize(responseHeaderSize);
}
@Override
public Type getRequestBufferType()
{
return _buffers.getRequestBufferType();
}
@Override
public Type getRequestHeaderType()
{
return _buffers.getRequestHeaderType();
}
@Override
public Type getResponseBufferType()
{
return _buffers.getResponseBufferType();
}
@Override
public Type getResponseHeaderType()
{
return _buffers.getResponseHeaderType();
}
@Override
public void setRequestBuffers(Buffers requestBuffers)
{
_buffers.setRequestBuffers(requestBuffers);
}
@Override
public void setResponseBuffers(Buffers responseBuffers)
{
_buffers.setResponseBuffers(responseBuffers);
}
@Override
public Buffers getRequestBuffers()
{
return _buffers.getRequestBuffers();
}
@Override
public Buffers getResponseBuffers()
{
return _buffers.getResponseBuffers();
}
@Override
public void setMaxBuffers(int maxBuffers)
{
_buffers.setMaxBuffers(maxBuffers);
}
@Override
public int getMaxBuffers()
{
return _buffers.getMaxBuffers();
}
/* ------------------------------------------------------------ */
@Override
public String toString()

View File

@ -15,10 +15,8 @@ package org.eclipse.jetty.server;
import java.io.IOException;
import org.eclipse.jetty.io.Buffers;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.thread.ThreadPool;
/** HTTP Connector.
* Implementations of this interface provide connectors for the HTTP protocol.
@ -61,77 +59,6 @@ public interface Connector extends LifeCycle
/* ------------------------------------------------------------ */
Server getServer();
/* ------------------------------------------------------------ */
/**
* @return Returns the request header buffer size in bytes.
*/
int getRequestHeaderSize();
/* ------------------------------------------------------------ */
/**
* Set the size of the buffer to be used for request headers.
* @param size The size in bytes.
*/
void setRequestHeaderSize(int size);
/* ------------------------------------------------------------ */
/**
* @return Returns the response header buffer size in bytes.
*/
int getResponseHeaderSize();
/* ------------------------------------------------------------ */
/**
* Set the size of the buffer to be used for request headers.
* @param size The size in bytes.
*/
void setResponseHeaderSize(int size);
/* ------------------------------------------------------------ */
/**
* @return factory for request buffers
*/
Buffers getRequestBuffers();
/* ------------------------------------------------------------ */
/**
* @return factory for response buffers
*/
Buffers getResponseBuffers();
/* ------------------------------------------------------------ */
/**
* @return Returns the requestBufferSize.
*/
int getRequestBufferSize();
/* ------------------------------------------------------------ */
/**
* Set the size of the content buffer for receiving requests.
* These buffers are only used for active connections that have
* requests with bodies that will not fit within the header buffer.
* @param requestBufferSize The requestBufferSize to set.
*/
void setRequestBufferSize(int requestBufferSize);
/* ------------------------------------------------------------ */
/**
* @return Returns the responseBufferSize.
*/
int getResponseBufferSize();
/* ------------------------------------------------------------ */
/**
* Set the size of the content buffer for sending responses.
* These buffers are only used for active connections that are sending
* responses with bodies that will not fit within the header buffer.
* @param responseBufferSize The responseBufferSize to set.
*/
void setResponseBufferSize(int responseBufferSize);
/* ------------------------------------------------------------ */
/**
* @return The port to use when redirecting a request if a data constraint of integral is

View File

@ -17,14 +17,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.sql.Connection;
import java.util.List;
import javax.servlet.DispatcherType;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.continuation.ContinuationThrowable;
@ -45,7 +41,6 @@ import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.RuntimeIOException;
import org.eclipse.jetty.io.UncheckedPrintWriter;
import org.eclipse.jetty.util.ArrayQueue;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

View File

@ -22,13 +22,14 @@ import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.jetty.http.HttpException;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpGenerator;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.http.HttpGenerator.Action;
import org.eclipse.jetty.http.HttpParser;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.AbstractAsyncConnection;
import org.eclipse.jetty.io.AsyncConnection;
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.DispatchingIOFuture;
import org.eclipse.jetty.io.DoneIOFuture;
import org.eclipse.jetty.io.EofException;
@ -47,14 +48,16 @@ public class HttpConnection extends AbstractAsyncConnection
private static final ThreadLocal<HttpConnection> __currentConnection = new ThreadLocal<HttpConnection>();
private final Lock _lock = new ReentrantLock();
private final Server _server;
private final Connector _connector;
private final HttpParser _parser;
private final HttpGenerator _generator;
private final HttpChannel _channel;
private final Lock _lock = new ReentrantLock();
private final ByteBufferPool _bufferPool;
private IOFuture _writeFuture;
ByteBuffer _requestBuffer=null;
ByteBuffer _responseHeader=null;
@ -82,6 +85,8 @@ public class HttpConnection extends AbstractAsyncConnection
{
super(endpoint);
_connector = connector;
_bufferPool=_connector.getBufferPool();
_server = server;
_channel = new HttpOverHttpChannel(server);
@ -132,16 +137,16 @@ public class HttpConnection extends AbstractAsyncConnection
_generator.reset();
_channel.reset();
if (_requestBuffer!=null)
_connector.getResponseBuffers().returnBuffer(_requestBuffer);
_bufferPool.release(_requestBuffer);
_requestBuffer=null;
if (_responseHeader!=null)
_connector.getResponseBuffers().returnBuffer(_responseHeader);
_bufferPool.release(_responseHeader);
_responseHeader=null;
if (_responseBuffer!=null)
_connector.getResponseBuffers().returnBuffer(_responseBuffer);
_bufferPool.release(_responseBuffer);
_responseBuffer=null;
if (_chunk!=null)
_connector.getResponseBuffers().returnBuffer(_chunk);
_bufferPool.release(_chunk);
_chunk=null;
}
@ -168,7 +173,7 @@ public class HttpConnection extends AbstractAsyncConnection
@Override
public void onReadable()
{
AbstractAsyncConnection connection = this;
AsyncConnection connection = this;
boolean progress=true;
try
@ -184,8 +189,8 @@ public class HttpConnection extends AbstractAsyncConnection
// We will need a buffer to read into
if (_requestBuffer==null)
_requestBuffer=_parser.isInContent()
?_connector.getRequestBuffers().getBuffer()
:_connector.getRequestBuffers().getHeader();
?_bufferPool.acquire(_connector.getRequestBufferSize(),false)
:_bufferPool.acquire(_connector.getRequestHeaderSize(),false);
// If we parse to an event, call the connection
if (BufferUtil.hasContent(_requestBuffer) && _parser.parseNext(_requestBuffer))
@ -216,7 +221,7 @@ public class HttpConnection extends AbstractAsyncConnection
// Return empty request buffer if all has been consumed
if (_requestBuffer!=null && !_requestBuffer.hasRemaining() && _channel.available()==0)
{
_connector.getRequestBuffers().returnBuffer(_requestBuffer);
_bufferPool.release(_requestBuffer);
_requestBuffer=null;
}
@ -226,7 +231,7 @@ public class HttpConnection extends AbstractAsyncConnection
// look for a switched connection instance?
if (_channel.getResponse().getStatus()==HttpStatus.SWITCHING_PROTOCOLS_101)
{
AbstractAsyncConnection switched=(AbstractAsyncConnection)_channel.getRequest().getAttribute("org.eclipse.jetty.io.Connection");
AsyncConnection switched=(AsyncConnection)_channel.getRequest().getAttribute("org.eclipse.jetty.io.Connection");
if (switched!=null)
connection=switched;
}
@ -291,11 +296,11 @@ public class HttpConnection extends AbstractAsyncConnection
switch(result)
{
case NEED_HEADER:
_responseHeader=_connector.getResponseBuffers().getHeader();
_responseHeader=_bufferPool.acquire(_connector.getResponseHeaderSize(),false);
break;
case NEED_BUFFER:
_responseBuffer=_connector.getResponseBuffers().getBuffer();
_responseBuffer=_bufferPool.acquire(_connector.getResponseBufferSize(),false);
break;
case NEED_CHUNK:
@ -377,16 +382,16 @@ public class HttpConnection extends AbstractAsyncConnection
switch(result)
{
case NEED_HEADER:
_responseHeader=_connector.getResponseBuffers().getHeader();
_responseHeader=_bufferPool.acquire(_connector.getResponseHeaderSize(),false);
break;
case NEED_BUFFER:
_responseBuffer=_connector.getResponseBuffers().getBuffer();
_responseBuffer=_bufferPool.acquire(_connector.getResponseBufferSize(),false);
break;
case NEED_CHUNK:
_responseHeader=null;
_chunk=_connector.getResponseBuffers().getBuffer(HttpGenerator.CHUNK_SIZE);
_chunk=_bufferPool.acquire(HttpGenerator.CHUNK_SIZE,false);
break;
case FLUSH:
@ -436,14 +441,14 @@ public class HttpConnection extends AbstractAsyncConnection
if (BufferUtil.hasContent(b1))
{
if (BufferUtil.hasContent(b2))
return _endp.write(b0,b1,b2);
return _endp.write(b0,b1);
return getEndPoint().write(b0,b1,b2);
return getEndPoint().write(b0,b1);
}
else
{
if (BufferUtil.hasContent(b2))
return _endp.write(b0,b2);
return _endp.write(b0);
return getEndPoint().write(b0,b2);
return getEndPoint().write(b0);
}
}
else
@ -451,13 +456,13 @@ public class HttpConnection extends AbstractAsyncConnection
if (BufferUtil.hasContent(b1))
{
if (BufferUtil.hasContent(b2))
return _endp.write(b1,b2);
return _endp.write(b1);
return getEndPoint().write(b1,b2);
return getEndPoint().write(b1);
}
else
{
if (BufferUtil.hasContent(b2))
return _endp.write(b2);
return getEndPoint().write(b2);
return DoneIOFuture.COMPLETE;
}
}
@ -627,7 +632,7 @@ public class HttpConnection extends AbstractAsyncConnection
protected void blockForContent() throws IOException
{
// While progress and the connection has not changed
while (_endp.isOpen())
while (getEndPoint().isOpen())
{
try
{
@ -636,7 +641,7 @@ public class HttpConnection extends AbstractAsyncConnection
// We will need a buffer to read into
if (_requestBuffer==null)
_requestBuffer=_connector.getRequestBuffers().getBuffer();
_requestBuffer=_bufferPool.acquire(_connector.getRequestBufferSize(),false);
// If we parse to an event, return
if (BufferUtil.hasContent(_requestBuffer) && _parser.parseNext(_requestBuffer))
@ -656,7 +661,7 @@ public class HttpConnection extends AbstractAsyncConnection
// Return empty request buffer
if (_requestBuffer!=null && !_requestBuffer.hasRemaining() && _channel.available()==0)
{
_connector.getRequestBuffers().returnBuffer(_requestBuffer);
_bufferPool.release(_requestBuffer);
_requestBuffer=null;
}
}

View File

@ -14,12 +14,9 @@
package org.eclipse.jetty.server;
import java.io.IOException;
import java.nio.ByteBuffer;
import javax.servlet.ServletInputStream;
import org.eclipse.jetty.util.BufferUtil;
public class HttpInput extends ServletInputStream
{

View File

@ -20,7 +20,6 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.ByteArrayEndPoint;
import org.eclipse.jetty.io.AsyncConnection;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

View File

@ -21,7 +21,6 @@ import org.eclipse.jetty.http.HttpParser;
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.SelectChannelEndPoint;
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.SelectorManager;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;

View File

@ -16,7 +16,6 @@
*/
package org.eclipse.jetty.server.nio;
import org.eclipse.jetty.io.Buffers.Type;
import org.eclipse.jetty.server.AbstractConnector;
public abstract class AbstractNIOConnector extends AbstractConnector implements NIOConnector

View File

@ -20,10 +20,10 @@ import java.util.ConcurrentModificationException;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.NetworkTrafficListener;
import org.eclipse.jetty.io.NetworkTrafficSelectChannelEndPoint;
import org.eclipse.jetty.io.SelectChannelEndPoint;
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.SelectorManager;
/**

View File

@ -22,10 +22,8 @@ import java.nio.channels.SocketChannel;
import org.eclipse.jetty.continuation.Continuation;
import org.eclipse.jetty.io.AsyncConnection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.SelectChannelEndPoint;
import org.eclipse.jetty.io.AbstractAsyncConnection;
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.SelectChannelEndPoint;
import org.eclipse.jetty.io.SelectorManager;
import org.eclipse.jetty.io.SelectorManager.SelectSet;
import org.eclipse.jetty.server.HttpConnection;
@ -255,7 +253,7 @@ public class SelectChannelConnector extends AbstractNIOConnector
}
/* ------------------------------------------------------------------------------- */
protected AbstractAsyncConnection newConnection(SocketChannel channel,final AsyncEndPoint endpoint)
protected AsyncConnection newConnection(SocketChannel channel,final AsyncEndPoint endpoint)
{
return new HttpConnection(SelectChannelConnector.this,endpoint,getServer());
}
@ -295,7 +293,7 @@ public class SelectChannelConnector extends AbstractNIOConnector
}
@Override
public AbstractAsyncConnection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint, Object attachment)
public AsyncConnection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint, Object attachment)
{
return SelectChannelConnector.this.newConnection(channel,endpoint);
}

View File

@ -23,9 +23,6 @@ import javax.net.ssl.SSLSocket;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.Buffers;
import org.eclipse.jetty.io.Buffers.Type;
import org.eclipse.jetty.io.BuffersFactory;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.RuntimeIOException;
import org.eclipse.jetty.io.SslConnection;

View File

@ -8,9 +8,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpGenerator;
import org.eclipse.jetty.io.Buffers;
import org.eclipse.jetty.io.ByteArrayEndPoint;
import org.eclipse.jetty.io.SimpleBuffers;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.Utf8StringBuilder;

View File

@ -5,8 +5,8 @@ import java.net.Socket;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.util.IO;
import org.junit.Test;