Package org.jgroups.util
Class Headers
java.lang.Object
org.jgroups.util.Headers
Helper class providing functions to manipulate the headers array in
BaseMessage.
The headers are stored in the array as follows:
Headers: hdr-1 | hdr-2 | hdr-3 | ... | hdr-n |The arrays are populated from left to right, and any empty slot in 'headers' can terminate an interation (e.g. a getHeader())
It is assumed that we only have a few headers, 3-4 on average. Note that getting a header for a given key and putting a new key/header are operations with O(n) cost, so this implementation is not recommended for a large number of elements.
This class is unsynchronized.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Header[]static <T extends Header>
TReturns the header associated with an IDstatic <T extends Header>
TReturns the header associated with a set of IDsgetHeaders(Header[] hdrs) static intmarshalledSize(Header[] hdrs) static StringprintHeaders(Header[] hdrs) static Header[]Adds hdr at the next available slot.private static HeaderreadHeader(DataInput in) static Header[]readHeaders(DataInput in) static Header[]Increases the capacity of the array and copies the contents of the old into the new arraystatic intprivate static voidwriteHeader(Header hdr, DataOutput out) static voidwriteHeaders(Header[] hdrs, DataOutput out)
-
Field Details
-
RESIZE_INCR
private static final int RESIZE_INCR- See Also:
-
-
Constructor Details
-
Headers
private Headers()
-
-
Method Details
-
getHeader
Returns the header associated with an ID- Parameters:
id- The ID- Returns:
-
getHeader
Returns the header associated with a set of IDs- Type Parameters:
T-- Parameters:
hdrs-ids- The IDs- Returns:
-
getHeaders
-
printHeaders
-
putHeader
public static Header[] putHeader(Header[] headers, short id, Header hdr, boolean replace_if_present) Adds hdr at the next available slot. If none is available, the headers array passed in will be copied and the copy returned- Parameters:
headers- The headers arrayid- The protocol ID of the headerhdr- The headerreplace_if_present- Whether to overwrite an existing header- Returns:
- A new copy of headers if the array needed to be expanded, or null otherwise
-
writeHeaders
- Throws:
IOException
-
readHeaders
- Throws:
IOExceptionClassNotFoundException
-
resize
Increases the capacity of the array and copies the contents of the old into the new array -
copy
-
marshalledSize
-
size
-
writeHeader
- Throws:
IOException
-
readHeader
- Throws:
IOExceptionClassNotFoundException
-