Mercurial Hosting > luan
diff src/org/eclipse/jetty/http/AbstractGenerator.java @ 983:23ec25435b8c
simplify AbstractGenerator
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 16 Oct 2016 22:58:41 -0600 |
parents | dbecd7faa1f5 |
children | 8c13b9224cff |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/http/AbstractGenerator.java Sun Oct 16 21:40:27 2016 -0600 +++ b/src/org/eclipse/jetty/http/AbstractGenerator.java Sun Oct 16 22:58:41 2016 -0600 @@ -38,7 +38,7 @@ * faster, but will consume more memory. This option is just for testing and tuning. * */ -public abstract class AbstractGenerator +abstract class AbstractGenerator { private static final Logger LOG = LoggerFactory.getLogger(AbstractGenerator.class); @@ -46,38 +46,34 @@ public static final boolean MORE=false; // states - public final static int STATE_HEADER = 0; - public final static int STATE_CONTENT = 2; - public final static int STATE_FLUSHING = 3; - public final static int STATE_END = 4; - - public static final byte[] NO_BYTES = {}; + final static int STATE_HEADER = 0; + final static int STATE_CONTENT = 2; + final static int STATE_FLUSHING = 3; + final static int STATE_END = 4; // data - protected final Buffers _buffers; // source of buffers - protected final EndPoint _endp; + final Buffers _buffers; // source of buffers + final EndPoint _endp; - protected int _state = STATE_HEADER; + int _state = STATE_HEADER; - protected int _status = 0; - protected int _version = HttpVersions.HTTP_1_1_ORDINAL; - protected Buffer _reason; - protected Buffer _method; - protected String _uri; + int _status = 0; + int _version = HttpVersions.HTTP_1_1_ORDINAL; + Buffer _reason; + Buffer _method; + String _uri; - protected long _contentWritten = 0; - protected long _contentLength = HttpTokens.UNKNOWN_CONTENT; - protected boolean _last = false; - protected boolean _head = false; - protected boolean _noContent = false; - protected Boolean _persistent = null; + long _contentWritten = 0; + long _contentLength = HttpTokens.UNKNOWN_CONTENT; + boolean _last = false; + boolean _head = false; + boolean _noContent = false; + Boolean _persistent = null; - protected Buffer _header; // Buffer for HTTP header (and maybe small _content) - protected Buffer _buffer; // Buffer for copy of passed _content - protected Buffer _content; // Buffer passed to addContent - - protected Buffer _date; + Buffer _header; // Buffer for HTTP header (and maybe small _content) + Buffer _buffer; // Buffer for copy of passed _content + Buffer _content; // Buffer passed to addContent /* ------------------------------------------------------------------------------- */ @@ -87,7 +83,7 @@ * @param buffers buffer pool * @param io the end point */ - public AbstractGenerator(Buffers buffers, EndPoint io) + AbstractGenerator(Buffers buffers, EndPoint io) { this._buffers = buffers; this._endp = io; @@ -106,19 +102,13 @@ */ public abstract void addContent(Buffer content, boolean last) throws IOException; - /* ------------------------------------------------------------------------------- */ - public abstract boolean isRequest(); + abstract boolean isRequest(); - /* ------------------------------------------------------------------------------- */ - public abstract boolean isResponse(); - - /* ------------------------------------------------------------------------------- */ - public boolean isOpen() + public final boolean isOpen() { return _endp.isOpen(); } - /* ------------------------------------------------------------------------------- */ public void reset() { _state = STATE_HEADER; @@ -131,14 +121,12 @@ _persistent = null; _contentWritten = 0; _contentLength = HttpTokens.UNKNOWN_CONTENT; - _date = null; _content = null; - _method=null; + _method = null; } - /* ------------------------------------------------------------------------------- */ - public void returnBuffers() + public final void returnBuffers() { if (_buffer!=null && _buffer.length()==0) { @@ -153,8 +141,7 @@ } } - /* ------------------------------------------------------------------------------- */ - public void resetBuffer() + public final void resetBuffer() { if(_state>=STATE_FLUSHING) throw new IllegalStateException("Flushed"); @@ -172,77 +159,34 @@ /** * @return Returns the contentBufferSize. */ - public int getContentBufferSize() + public final int getContentBufferSize() { if (_buffer==null) _buffer=_buffers.getBuffer(); return _buffer.capacity(); } - /* ------------------------------------------------------------ */ - /** - * @param contentBufferSize The contentBufferSize to set. - */ - public void increaseContentBufferSize(int contentBufferSize) - { - if (_buffer==null) - _buffer=_buffers.getBuffer(); - if (contentBufferSize > _buffer.capacity()) - { - Buffer nb = _buffers.getBuffer(contentBufferSize); - nb.put(_buffer); - _buffers.returnBuffer(_buffer); - _buffer = nb; - } - } - - /* ------------------------------------------------------------ */ - public Buffer getUncheckedBuffer() + public final Buffer getUncheckedBuffer() { return _buffer; } - /* ------------------------------------------------------------ */ - public int getState() - { - return _state; - } - - /* ------------------------------------------------------------ */ - public boolean isState(int state) - { - return _state == state; - } - - /* ------------------------------------------------------------ */ - public boolean isComplete() + public final boolean isComplete() { return _state == STATE_END; } - /* ------------------------------------------------------------ */ - public boolean isIdle() + public final boolean isIdle() { return _state == STATE_HEADER && _method==null && _status==0; } - /* ------------------------------------------------------------ */ - public boolean isCommitted() + public final boolean isCommitted() { return _state != STATE_HEADER; } - /* ------------------------------------------------------------ */ - /** - * @return Returns the head. - */ - public boolean isHead() - { - return _head; - } - - /* ------------------------------------------------------------ */ - public void setContentLength(long value) + public final void setContentLength(long value) { if (value<0) _contentLength=HttpTokens.UNKNOWN_CONTENT; @@ -250,11 +194,7 @@ _contentLength=value; } - /* ------------------------------------------------------------ */ - /** - * @param head The head to set. - */ - public void setHead(boolean head) + public final void setHead(boolean head) { _head = head; } @@ -264,17 +204,16 @@ * @return <code>false</code> if the connection should be closed after a request has been read, * <code>true</code> if it should be used for additional requests. */ - public boolean isPersistent() + public final boolean isPersistent() { return _persistent!=null ?_persistent.booleanValue() :(isRequest()?true:_version>HttpVersions.HTTP_1_0_ORDINAL); } - /* ------------------------------------------------------------ */ - public void setPersistent(boolean persistent) + public final void setPersistent(boolean persistent) { - _persistent=persistent; + _persistent = persistent; } /* ------------------------------------------------------------ */ @@ -282,7 +221,7 @@ * @param version The version of the client the response is being sent to (NB. Not the version * in the response, which is the version of the server). */ - public void setVersion(int version) + public final void setVersion(int version) { if (_state != STATE_HEADER) throw new IllegalStateException("STATE!=START "+_state); @@ -291,36 +230,12 @@ _noContent=true; } - public int getVersion() - { - return _version; - } - - public void setDate(Buffer timeStampBuffer) - { - _date=timeStampBuffer; - } - - /* ------------------------------------------------------------ */ - /** - */ - public void setRequest(String method, String uri) - { - if (method==null || HttpMethods.GET.equals(method) ) - _method=HttpMethods.GET_BUFFER; - else - _method=HttpMethods.CACHE.lookup(method); - _uri=uri; - if (_version==HttpVersions.HTTP_0_9_ORDINAL) - _noContent=true; - } - /* ------------------------------------------------------------ */ /** * @param status The status code to send. * @param reason the status message to send. */ - public void setResponse(int status, String reason) + public final void setResponse(int status, String reason) { if (_state != STATE_HEADER) throw new IllegalStateException("STATE!=START"); _method=null; @@ -344,22 +259,7 @@ } } - /* ------------------------------------------------------------ */ - /** Prepare buffer for unchecked writes. - * Prepare the generator buffer to receive unchecked writes - * @return the available space in the buffer. - * @throws IOException - */ - public abstract int prepareUncheckedAddContent() throws IOException; - - /* ------------------------------------------------------------ */ - void uncheckedAddContent(int b) - { - _buffer.put((byte)b); - } - - /* ------------------------------------------------------------ */ - public void completeUncheckedAddContent() + public final void completeUncheckedAddContent() { if (_noContent) { @@ -374,7 +274,6 @@ } } - /* ------------------------------------------------------------ */ public boolean isBufferFull() { if (_buffer != null && _buffer.space()==0) @@ -387,19 +286,16 @@ return _content!=null && _content.length()>0; } - /* ------------------------------------------------------------ */ - public boolean isWritten() + public final boolean isWritten() { return _contentWritten>0; } - /* ------------------------------------------------------------ */ - public boolean isAllContentWritten() + public final boolean isAllContentWritten() { return _contentLength>=0 && _contentWritten>=_contentLength; } - /* ------------------------------------------------------------ */ public abstract void completeHeader(HttpFields fields, boolean allContentAdded) throws IOException; /* ------------------------------------------------------------ */ @@ -423,12 +319,10 @@ } } - /* ------------------------------------------------------------ */ public abstract int flushBuffer() throws IOException; - /* ------------------------------------------------------------ */ - public void flush(long maxIdleTime) throws IOException + public final void flush(long maxIdleTime) throws IOException { // block until everything is flushed long now=System.currentTimeMillis(); @@ -458,7 +352,7 @@ * @param close True if the connection should be closed * @throws IOException if there is a problem flushing the response */ - public void sendError(int code, String reason, String content, boolean close) throws IOException + public final void sendError(int code, String reason, String content, boolean close) throws IOException { if (close) _persistent=false; @@ -488,19 +382,13 @@ } } - /* ------------------------------------------------------------ */ - /** - * @return Returns the contentWritten. - */ - public long getContentWritten() + public final long getContentWritten() { return _contentWritten; } - - /* ------------------------------------------------------------ */ - public void blockForOutput(long maxIdleTime) throws IOException + public final void blockForOutput(long maxIdleTime) throws IOException { if (_endp.isBlocking()) {