Class Metadata

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

public class Metadata extends Object implements Map<String,@Nullable 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(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,@Nullable 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(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(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(String key, 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(Map<String,@Nullable 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(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

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

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

      Specified by:
      put in interface Map<String,@Nullable 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,@Nullable String>
    • putAll

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

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

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

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

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

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

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

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

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

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

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

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

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

      public String toString()
      Overrides:
      toString in class Object