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 strings and the values Headers, and they're stored in an array in the format key-1 | header-1 | key-2 | header-2. The array is populated from left to right, so any null slots 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
Version:
$Id: Headers.java,v 1.11.2.5 2008/07/31 12:55:23 belaban Exp $
Author:
Bela Ban
  • Constructor Details

    • Headers

      public Headers(int initial_capacity)
    • Headers

      public Headers(Headers hdrs)
  • Method Details

    • getRawData

      public Object[] getRawData()
    • getHeader

      public Header getHeader(String key)
      Returns the header associated with key
      Parameters:
      key -
      Returns:
    • getHeaders

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

      public String printHeaders()
    • putHeader

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

      public Header putHeaderIfAbsent(String key, Header hdr)
      Puts a header given a key into the map, only if the key doesn't exist yet
      Parameters:
      key -
      hdr -
      Returns:
      the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)
    • removeHeader

      public Header removeHeader(String key)
      Deprecated.
      Use getHeader() instead. The issue with removing a header is described in http://jira.jboss.com/jira/browse/JGRP-393
      Parameters:
      key -
      Returns:
      the header assoaicted 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