java.lang.Object
org.glassfish.grizzly.http.util.MimeHeaders
Memory-efficient repository for Mime Headers. When the object is recycled, it will keep the allocated headers[] and
all the MimeHeaderField - no GC is generated.
For input headers it is possible to use the DataChunk for Fields - so no GC will be generated.
The only garbage is generated when using the String for header names/values - this can't be avoided when the servlet
calls header methods, but is easy to avoid inside tomcat. The goal is to use _only_ DataChunk-based Fields, and
reduce to 0 the memory overhead of tomcat.
TODO: XXX one-buffer parsing - for HTTP ( other protocols don't need that ) XXX remove unused methods XXX External
enumerations, with 0 GC. XXX use HeaderName ID
- Author:
- [email protected], James Todd [[email protected]], Costin Manolache, kevin seguin
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Initial size - should be == average number of headers per request XXX make it configurable ( fine-tuning of web-apps )protected int
static final int
static final int
static DataChunk
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddValue
(byte[] buffer, int startN, int len) Create a new named header using un-translated byte[].Create a new named header , return the MessageBytes container for the new valueaddValue
(org.glassfish.grizzly.Buffer buffer, int startN, int len) Create a new named header using un-translated Buffer.Create a new named header , return the MessageBytes container for the new valuevoid
clear()
Clears all header fields.boolean
boolean
void
copyFrom
(MimeHeaders source) int
getName
(int n) Returns the Nth header name, or null if there is no such header.getValue
(int n) Returns the Nth header value, or null if there is no such header.Finds and returns a header field with the given name.Finds and returns a header field with the given name.int
Find the index of a header with the given name.int
Find the index of a header with the given name.boolean
isSerialized
(int n) Get the header's "serialized" flag.void
mark()
names()
Returns an enumeration of strings representing the header field names.void
recycle()
Clears all header fields.void
removeHeader
(String name) Removes a header field with the specified name.void
removeHeader
(String name, String str) Removes the headers with the given name whose values contain the given string.void
removeHeader
(Header header) void
removeHeaderMatches
(String name, String regex) Removes the headers with the given name whose values contain the given string.void
removeHeaderMatches
(Header header, String regex) Removes the headers with the given name whose values contain the given string.void
setMaxNumHeaders
(int maxNumHeaders) boolean
setSerialized
(int n, boolean newValue) Set the header's "serialized" flag.Allow "set" operations - return a DataChunk container for the header value ( existing header or new if this .Allow "set" operations - return a DataChunk container for the header value ( existing header or new if this .int
size()
Returns the current number of header fields.toString()
EXPENSIVE!!! only for debugging.int
trailerValues
(String name) trailerValues
(Header name)
-
Field Details
-
MAX_NUM_HEADERS_UNBOUNDED
public static final int MAX_NUM_HEADERS_UNBOUNDED- See Also:
-
MAX_NUM_HEADERS_DEFAULT
public static final int MAX_NUM_HEADERS_DEFAULT- See Also:
-
DEFAULT_HEADER_SIZE
public static final int DEFAULT_HEADER_SIZEInitial size - should be == average number of headers per request XXX make it configurable ( fine-tuning of web-apps )- See Also:
-
NOOP_CHUNK
-
mark
protected int mark
-
-
Constructor Details
-
MimeHeaders
public MimeHeaders()Creates a new MimeHeaders object using a default buffer size.
-
-
Method Details
-
mark
public void mark() -
recycle
public void recycle()Clears all header fields. -
clear
public void clear()Clears all header fields. -
toString
EXPENSIVE!!! only for debugging. -
copyFrom
-
size
public int size()Returns the current number of header fields. -
trailerSize
public int trailerSize() -
getName
Returns the Nth header name, or null if there is no such header. This may be used to iterate through all header fields. -
getValue
Returns the Nth header value, or null if there is no such header. This may be used to iterate through all header fields. -
isSerialized
public boolean isSerialized(int n) Get the header's "serialized" flag.- Parameters:
n
- the header index- Returns:
- the header's "serialized" flag value.
-
setSerialized
public boolean setSerialized(int n, boolean newValue) Set the header's "serialized" flag.- Parameters:
n
- the header indexnewValue
- the new value- Returns:
- the old header "serialized" flag value.
-
indexOf
Find the index of a header with the given name. -
indexOf
Find the index of a header with the given name. -
contains
-
contains
-
names
Returns an enumeration of strings representing the header field names. Field names may appear multiple times in this enumeration, indicating that multiple fields with that name exist in this header. -
trailerNames
-
values
-
values
-
trailerValues
-
trailerValues
-
addValue
Create a new named header , return the MessageBytes container for the new value -
addValue
Create a new named header , return the MessageBytes container for the new value -
addValue
Create a new named header using un-translated byte[]. The conversion to chars can be delayed until encoding is known. -
addValue
Create a new named header using un-translated Buffer. The conversion to chars can be delayed until encoding is known. -
setValue
Allow "set" operations - return a DataChunk container for the header value ( existing header or new if this . -
setValue
Allow "set" operations - return a DataChunk container for the header value ( existing header or new if this . -
getValue
Finds and returns a header field with the given name. If no such field exists, null is returned. If more than one such field is in the header, an arbitrary one is returned. -
getValue
Finds and returns a header field with the given name. If no such field exists, null is returned. If more than one such field is in the header, an arbitrary one is returned. -
getHeader
-
getHeader
-
removeHeader
Removes a header field with the specified name. Does nothing if such a field could not be found.- Parameters:
name
- the name of the header field to be removed
-
removeHeader
-
removeHeader
Removes the headers with the given name whose values contain the given string.- Parameters:
name
- The name of the headers to be removedstr
- The string to check the header values against
-
removeHeaderMatches
Removes the headers with the given name whose values contain the given string.- Parameters:
name
- The name of the headers to be removedregex
- The regex string to check the header values against
-
removeHeaderMatches
Removes the headers with the given name whose values contain the given string.- Parameters:
header
- The name of theHeader
s to be removedregex
- The regex string to check the header values against
-
setMaxNumHeaders
public void setMaxNumHeaders(int maxNumHeaders) -
getMaxNumHeaders
public int getMaxNumHeaders()
-