Package org.jgroups.util
Class Headers
java.lang.Object
org.jgroups.util.Headers
Open addressing based implementation of a hashmap (not supporting the Map interface though) for message
headers. The keys are shorts (IDs) and the values Headers, and they're stored in 2 arrays: an ID array and a headers
array. The indices of the IDs array corespond with the headers array, e.g.
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 not synchronized
IDs: id-1 | id-2 | id-3 | ... | id-n | Headers: hdr-1 | hdr-2 | hdr-3 | ... | hdr-n |The arrays are populated from left to right, and any 0 slots in 'ids' can terminate an interation, or signal empty slots.
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 not synchronized
- Author:
- Bela Ban
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcapacity()copy()getHeader(short id) Returns the header associated with an IDHeader[]short[]intvoidPuts a header given a key into the hashmap.putHeaderIfAbsent(short id, Header hdr) Puts a header given a key into the map, only if the key doesn't exist yetremoveHeader(short id) Deprecated.Use getHeader() instead.intsize()toString()
-
Constructor Details
-
Headers
public Headers(int capacity) -
Headers
-
-
Method Details
-
getRawIDs
public short[] getRawIDs() -
getRawHeaders
-
getHeader
Returns the header associated with an ID- Parameters:
id- The ID- Returns:
-
getHeaders
-
printHeaders
-
putHeader
Puts a header given a key into the hashmap. Overwrites potential existing entry. -
putHeaderIfAbsent
Puts a header given a key into the map, only if the key doesn't exist yet- Parameters:
id-hdr-- Returns:
- the previous value associated with the specified id, or null if there was no mapping for the id. (A null return can also indicate that the map previously associated null with the id, if the implementation supports null values.)
-
removeHeader
Deprecated.Use getHeader() instead. The issue with removing a header is described in http://jira.jboss.com/jira/browse/JGRP-393- Parameters:
id-- Returns:
- the header associated with key
-
copy
-
marshalledSize
public int marshalledSize() -
size
public int size() -
capacity
public int capacity() -
printObjectHeaders
-
toString
-