Class MetaData

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

public class MetaData extends Object implements Map<String,Object>, Serializable
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
Author:
Allard Buijze
See Also:
  • Constructor Details

    • MetaData

      public MetaData(@Nonnull Map<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,?> 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 items to populate the MetaData with
      Returns:
      a MetaData instance with the given metaDataEntries as content
    • with

      public static MetaData with(@Nonnull String key, @Nullable Object value)
      Creates a MetaData instances with a single entry, with 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 Object value)
      Returns a MetaData instances 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<Object> value)
      Returns a MetaData instances containing the current entries, and the given key if it was not yet present in this MetaData. If key already existed, the current value will be used. Otherwise the 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
    • get

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

      public Object put(String key, Object value)
      This operation is not supported.

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

      public Object remove(Object key)
      This operation is not supported.

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

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

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

      public void clear()
      This operation is not supported.

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

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

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

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

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

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

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

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

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

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

      public MetaData mergedWith(@Nonnull Map<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 with the items with given keys 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.invalid input: '<'
      Parameters:
      keys - The keys of the entries to remove
      Returns:
      a MetaData instance containing the given keys if these were already present
    • readResolve

      protected Object readResolve()
      Java Serialization specification method that will ensure that deserialization will maintain a single instance of empty MetaData.
      Returns:
      the MetaData instance to use after deserialization
    • toString

      public String toString()
      Overrides:
      toString in class Object