Class Headers

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

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

  • Constructor Details

    • Headers

      private Headers()
  • Method Details

    • 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:
    • getHeaders

      public static Map<Short,Header> getHeaders(Header[] hdrs)
    • printHeaders

      public static 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 array
      id - The protocol ID of the header
      hdr - The header
      replace_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

      public static void writeHeaders(Header[] hdrs, DataOutput out) throws IOException
      Throws:
      IOException
    • readHeaders

      public static Header[] readHeaders(DataInput in) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • resize

      public static Header[] resize(Header[] headers)
      Increases the capacity of the array and copies the contents of the old into the new array
    • copy

      public static Header[] copy(Header[] headers)
    • marshalledSize

      public static int marshalledSize(Header[] hdrs)
    • size

      public static int size(Header[] hdrs)
    • writeHeader

      private static void writeHeader(Header hdr, DataOutput out) throws IOException
      Throws:
      IOException
    • readHeader

      private static Header readHeader(DataInput in) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException