Class HeaderInformation

java.lang.Object
de.wuespace.telestion.api.message.HeaderInformation
Direct Known Subclasses:
DelayCounterInformation, TimeInformation

public class HeaderInformation extends Object

Description

The HeaderInformation class wraps APIs to attach information to messages to transfer them over the Vert.x event bus.

This implementation extends the already existing functionality of the Vert.x message headers to allow storing and retrieving of other basic data types than String.

Usage

 
 public class MyVerticle extends TelestionVerticle<GenericConfiguration> implements WithEventBus {
     @Override
     public void onStart() {
         var requestInfos = new HeaderInformation()
                 .add("version", 1)
                 .add("log-enabled", true)
                 .add("my-initial-char", 'C').
                 .add("my-coworkers-name", "fussel178");

         request("request-address", "Hello with Info", requestInfos).onSuccess(message -> {
             var responseInfos = HeaderInformation.from(message);

             logger.info("Received version: {}", responseInfos.getInt("version", -1));
             logger.info("Received log enabled state: {}", responseInfos.getBoolean("log-enabled", false));
             logger.info("Received initial char: {}", responseInfos.getChar("my-initial-char", '\0'));
             logger.info("Received coworker name: {}", responseInfos.get("my-coworkers-name", "unset"));
         });
     }
 }
 
 
