Class Headers

java.lang.Object
org.jgroups.util.Headers

public class Headers extends Object
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.
 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 Details

    • Headers

      public Headers(int capacity)
    • Headers

      public Headers(Headers other)
  • Method Details

    • getRawIDs

      public short[] getRawIDs()
    • getRawHeaders

      public Header[] getRawHeaders()
    • getHeader

      public Header getHeader(short id)
      Returns the header associated with an ID
      Parameters:
      id - The ID
      Returns:
    • getHeaders

      public Map<Short,Header> getHeaders()
    • printHeaders

      public String printHeaders()
    • putHeader

      public void putHeader(short id, Header hdr)
      Puts a header given a key into the hashmap. Overwrites potential existing entry.
    • putHeaderIfAbsent

      public Header putHeaderIfAbsent(short id, Header hdr)
      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

      public Header removeHeader(short id)
      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

      public Headers copy()
    • marshalledSize

      public int marshalledSize()
    • size

      public int size()
    • capacity

      public int capacity()
    • printObjectHeaders

      public String printObjectHeaders()
    • toString

      public String toString()
      Overrides:
      toString in class Object