Package org.jgroups.util
Class Headers
- java.lang.Object
-
- org.jgroups.util.Headers
-
public final class Headers extends java.lang.Object
Helper class providing functions to manipulate theMessage.headers
array. 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 synchronized for writes (put(), resize()), but not for reads (size(), get())- Author:
- Bela Ban
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Header[]
copy(Header[] headers)
static <T extends Header>
TgetHeader(Header[] hdrs, short id)
Returns the header associated with an IDstatic <T extends Header>
TgetHeader(Header[] hdrs, short... ids)
Returns the header associated with a set of IDsstatic java.util.Map<java.lang.Short,Header>
getHeaders(Header[] hdrs)
static int
marshalledSize(Header[] hdrs)
static java.lang.String
printHeaders(Header[] hdrs)
static java.lang.String
printObjectHeaders(Header[] hdrs)
static Header[]
putHeader(Header[] headers, short id, Header hdr, boolean replace_if_present)
Adds hdr at the next available slot.static Header[]
resize(Header[] headers)
Increases the capacity of the array and copies the contents of the old into the new arraystatic int
size(Header[] hdrs)
static int
size(Header[] hdrs, short... excluded_ids)
-
-
-
Method Detail
-
getHeader
public static <T extends Header> T getHeader(Header[] hdrs, short id)
Returns the header associated with an ID- Parameters:
id
- The ID- Returns:
-
getHeader
public static <T extends Header> T getHeader(Header[] hdrs, short... ids)
Returns the header associated with a set of IDs- Type Parameters:
T
-- Parameters:
hdrs
-ids
- The IDs- Returns:
-
printHeaders
public static java.lang.String printHeaders(Header[] hdrs)
-
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 or not to overwrite an existing header- Returns:
- A new copy of headers if the array needed to be expanded, or null otherwise
-
resize
public static Header[] resize(Header[] headers)
Increases the capacity of the array and copies the contents of the old into the new array
-
printObjectHeaders
public static java.lang.String printObjectHeaders(Header[] hdrs)
-
marshalledSize
public static int marshalledSize(Header[] hdrs)
-
size
public static int size(Header[] hdrs)
-
size
public static int size(Header[] hdrs, short... excluded_ids)
-
-