See Also:
WithEventBus
  • Constructor Details

    • HeaderInformation

      public HeaderInformation()
      Creates a new HeaderInformation object with empty headers.
      See Also:
      MultiMap.caseInsensitiveMultiMap()
    • HeaderInformation

      public HeaderInformation(io.vertx.core.MultiMap headers)
      Creates a new HeaderInformation object with the provided Vert.x headers.
      Parameters:
      headers - the Vert.x headers that you want to wrap inside the HeaderInformation object
    • HeaderInformation

      public HeaderInformation(io.vertx.core.eventbus.Message<?> message)
      Creates a new HeaderInformation object with the headers from the Vert.x message.
      Parameters:
      message - the Vert.x message that contains the Vert.x headers which you want to wrap inside the HeaderInformation object
    • HeaderInformation

      public HeaderInformation(io.vertx.core.eventbus.DeliveryOptions options)
      Creates a new HeaderInformation object with the headers from the DeliveryOptions.
      Parameters:
      options - the DeliveryOptions that contain the Vert.x headers which you want to wrap inside the HeaderInformation object
  • Method Details

    • merge

      public static HeaderInformation merge(HeaderInformation... information)
      Merges an array of HeaderInformation objects into one HeaderInformation object.
      Parameters:
      information - multiple HeaderInformation objects you want to merge
      Returns:
      the merged HeaderInformation object
    • merge

      public static HeaderInformation merge(List<HeaderInformation> list)
      Merges a list of HeaderInformation objects into one HeaderInformation object.
      Parameters:
      list - multiple HeaderInformation objects you want to merge
      Returns:
      the merged HeaderInformation object
    • merge

      public static HeaderInformation merge(Stream<HeaderInformation> stream)
      Merges a stream of HeaderInformation objects into one HeaderInformation object.
      Parameters:
      stream - a stream that contains multiple HeaderInformation objects you want to merge
      Returns:
      the merged HeaderInformation object
    • from

      public static HeaderInformation from(io.vertx.core.MultiMap headers)
      Creates a new HeaderInformation object from existing Vert.x headers.
      Parameters:
      headers - the Vert.x headers you want to wrap into the HeaderInformation object
      Returns:
      a new HeaderInformation object with the wrapped Vert.x headers
    • from

      public static HeaderInformation from(io.vertx.core.eventbus.Message<?> message)
      Creates a new HeaderInformation object from a Vert.x message.
      Parameters:
      message - the Vert.x message that contains the Vert.x headers you want to wrap into the HeaderInformation object
      Returns:
      a new HeaderInformation object with the Vert.x headers from the Vert.x message
    • from

      public static HeaderInformation from(io.vertx.core.eventbus.DeliveryOptions options)
      Creates a new HeaderInformation object from DeliveryOptions.
      Parameters:
      options - DeliveryOptions that contain the Vert.x headers you want to wrap into the HeaderInformation object
      Returns:
      a new HeaderInformation object with the Vert.x headers from the DeliveryOptions
    • getHeaders

      public io.vertx.core.MultiMap getHeaders()
      Returns the wrapped Vert.x headers ready to use in DeliveryOptions or the WithEventBus verticle trait.
      Returns:
      the wrapped Vert.x headers
    • attach

      public io.vertx.core.eventbus.DeliveryOptions attach(io.vertx.core.eventbus.DeliveryOptions options)
      Attaches the wrapped Vert.x headers to the DeliveryOptions and return them again for further usage.
      Parameters:
      options - the DeliveryOptions that receive the wrapped Vert.x headers
      Returns:
      the DeliveryOptions for further usage
    • toOptions

      public io.vertx.core.eventbus.DeliveryOptions toOptions()
      Creates new and empty DeliveryOptions and attaches the wrapped Vert.x headers to them.
      Returns:
      the new DeliveryOptions with the attached Vert.x headers
    • get

      public Optional<String> get(String key)
      Returns the first stored value assigned to the key as String. If no value is assigned to the key, an empty Optional is returned instead.
      Parameters:
      key - the key to which the value is assigned
      Returns:
      the first stored value wrapped inside an Optional for better null type safety
      See Also:
      MultiMap.get(String)
    • get

      public String get(String key, String defaultValue)
      Returns the first stored value assigned to the key as String. If no value is assigned to the key, the default value is used instead.
      Parameters:
      key - the key to which the value is assigned
      defaultValue - the value which is returned if no value is assigned to the key
      Returns:
      the first stored value or the default value if no value is assigned to the key
      See Also:
      MultiMap.get(String)
    • getByte

      public Optional<Byte> getByte(String key)
      Returns the first stored value assigned to the key as Byte. If no value is assigned to the key, an empty Optional is returned instead.
      Parameters:
      key - the key to which the value is assigned
      Returns:
      the first stored value wrapped inside an Optional for better null type safety
      See Also:
      MultiMap.get(String)
    • getByte

      public byte getByte(String key, byte defaultValue)
      Returns the first stored value assigned to the key as Byte. If no value is assigned to the key, the default value is used instead.
      Parameters:
      key - the key to which the value is assigned
      defaultValue - the value which is returned if no value is assigned to the key
      Returns:
      the first stored value or the default value if no value is assigned to the key
      See Also:
      MultiMap.get(String)
    • getInt

      public Optional<Integer> getInt(String key)
      Returns the first stored value assigned to the key as Integer. If no value is assigned to the key, an empty Optional is returned instead.
      Parameters:
      key - the key to which the value is assigned
      Returns:
      the first stored value wrapped inside an Optional for better null type safety
      See Also:
      MultiMap.get(String)
    • getInt

      public int getInt(String key, int defaultValue)
      Returns the first stored value assigned to the key as Integer. If no value is assigned to the key, the default value is used instead.
      Parameters:
      key - the key to which the value is assigned
      defaultValue - the value which is returned if no value is assigned to the key
      Returns:
      the first stored value or the default value if no value is assigned to the key
      See Also:
      MultiMap.get(String)
    • getLong

      public Optional<Long> getLong(String key)
      Returns the first stored value assigned to the key as Long. If no value is assigned to the key, an empty Optional is returned instead.
      Parameters:
      key - the key to which the value is assigned
      Returns:
      the first stored value wrapped inside an Optional for better null type safety
      See Also:
      MultiMap.get(String)
    • getLong

      public long getLong(String key, long defaultValue)
      Returns the first stored value assigned to the key as Long. If no value is assigned to the key, the default value is used instead.
      Parameters:
      key - the key to which the value is assigned
      defaultValue - the value which is returned if no value is assigned to the key
      Returns:
      the first stored value or the default value if no value is assigned to the key
      See Also:
      MultiMap.get(String)
    • getFloat

      public Optional<Float> getFloat(String key)
      Returns the first stored value assigned to the key as Float. If no value is assigned to the key, an empty Optional is returned instead.
      Parameters:
      key - the key to which the value is assigned
      Returns:
      the first stored value wrapped inside an Optional for better null type safety
      See Also:
      MultiMap.get(String)
    • getFloat

      public float getFloat(String key, float defaultValue)
      Returns the first stored value assigned to the key as Float. If no value is assigned to the key, the default value is used instead.
      Parameters:
      key - the key to which the value is assigned
      defaultValue - the value which is returned if no value is assigned to the key
      Returns:
      the first stored value or the default value if no value is assigned to the key
      See Also:
      MultiMap.get(String)
    • getDouble

      public Optional<Double> getDouble(String key)
      Returns the first stored value assigned to the key as Double. If no value is assigned to the key, an empty Optional is returned instead.
      Parameters:
      key - the key to which the value is assigned
      Returns:
      the first stored value wrapped inside an Optional for better null type safety
      See Also:
      MultiMap.get(String)
    • getDouble

      public double getDouble(String key, double defaultValue)
      Returns the first stored value assigned to the key as Double. If no value is assigned to the key, the default value is used instead.
      Parameters:
      key - the key to which the value is assigned
      defaultValue - the value which is returned if no value is assigned to the key
      Returns:
      the first stored value or the default value if no value is assigned to the key
      See Also:
      MultiMap.get(String)
    • getChar

      public Optional<Character> getChar(String key)
      Returns the first stored value assigned to the key as Character. If no value is assigned to the key, an empty Optional is returned instead.
      Parameters:
      key - the key to which the value is assigned
      Returns:
      the first stored value wrapped inside an Optional for better null type safety
      See Also:
      MultiMap.get(String)
    • getChar

      public char getChar(String key, char defaultValue)
      Returns the first stored value assigned to the key as Character. If no value is assigned to the key, the default value is used instead.
      Parameters:
      key - the key to which the value is assigned
      defaultValue - the value which is returned if no value is assigned to the key
      Returns:
      the first stored value or the default value if no value is assigned to the key
      See Also:
      MultiMap.get(String)
    • getBoolean

      public Optional<Boolean> getBoolean(String key)
      Returns the first stored value assigned to the key as Boolean. If no value is assigned to the key, an empty Optional is returned instead.
      Parameters:
      key - the key to which the value is assigned
      Returns:
      the first stored value wrapped inside an Optional for better null type safety
      See Also:
      MultiMap.get(String)
    • getBoolean

      public boolean getBoolean(String key, boolean defaultValue)
      Returns the first stored value assigned to the key as Boolean. If no value is assigned to the key, the default value is used instead.
      Parameters:
      key - the key to which the value is assigned
      defaultValue - the value which is returned if no value is assigned to the key
      Returns:
      the first stored value or the default value if no value is assigned to the key
      See Also:
      MultiMap.get(String)
    • getAll

      public List<String> getAll(String key)
      Returns a list of all stored values assigned to the key as a list of Strings.
      Parameters:
      key - the key to which the values are assigned
      Returns:
      all stored values as a list of Strings
      See Also:
      MultiMap.getAll(String)
    • add

      public HeaderInformation add(String key, String... values)
      Appends multiple String values assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new String values that you want to append to the key
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.add(String, Iterable)
    • add

      public HeaderInformation add(String key, Byte... values)
      Appends multiple Byte values assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Byte values that you want to append to the key
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.add(String, Iterable)
    • add

      public HeaderInformation add(String key, Integer... values)
      Appends multiple Integer values assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Integer values that you want to append to the key
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.add(String, Iterable)
    • add

      public HeaderInformation add(String key, Long... values)
      Appends multiple Long values assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Long values that you want to append to the key
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.add(String, Iterable)
    • add

      public HeaderInformation add(String key, Float... values)
      Appends multiple Float values assigned to the key. Return a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Float values that you want to append to the key
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.add(String, Iterable)
    • add

      public HeaderInformation add(String key, Double... values)
      Appends multiple Double values assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Double values that you want to append to the key
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.add(String, Iterable)
    • add

      public HeaderInformation add(String key, Character... values)
      Appends multiple Character values assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Character values that you want to append to the key
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.add(String, Iterable)
    • add

      public HeaderInformation add(String key, Boolean... values)
      Appends multiple Boolean values assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Boolean values that you want to append to the key
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.add(String, Iterable)
    • addAll

      public HeaderInformation addAll(io.vertx.core.MultiMap headers)
      Appends all values assigned to their keys from the MultiMap to already existing values. Returns a reference to this for fluent design.
      Parameters:
      headers - the MultiMap that contains the new values which you want to append to the existing values
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.addAll(MultiMap)
    • addAll

      public HeaderInformation addAll(Map<String,​String> headers)
      Appends all values assigned to their keys from the Map to already existing values. Returns a reference to this for fluent design.
      Parameters:
      headers - the Map that contains the new values which you want to append to the existing values
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.addAll(Map)
    • addAll

      public HeaderInformation addAll(HeaderInformation information)
      Appends all values assigned to their keys from the HeaderInformation object to already existing values. Returns a reference to this for fluent design.
      Parameters:
      information - the HeaderInformation object that contains the new values which you want to append to the existing values
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.addAll(MultiMap)
    • set

      public HeaderInformation set(String key, String... values)
      Replaces multiple String values with the old allocation assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new String values that you want to replace with the old allocation
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.set(String, Iterable)
    • set

      public HeaderInformation set(String key, Byte... values)
      Replaces multiple Byte values with the old allocation assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Byte values that you want to replace with the old allocation
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.set(String, Iterable)
    • set

      public HeaderInformation set(String key, Integer... values)
      Replaces multiple Integer values with the old allocation assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Integer values that you want to replace with the old allocation
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.set(String, Iterable)
    • set

      public HeaderInformation set(String key, Long... values)
      Replaces multiple Long values with the old allocation assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Long values that you want to replace with the old allocation
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.set(String, Iterable)
    • set

      public HeaderInformation set(String key, Float... values)
      Replaces multiple Float values with the old allocation assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Float values that you want to replace with the old allocation
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.set(String, Iterable)
    • set

      public HeaderInformation set(String key, Double... values)
      Replaces multiple Double values with the old allocation assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Double values that you want to replace with the old allocation
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.set(String, Iterable)
    • set

      public HeaderInformation set(String key, Character... values)
      Replaces multiple Character values with the old allocation assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Character values that you want to replace with the old allocation
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.set(String, Iterable)
    • set

      public HeaderInformation set(String key, Boolean... values)
      Replaces multiple Boolean values with the old allocation assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      values - the new Boolean values that you want to replace with the old allocation
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.set(String, Iterable)
    • setAll

      public HeaderInformation setAll(io.vertx.core.MultiMap headers)
      Replaces all values assigned to their keys with the content of the MultiMap. All remaining values are cleared. It is effectively an entire replacement of the entire MultiMap instance.
      Returns a reference to this for fluent design.
      Parameters:
      headers - the MultiMap that contains the new values assigned to their keys
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.setAll(MultiMap)
    • setAll

      public HeaderInformation setAll(Map<String,​String> headers)
      Replaces all values assigned to their keys with the content of the Map. All remaining values are cleared. It is effectively an entire replacement of the entire MultiMap instance.
      Returns a reference to this for fluent design.
      Parameters:
      headers - the Map that contains the new values assigned to their keys
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.setAll(Map)
    • setAll

      public HeaderInformation setAll(HeaderInformation information)
      Replaces all values assigned to their keys with the content of the HeaderInformation object. All other existing key slots are cleared. It is effectively an entire replacement of the entire MultiMap instance.
      Returns a reference to this for fluent design.
      Parameters:
      information - the HeaderInformation object that contains the new values assigned to their keys
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      setAll(MultiMap)
    • contains

      public boolean contains(String key)
      Returns true, if at least one value is assigned to the key. If no value is assigned, false is returned instead.
      Parameters:
      key - the key to which the value can be assigned
      Returns:
      true, if at least one value is assigned to the key
    • remove

      public HeaderInformation remove(String key)
      Removes all values assigned to the key. Returns a reference to this for fluent design.
      Parameters:
      key - the key to which the values are assigned
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.remove(String)
    • clear

      public HeaderInformation clear()
      Clears all values assigned to their keys. Returns a reference to this for fluent design.
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
      MultiMap.clear()
    • size

      public int size()
      Returns the number of all keys which have values assigned to.
      Returns:
      the number of all keys which have values assigned to
      See Also:
      MultiMap.size()
    • names

      public Set<String> names()
      Returns an immutable set of all keys which have values assigned to.
      Returns:
      an immutable set of all keys which have values assigned to
      See Also:
      MultiMap.names()
    • isEmpty

      public boolean isEmpty()
      Returns true, if the wrapped Vert.x headers have no entries.
      Returns:
      true if the wrapped Vert.x headers have no entries
      See Also:
      MultiMap.isEmpty()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object