org.mortbay.jetty
Class AbstractGenerator
java.lang.Object
org.mortbay.jetty.AbstractGenerator
- All Implemented Interfaces:
- Generator
- Direct Known Subclasses:
- HttpGenerator
public abstract class AbstractGenerator
- extends Object
- implements Generator
Abstract Generator. Builds HTTP Messages.
Currently this class uses a system parameter "jetty.direct.writers" to control
two optional writer to byte conversions. buffer.writers=true will probably be
faster, but will consume more memory. This option is just for testing and tuning.
- Author:
- gregw
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
STATE_HEADER
public static final int STATE_HEADER
- See Also:
- Constant Field Values
STATE_CONTENT
public static final int STATE_CONTENT
- See Also:
- Constant Field Values
STATE_FLUSHING
public static final int STATE_FLUSHING
- See Also:
- Constant Field Values
STATE_END
public static final int STATE_END
- See Also:
- Constant Field Values
_state
protected int _state
_status
protected int _status
_version
protected int _version
_reason
protected Buffer _reason
_method
protected Buffer _method
_uri
protected String _uri
_contentWritten
protected long _contentWritten
_contentLength
protected long _contentLength
_last
protected boolean _last
_head
protected boolean _head
_noContent
protected boolean _noContent
_close
protected boolean _close
_buffers
protected Buffers _buffers
_endp
protected EndPoint _endp
_headerBufferSize
protected int _headerBufferSize
_contentBufferSize
protected int _contentBufferSize
_header
protected Buffer _header
_buffer
protected Buffer _buffer
_content
protected Buffer _content
AbstractGenerator
public AbstractGenerator(Buffers buffers,
EndPoint io,
int headerBufferSize,
int contentBufferSize)
- Constructor.
- Parameters:
buffers
- buffer poolheaderBufferSize
- Size of the buffer to allocate for HTTP headercontentBufferSize
- Size of the buffer to allocate for HTTP content
getReasonBuffer
protected static Buffer getReasonBuffer(int code)
getReason
public static String getReason(int code)
reset
public void reset(boolean returnBuffers)
- Specified by:
reset
in interface Generator
resetBuffer
public void resetBuffer()
- Specified by:
resetBuffer
in interface Generator
getContentBufferSize
public int getContentBufferSize()
- Specified by:
getContentBufferSize
in interface Generator
- Returns:
- Returns the contentBufferSize.
increaseContentBufferSize
public void increaseContentBufferSize(int contentBufferSize)
- Specified by:
increaseContentBufferSize
in interface Generator
- Parameters:
contentBufferSize
- The contentBufferSize to set.
getUncheckedBuffer
public Buffer getUncheckedBuffer()
getSendServerVersion
public boolean getSendServerVersion()
setSendServerVersion
public void setSendServerVersion(boolean sendServerVersion)
- Specified by:
setSendServerVersion
in interface Generator
getState
public int getState()
isState
public boolean isState(int state)
isComplete
public boolean isComplete()
- Specified by:
isComplete
in interface Generator
isIdle
public boolean isIdle()
- Specified by:
isIdle
in interface Generator
isCommitted
public boolean isCommitted()
- Specified by:
isCommitted
in interface Generator
isHead
public boolean isHead()
- Returns:
- Returns the head.
setContentLength
public void setContentLength(long value)
- Specified by:
setContentLength
in interface Generator
setHead
public void setHead(boolean head)
- Specified by:
setHead
in interface Generator
- Parameters:
head
- The head to set.
isPersistent
public boolean isPersistent()
- Specified by:
isPersistent
in interface Generator
- Returns:
false
if the connection should be closed after a request has been read,
true
if it should be used for additional requests.
setPersistent
public void setPersistent(boolean persistent)
setVersion
public void setVersion(int version)
- Specified by:
setVersion
in interface Generator
- Parameters:
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).
getVersion
public int getVersion()
setRequest
public void setRequest(String method,
String uri)
- Specified by:
setRequest
in interface Generator
setResponse
public void setResponse(int status,
String reason)
- Specified by:
setResponse
in interface Generator
- Parameters:
status
- The status code to send.reason
- the status message to send.
prepareUncheckedAddContent
protected abstract int prepareUncheckedAddContent()
throws IOException
- Prepare buffer for unchecked writes.
Prepare the generator buffer to receive unchecked writes
- Returns:
- the available space in the buffer.
- Throws:
IOException
isBufferFull
public boolean isBufferFull()
- Specified by:
isBufferFull
in interface Generator
isContentWritten
public boolean isContentWritten()
completeHeader
public abstract void completeHeader(HttpFields fields,
boolean allContentAdded)
throws IOException
- Specified by:
completeHeader
in interface Generator
- Throws:
IOException
complete
public void complete()
throws IOException
- Complete the message.
- Specified by:
complete
in interface Generator
- Throws:
IOException
flush
public abstract long flush()
throws IOException
- Specified by:
flush
in interface Generator
- Throws:
IOException
sendError
public void sendError(int code,
String reason,
String content,
boolean close)
throws IOException
- Utility method to send an error response. If the builder is not committed, this call is
equivalent to a setResponse, addcontent and complete call.
- Specified by:
sendError
in interface Generator
- Parameters:
code
- reason
- content
- close
-
- Throws:
IOException
getContentWritten
public long getContentWritten()
- Specified by:
getContentWritten
in interface Generator
- Returns:
- Returns the contentWritten.