Mercurial Hosting > luan
changeset 868:688b875e18ba
remove ThreadLocalBuffers
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 03 Oct 2016 19:29:34 -0600 |
parents | 4f5547d29192 |
children | 3f3675b1c83c |
files | src/org/eclipse/jetty/http/HttpBuffers.java src/org/eclipse/jetty/http/HttpBuffersImpl.java src/org/eclipse/jetty/io/BuffersFactory.java src/org/eclipse/jetty/io/ThreadLocalBuffers.java src/org/eclipse/jetty/server/AbstractConnector.java |
diffstat | 5 files changed, 250 insertions(+), 399 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/http/HttpBuffers.java Sun Oct 02 21:06:18 2016 -0600 +++ b/src/org/eclipse/jetty/http/HttpBuffers.java Mon Oct 03 19:29:34 2016 -0600 @@ -19,90 +19,86 @@ 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. */ public interface HttpBuffers { - /** - * @return the requestBufferSize - */ - public int getRequestBufferSize(); - - /** - * @param requestBufferSize the requestBufferSize to set - */ - public void setRequestBufferSize(int requestBufferSize); + /** + * @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 requestHeaderSize + */ + public int getRequestHeaderSize(); - /** - * @return the responseBufferSize - */ - public int getResponseBufferSize(); + /** + * @param requestHeaderSize the requestHeaderSize to set + */ + public void setRequestHeaderSize(int requestHeaderSize); - /** - * @param responseBufferSize the responseBufferSize to set - */ - public void setResponseBufferSize(int responseBufferSize); + /** + * @return the responseBufferSize + */ + public int getResponseBufferSize(); - /** - * @return the responseHeaderSize - */ - public int getResponseHeaderSize(); + /** + * @param responseBufferSize the responseBufferSize to set + */ + public void setResponseBufferSize(int responseBufferSize); - /** - * @param responseHeaderSize the responseHeaderSize to set - */ - public void setResponseHeaderSize(int responseHeaderSize); + /** + * @return the responseHeaderSize + */ + public int getResponseHeaderSize(); - /** - * @return the requestBufferType - */ - public Buffers.Type getRequestBufferType(); + /** + * @param responseHeaderSize the responseHeaderSize to set + */ + public void setResponseHeaderSize(int responseHeaderSize); - /** - * @return the requestHeaderType - */ - public Buffers.Type getRequestHeaderType(); + /** + * @return the requestBufferType + */ + public Buffers.Type getRequestBufferType(); - /** - * @return the responseBufferType - */ - public Buffers.Type getResponseBufferType(); + /** + * @return the requestHeaderType + */ + public Buffers.Type getRequestHeaderType(); - /** - * @return the responseHeaderType - */ - public Buffers.Type getResponseHeaderType(); + /** + * @return the responseBufferType + */ + public Buffers.Type getResponseBufferType(); - /** - * @param requestBuffers the requestBuffers to set - */ - public void setRequestBuffers(Buffers requestBuffers); + /** + * @return the responseHeaderType + */ + public Buffers.Type getResponseHeaderType(); - /** - * @param responseBuffers the responseBuffers to set - */ - public void setResponseBuffers(Buffers responseBuffers); + /** + * @param requestBuffers the requestBuffers to set + */ + public void setRequestBuffers(Buffers requestBuffers); - public Buffers getRequestBuffers(); - - public Buffers getResponseBuffers(); + /** + * @param responseBuffers the responseBuffers to set + */ + public void setResponseBuffers(Buffers responseBuffers); - public void setMaxBuffers(int maxBuffers); + public Buffers getRequestBuffers(); + + public Buffers getResponseBuffers(); - public int getMaxBuffers(); - + public int getMaxBuffers(); + }
--- a/src/org/eclipse/jetty/http/HttpBuffersImpl.java Sun Oct 02 21:06:18 2016 -0600 +++ b/src/org/eclipse/jetty/http/HttpBuffersImpl.java Mon Oct 03 19:29:34 2016 -0600 @@ -27,212 +27,207 @@ * simple unbounded pool of buffers for header, request and response sizes. * */ -public class HttpBuffersImpl extends AbstractLifeCycle implements HttpBuffers +public final 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.BYTE_ARRAY; - private Buffers.Type _requestHeaderType=Buffers.Type.BYTE_ARRAY; - private Buffers.Type _responseBufferType=Buffers.Type.BYTE_ARRAY; - private Buffers.Type _responseHeaderType=Buffers.Type.BYTE_ARRAY; - - private Buffers _requestBuffers; - private Buffers _responseBuffers; - - - public HttpBuffersImpl() - { - super(); - } - - /** - * @return the requestBufferSize - */ - public int getRequestBufferSize() - { - return _requestBufferSize; - } - - /** - * @param requestBufferSize the requestBufferSize to set - */ - public void setRequestBufferSize(int requestBufferSize) - { - _requestBufferSize = requestBufferSize; - } + private int _requestBufferSize=16*1024; + private int _requestHeaderSize=6*1024; + private int _responseBufferSize=32*1024; + private int _responseHeaderSize=6*1024; + private final int _maxBuffers=1024; + + private Buffers.Type _requestBufferType=Buffers.Type.BYTE_ARRAY; + private Buffers.Type _requestHeaderType=Buffers.Type.BYTE_ARRAY; + private Buffers.Type _responseBufferType=Buffers.Type.BYTE_ARRAY; + private Buffers.Type _responseHeaderType=Buffers.Type.BYTE_ARRAY; + + private Buffers _requestBuffers; + private Buffers _responseBuffers; + + + public HttpBuffersImpl() + { + super(); + } + + /** + * @return the requestBufferSize + */ + public int getRequestBufferSize() + { + return _requestBufferSize; + } + + /** + * @param requestBufferSize the requestBufferSize to set + */ + public void setRequestBufferSize(int requestBufferSize) + { + _requestBufferSize = requestBufferSize; + } - /** - * @return the requestHeaderSize - */ - public int getRequestHeaderSize() - { - return _requestHeaderSize; - } + /** + * @return the requestHeaderSize + */ + public int getRequestHeaderSize() + { + return _requestHeaderSize; + } - /** - * @param requestHeaderSize the requestHeaderSize to set - */ - public void setRequestHeaderSize(int requestHeaderSize) - { - _requestHeaderSize = requestHeaderSize; - } + /** + * @param requestHeaderSize the requestHeaderSize to set + */ + public void setRequestHeaderSize(int requestHeaderSize) + { + _requestHeaderSize = requestHeaderSize; + } - /** - * @return the responseBufferSize - */ - public int getResponseBufferSize() - { - return _responseBufferSize; - } + /** + * @return the responseBufferSize + */ + public int getResponseBufferSize() + { + return _responseBufferSize; + } - /** - * @param responseBufferSize the responseBufferSize to set - */ - public void setResponseBufferSize(int responseBufferSize) - { - _responseBufferSize = responseBufferSize; - } + /** + * @param responseBufferSize the responseBufferSize to set + */ + public void setResponseBufferSize(int responseBufferSize) + { + _responseBufferSize = responseBufferSize; + } - /** - * @return the responseHeaderSize - */ - public int getResponseHeaderSize() - { - return _responseHeaderSize; - } + /** + * @return the responseHeaderSize + */ + public int getResponseHeaderSize() + { + return _responseHeaderSize; + } - /** - * @param responseHeaderSize the responseHeaderSize to set - */ - public void setResponseHeaderSize(int responseHeaderSize) - { - _responseHeaderSize = responseHeaderSize; - } + /** + * @param responseHeaderSize the responseHeaderSize to set + */ + public void setResponseHeaderSize(int responseHeaderSize) + { + _responseHeaderSize = responseHeaderSize; + } - /** - * @return the requestBufferType - */ - public Buffers.Type getRequestBufferType() - { - return _requestBufferType; - } + /** + * @return the requestBufferType + */ + public Buffers.Type getRequestBufferType() + { + return _requestBufferType; + } - /** - * @param requestBufferType the requestBufferType to set - */ - public void setRequestBufferType(Buffers.Type requestBufferType) - { - _requestBufferType = requestBufferType; - } + /** + * @param requestBufferType the requestBufferType to set + */ + public void setRequestBufferType(Buffers.Type requestBufferType) + { + _requestBufferType = requestBufferType; + } - /** - * @return the requestHeaderType - */ - public Buffers.Type getRequestHeaderType() - { - return _requestHeaderType; - } + /** + * @return the requestHeaderType + */ + public Buffers.Type getRequestHeaderType() + { + return _requestHeaderType; + } - /** - * @param requestHeaderType the requestHeaderType to set - */ - public void setRequestHeaderType(Buffers.Type requestHeaderType) - { - _requestHeaderType = requestHeaderType; - } + /** + * @param requestHeaderType the requestHeaderType to set + */ + public void setRequestHeaderType(Buffers.Type requestHeaderType) + { + _requestHeaderType = requestHeaderType; + } - /** - * @return the responseBufferType - */ - public Buffers.Type getResponseBufferType() - { - return _responseBufferType; - } + /** + * @return the responseBufferType + */ + public Buffers.Type getResponseBufferType() + { + return _responseBufferType; + } - /** - * @param responseBufferType the responseBufferType to set - */ - public void setResponseBufferType(Buffers.Type responseBufferType) - { - _responseBufferType = responseBufferType; - } + /** + * @param responseBufferType the responseBufferType to set + */ + public void setResponseBufferType(Buffers.Type responseBufferType) + { + _responseBufferType = responseBufferType; + } - /** - * @return the responseHeaderType - */ - public Buffers.Type getResponseHeaderType() - { - return _responseHeaderType; - } + /** + * @return the responseHeaderType + */ + public Buffers.Type getResponseHeaderType() + { + return _responseHeaderType; + } - /** - * @param responseHeaderType the responseHeaderType to set - */ - public void setResponseHeaderType(Buffers.Type responseHeaderType) - { - _responseHeaderType = responseHeaderType; - } + /** + * @param responseHeaderType the responseHeaderType to set + */ + public void setResponseHeaderType(Buffers.Type responseHeaderType) + { + _responseHeaderType = responseHeaderType; + } - /** - * @param requestBuffers the requestBuffers to set - */ - public void setRequestBuffers(Buffers requestBuffers) - { - _requestBuffers = requestBuffers; - } + /** + * @param requestBuffers the requestBuffers to set + */ + public void setRequestBuffers(Buffers requestBuffers) + { + _requestBuffers = requestBuffers; + } - /** - * @param responseBuffers the responseBuffers to set - */ - public void setResponseBuffers(Buffers responseBuffers) - { - _responseBuffers = responseBuffers; - } + /** + * @param responseBuffers the responseBuffers to set + */ + 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 + 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; + } - public Buffers getRequestBuffers() - { - return _requestBuffers; - } - + public Buffers getRequestBuffers() + { + return _requestBuffers; + } + - public Buffers getResponseBuffers() - { - return _responseBuffers; - } + public Buffers getResponseBuffers() + { + return _responseBuffers; + } - public void setMaxBuffers(int maxBuffers) - { - _maxBuffers = maxBuffers; - } - - public int getMaxBuffers() - { - return _maxBuffers; - } - - public String toString() - { - return _requestBuffers+"/"+_responseBuffers; - } + public int getMaxBuffers() + { + return _maxBuffers; + } + + public String toString() + { + return _requestBuffers+"/"+_responseBuffers; + } }
--- a/src/org/eclipse/jetty/io/BuffersFactory.java Sun Oct 02 21:06:18 2016 -0600 +++ b/src/org/eclipse/jetty/io/BuffersFactory.java Mon Oct 03 19:29:34 2016 -0600 @@ -20,10 +20,10 @@ public class BuffersFactory { - public static Buffers newBuffers(Buffers.Type headerType, int headerSize, Buffers.Type bufferType, int bufferSize, Buffers.Type otherType,int maxSize) - { - if (maxSize>=0) - return new PooledBuffers(headerType,headerSize,bufferType,bufferSize,otherType,maxSize); - return new ThreadLocalBuffers(headerType,headerSize,bufferType,bufferSize,otherType); - } + public static Buffers newBuffers(Buffers.Type headerType, int headerSize, Buffers.Type bufferType, int bufferSize, Buffers.Type otherType,int maxSize) + { + if (maxSize<0) + throw new RuntimeException(); + return new PooledBuffers(headerType,headerSize,bufferType,bufferSize,otherType,maxSize); + } }
--- a/src/org/eclipse/jetty/io/ThreadLocalBuffers.java Sun Oct 02 21:06:18 2016 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2014 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.io; - - - -/* ------------------------------------------------------------ */ -/** Abstract Buffer pool. - * simple unbounded pool of buffers for header, request and response sizes. - * - */ -public class ThreadLocalBuffers extends AbstractBuffers -{ - /* ------------------------------------------------------------ */ - private final ThreadLocal<ThreadBuffers> _buffers=new ThreadLocal<ThreadBuffers>() - { - @Override - protected ThreadBuffers initialValue() - { - return new ThreadBuffers(); - } - }; - - /* ------------------------------------------------------------ */ - public ThreadLocalBuffers(Buffers.Type headerType, int headerSize, Buffers.Type bufferType, int bufferSize, Buffers.Type otherType) - { - super(headerType,headerSize,bufferType,bufferSize,otherType); - } - - /* ------------------------------------------------------------ */ - public Buffer getBuffer() - { - ThreadBuffers buffers = _buffers.get(); - if (buffers._buffer!=null) - { - Buffer b=buffers._buffer; - buffers._buffer=null; - return b; - } - - if (buffers._other!=null && isBuffer(buffers._other)) - { - Buffer b=buffers._other; - buffers._other=null; - return b; - } - - return newBuffer(); - } - - /* ------------------------------------------------------------ */ - public Buffer getHeader() - { - ThreadBuffers buffers = _buffers.get(); - if (buffers._header!=null) - { - Buffer b=buffers._header; - buffers._header=null; - return b; - } - - if (buffers._other!=null && isHeader(buffers._other)) - { - Buffer b=buffers._other; - buffers._other=null; - return b; - } - - return newHeader(); - } - - /* ------------------------------------------------------------ */ - public Buffer getBuffer(int size) - { - ThreadBuffers buffers = _buffers.get(); - if (buffers._other!=null && buffers._other.capacity()==size) - { - Buffer b=buffers._other; - buffers._other=null; - return b; - } - - return newBuffer(size); - } - - /* ------------------------------------------------------------ */ - public void returnBuffer(Buffer buffer) - { - buffer.clear(); - if (buffer.isVolatile() || buffer.isImmutable()) - return; - - ThreadBuffers buffers = _buffers.get(); - - if (buffers._header==null && isHeader(buffer)) - buffers._header=buffer; - else if (buffers._buffer==null && isBuffer(buffer)) - buffers._buffer=buffer; - else - buffers._other=buffer; - } - - - /* ------------------------------------------------------------ */ - @Override - public String toString() - { - return "{{"+getHeaderSize()+","+getBufferSize()+"}}"; - } - - /* ------------------------------------------------------------ */ - /* ------------------------------------------------------------ */ - protected static class ThreadBuffers - { - Buffer _buffer; - Buffer _header; - Buffer _other; - } -}
--- a/src/org/eclipse/jetty/server/AbstractConnector.java Sun Oct 02 21:06:18 2016 -0600 +++ b/src/org/eclipse/jetty/server/AbstractConnector.java Mon Oct 03 19:29:34 2016 -0600 @@ -849,11 +849,6 @@ return _buffers.getResponseBuffers(); } - public void setMaxBuffers(int maxBuffers) - { - _buffers.setMaxBuffers(maxBuffers); - } - public int getMaxBuffers() { return _buffers.getMaxBuffers();