Class Metadata

  • All Implemented Interfaces:
    Iterable<Object>

    @Experimental("metadata propagation is a SmallRye-specific feature")
    public class Metadata
    extends Object
    implements Iterable<Object>
    Message metadata containers.

    This class stores message metadata that can be related to the transport layer or to the business / application.

    Instances of this class are immutable. Modification operation returned new instances. Contained instances are not constrained, but should be immutable. Only one instance of each class can be stored, as the class is used to retrieve the metadata.

    You can create new instances using the of(Object...) and from(Iterable)methods.

    IMPORTANT: Experimental.

    • Method Detail

      • empty

        public static Metadata empty()
        Returns an empty set of metadata.
        Returns:
        the empty instance
      • of

        public static Metadata of​(Object... metadata)
        Returns an instance of Metadata containing multiple values.
        Parameters:
        metadata - the metadata, must not be null, must not contain null, must not contain multiple objects of the same class
        Returns:
        the new metadata
      • from

        public static Metadata from​(Iterable<Object> metadata)
        Returns an instance of Metadata containing multiple values.
        Parameters:
        metadata - the metadata, must not be null, must not contain null, must not contain multiple objects of the same class
        Returns:
        the new metadata
      • with

        public Metadata with​(Object item)
        Creates a new instance of Metadata with the current entries, plus item. If the current set of metadata contains already an instance of the class of item, the value is replaced in the returned Metadata.
        Parameters:
        item - the metadata to be added, must not be null.
        Returns:
        the new instance of Metadata
      • without

        public Metadata without​(Class<?> clazz)
        Creates a new instance of Metadata with the current entries, minus the entry associated with the given class. If there is no instance of the class in the current set of metadata, the same entries are composing returned instance of metadata.
        Parameters:
        clazz - instance from this class are removed from the metadata.
        Returns:
        the new instance of Metadata
      • copy

        public Metadata copy()
        Copies the current Metadata instance.
        Returns:
        the new instance.
      • get

        public <T> Optional<T> get​(Class<T> clazz)
        Retrieves the metadata associated with given class.
        Parameters:
        clazz - the class of the metadata to retrieve, must not be null
        Returns:
        an Optional containing the associated metadata, empty if none.
      • iterator

        public Iterator<Object> iterator()
        Specified by:
        iterator in interface Iterable<Object>
        Returns:
        an iterator to traverse the set of metadata. This method will never return null.