All Known Implementing Classes:
InvalidMessage, ValidMessage

public sealed interface Message permits ValidMessage, InvalidMessage
A sealed interface representing a message that can be composed using macros and sent to a valid recipient.

Messages are constructed dynamically using the fluent API exposed by MessageBuilder, and are resolved at runtime using a combination of a message template, a macro object map, and a validated Recipient.

The Message interface has two implementations:

  • ValidMessage – A fully-constructed message with a resolvable template and a valid recipient
  • InvalidMessage – A placeholder or sentinel used when the message cannot be composed

Fluent Macro Assignment

Macros can be added to the message using the setMacro methods. These allow rich contextual data such as strings, durations, quantities, and domain objects to be bound to placeholders in the final rendered message.

Sending

Once composed, the send() method dispatches the message to the resolved recipient, if one is available and valid.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static Message
    Returns an empty Message instance that performs no action when sent.
    Returns the RecordKey identifying the message template used in composition.
    Returns the MacroObjectMap of macro values bound to this message.
    Returns the Recipient.Sendable to whom the message will be sent.
    void
    Sends the composed message to the resolved recipient, if valid.
    <K extends Enum<K>, V>
    Message
    setMacro(int quantity, K macro, V value)
    Associates a macro key with a value and explicit quantity, useful for pluralization or contextual substitution that depends on numeric counts.
    <K extends Enum<K>>
    Message
    setMacro(K macro, Duration duration, ChronoUnit precision)
    Associates a duration with the given macro key, using a defined precision.
    <K extends Enum<K>, V>
    Message
    setMacro(K macro, V value)
    Associates a macro key with a value for later substitution during message rendering.
  • Method Details

    • setMacro

      <K extends Enum<K>, V> Message setMacro(K macro, V value)
      Associates a macro key with a value for later substitution during message rendering.
      Type Parameters:
      K - the enum type of the macro
      V - the value type
      Parameters:
      macro - the macro key to assign
      value - the value to associate with the macro
      Returns:
      the same Message instance, for fluent chaining
    • setMacro

      <K extends Enum<K>, V> Message setMacro(int quantity, K macro, V value)
      Associates a macro key with a value and explicit quantity, useful for pluralization or contextual substitution that depends on numeric counts.
      Type Parameters:
      K - the enum type of the macro
      V - the value type
      Parameters:
      quantity - the quantity associated with the value
      macro - the macro key
      value - the object to associate
      Returns:
      the same Message instance, for fluent chaining
    • setMacro

      <K extends Enum<K>> Message setMacro(K macro, Duration duration, ChronoUnit precision)
      Associates a duration with the given macro key, using a defined precision.
      Type Parameters:
      K - the enum type of the macro
      Parameters:
      macro - the macro key
      duration - the Duration to be formatted and resolved
      precision - the ChronoUnit to control formatting granularity
      Returns:
      the same Message instance, for fluent chaining
    • send

      void send()
      Sends the composed message to the resolved recipient, if valid.

      No-op if the message is invalid or the recipient is missing or unsupported.

    • getMessageKey

      RecordKey getMessageKey()
      Returns the RecordKey identifying the message template used in composition.
      Returns:
      the message key
    • getRecipient

      Recipient.Sendable getRecipient()
      Returns the Recipient.Sendable to whom the message will be sent.
      Returns:
      the message recipient
    • getObjectMap

      MacroObjectMap getObjectMap()
      Returns the MacroObjectMap of macro values bound to this message.
      Returns:
      the macro object map
    • empty

      static Message empty()
      Returns an empty Message instance that performs no action when sent. Used as a fallback when message construction fails.
      Returns:
      an InvalidMessage representing an inert or failed message