Class Metadata

java.lang.Object
org.axonframework.messaging.core.Metadata
All Implemented Interfaces:
Map<String,String>

public class Metadata extends Object implements Map<String,String>
Represents metadata that is passed along with a payload in a Message.

Typically, the metadata contains information about the message payload that isn't "domain-specific." Examples are originating IP-address or executing User ID.

Since:
2.0.0
Author:
Allard Buijze
  • Constructor Details

    • Metadata

      public Metadata(@Nonnull Map<String,String> items)
      Initializes a Metadata instance with the given items as content.

      Note that the items are copied into the Metadata. Modifications in the Map of items will not reflect is the Metadata, or vice versa. Modifications in the items themselves are reflected in the Metadata.

      Parameters:
      items - The items to populate the Metadata with.
  • Method Details

    • emptyInstance

      public static Metadata emptyInstance()
      Returns an empty Metadata instance.
      Returns:
      An empty Metadata instance.
    • from

      public static Metadata from(@Nullable Map<String,String> metadataEntries)
      Creates a new Metadata instance from the given metadataEntries.

      If metadataEntries is already a Metadata instance, it is returned as is. This makes this method more suitable than the Metadata(java.util.Map) copy-constructor.

      Parameters:
      metadataEntries - The entries to populate the Metadata with.
      Returns:
      A MetadataData instance with the given MetadataEntries as content.
    • with

      public static Metadata with(@Nonnull String key, @Nullable String value)
      Creates a Metadata instance with a single entry from the given key and given value.
      Parameters:
      key - The key for the entry.
      value - The value of the entry.
      Returns:
      A Metadata instance with a single entry.
    • and

      public Metadata and(@Nonnull String key, @Nullable String value)
      Returns a Metadata instance containing the current entries, and the given key and given value.

      If key already existed, it's old value is overwritten with the given value.

      Parameters:
      key - The key for the entry.
      value - The value of the entry.
      Returns:
      A Metadata instance with an additional entry.
    • andIfNotPresent

      public Metadata andIfNotPresent(@Nonnull String key, @Nonnull Supplier<String> value)
      Returns a Metadata instance containing the current entries, and the given key if it was not yet present in this Metadata.

      If the given key already existed, the current value will be used. Otherwise, the value Supplier function will provide the value for key.

      Parameters:
      key - The key for the entry.
      value - A Supplier function which provides the value.
      Returns:
      A Metadata instance with an additional entry.
    • mergedWith

      public Metadata mergedWith(@Nonnull Map<String,String> additionalEntries)
      Returns a Metadata instance containing values of this, combined with the given additionalEntries.

      If any entries have identical keys, the values from the additionalEntries will take precedence.

      Parameters:
      additionalEntries - The additional entries for the new Metadata.
      Returns:
      A Metadata instance containing values of this, combined with the given additionalEntries.
    • withoutKeys

      public Metadata withoutKeys(@Nonnull Set<String> keys)
      Returns a Metadata instance for which the entries with given keys are removed.

      Keys for which there is no assigned value are ignored. This Metadata instance is not influenced by this operation.

      Parameters:
      keys - The keys of the entries to remove.
      Returns:
      A Metadata instance without the given keys.
    • subset

      public Metadata subset(String... keys)
      Returns a Metadata instance containing a subset of the keys in this instance.

      Keys for which there is no assigned value are ignored. This Metadata instance is not influenced by this operation.

      Parameters:
      keys - The keys of the entries to remove.
      Returns:
      A Metadata instance containing the given keys if these were already present.
    • get

      @Nullable public String get(Object key)
      Specified by:
      get in interface Map<String,String>
    • put

      public String put(String key, String value)
      This operation is not supported since Metadata is an immutable object.

      Specified by:
      put in interface Map<String,String>
    • remove

      public String remove(Object key)
      This operation is not supported since Metadata is an immutable object.

      Specified by:
      remove in interface Map<String,String>
    • putAll

      public void putAll(@Nonnull Map<? extends String,? extends String> m)
      This operation is not supported since Metadata is an immutable object.

      Specified by:
      putAll in interface Map<String,String>
    • clear

      public void clear()
      This operation is not supported since Metadata is an immutable object.

      Specified by:
      clear in interface Map<String,String>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<String,String>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<String,String>
    • keySet

      public Set<String> keySet()
      Specified by:
      keySet in interface Map<String,String>
    • values

      public Collection<String> values()
      Specified by:
      values in interface Map<String,String>
    • entrySet

      public Set<Map.Entry<String,String>> entrySet()
      Specified by:
      entrySet in interface Map<String,String>
    • size

      public int size()
      Specified by:
      size in interface Map<String,String>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<String,String>
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Map<String,String>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<String,String>
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object