Class AbstractMessage

java.lang.Object
io.gravitee.gateway.reactive.api.message.AbstractMessage
All Implemented Interfaces:
Message
Direct Known Subclasses:
DefaultMessage

public abstract class AbstractMessage extends Object implements Message
  • Field Details

    • SOURCE_TIMESTAMP

      public static final String SOURCE_TIMESTAMP
      See Also:
    • timestamp

      protected final long timestamp
    • sourceTimestamp

      protected final long sourceTimestamp
    • metadata

      protected final Map<String,Object> metadata
    • attributes

      protected Map<String,Object> attributes
    • internalAttributes

      protected Map<String,Object> internalAttributes
  • Constructor Details

  • Method Details

    • timestamp

      public long timestamp()
      Description copied from interface: Message
      The timestamp for when this message was created.
      Specified by:
      timestamp in interface Message
      Returns:
      the instant timestamp for the message.
    • metadata

      public Map<String,Object> metadata()
      Description copied from interface: Message
      Get the metadata of the message. Metadata are read-only. They usually come from the source that emits the message and can't be changed.
      Specified by:
      metadata in interface Message
      Returns:
      the metadata of the message or an empty map if the message doesn't have any metadata.
    • attribute

      public <T> T attribute(String name)
      Description copied from interface: Message
      Returns the value of the attribute cast in the expected type T, or null if no attribute for the given name exists.
      Specified by:
      attribute in interface Message
      Type Parameters:
      T - the expected type of the attribute value. Specify Object if you expect value of any type.
      Parameters:
      name - the name of the attribute.
      Returns:
      an Object containing the value of the attribute, or null if the attribute does not exist.
    • attributeAsList

      public <T> List<T> attributeAsList(String name)
      Description copied from interface: Message
      Return the attribute as an immutable List. This method acts differently depending on the type of the attribute's value. Elements of the List are mapped as follows:

      For String:

      • comma separated string are spitted and returned trimmed
      • Parsable JSON Array elements are returned as strings (including objects)
      • if none of the above, the string is simply wrapped

      For Collection:

      • Elements of the collection are wrapped in a new List

      For Array:

      • Each elements of the is wrapped into the returned List

      For any other cases: the value is simply wrapped into the returned List. Notes: One calling Message.attribute(String, Object) with a mutable collection will retrieve an immutable one.

      Specified by:
      attributeAsList in interface Message
      Type Parameters:
      T - the expected type of the attribute value. Specify Object if you expect value of any type.
      Parameters:
      name - the name of the attribute.
      Returns:
      an immutable List with the attribute values.
    • attribute

      public Message attribute(String name, Object value)
      Description copied from interface: Message
      Stores an attribute in this message.
      Specified by:
      attribute in interface Message
      Parameters:
      name - a String specifying the name of the attribute.
      value - the Object to be stored.Returns:
      Returns:
      reference to itself for easily chain calls
    • removeAttribute

      public Message removeAttribute(String name)
      Description copied from interface: Message
      Removes an attribute from this request. This method is not generally needed as attributes only persist as long as the message is being handled.
      Specified by:
      removeAttribute in interface Message
      Parameters:
      name - the name of the attribute to remove.
      Returns:
      reference to itself for easily chain calls
    • attributeNames

      public Set<String> attributeNames()
      Description copied from interface: Message
      Returns a Set containing the names of the attributes available to this message. This method returns an empty Set if the message has no attributes available to it.
      Specified by:
      attributeNames in interface Message
      Returns:
      a set of strings containing the names of the message's attributes.
    • attributes

      public <T> Map<String,T> attributes()
      Description copied from interface: Message
      Get all attributes available.
      Specified by:
      attributes in interface Message
      Type Parameters:
      T - the expected type of the attribute values. Specify Object if you expect values of any types.
      Returns:
      the list of all the attributes.
    • internalAttribute

      public <T> T internalAttribute(String name)
      Specified by:
      internalAttribute in interface Message
    • internalAttribute

      public Message internalAttribute(String name, Object value)
      Description copied from interface: Message
      Stores an internal attribute in this message. Internal attributes can be used to avoid mixin with attributes set by the user during the request processing.. You can safely use internal attribute to temporary store useful objects required during different phases of the execution.
      Specified by:
      internalAttribute in interface Message
      Parameters:
      name - a String specifying the name of the attribute.
      value - the Object to be stored.Returns:
      Returns:
      reference to itself for easily chain calls
    • removeInternalAttribute

      public Message removeInternalAttribute(String name)
      Description copied from interface: Message
      Removes an internal attribute from this request. This method is not generally needed as internal attributes only persist as long as the message is being handled.
      Specified by:
      removeInternalAttribute in interface Message
      Parameters:
      name - the name of the internal attribute to remove.
      Returns:
      reference to itself for easily chain calls.
    • internalAttributeNames

      public Set<String> internalAttributeNames()
      Description copied from interface: Message
      Returns a Set containing the names of the internal attributes available to this message. This method returns an empty Set if the message has no internal attributes available to it.
      Specified by:
      internalAttributeNames in interface Message
      Returns:
      a set of strings containing the names of the message's internal attributes.
    • internalAttributes

      public <T> Map<String,T> internalAttributes()
      Description copied from interface: Message
      Get all internal attributes available. Internal attributes are not intended to be manipulated by end-users. You can safely use internal attribute to temporary store useful objects required during different phases of the execution.
      Specified by:
      internalAttributes in interface Message
      Type Parameters:
      T - the expected type of the internal attribute values. Specify Object if you expect values of any types.
      Returns:
      the list of all the internal attributes.
    • unmodifiableMetadata

      protected static Map<String,Object> unmodifiableMetadata(Map<String,Object> metadata)