Interface Message
- All Known Implementing Classes:
InvalidMessage
,ValidMessage
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 recipientInvalidMessage
– A placeholder or sentinel used when the message cannot be composed
Fluent Macro Assignment
Macros can be added to the message using thesetMacro
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, thesend()
method dispatches the message to the resolved recipient,
if one is available and valid.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Message
empty()
Returns an emptyMessage
instance that performs no action when sent.Returns theRecordKey
identifying the message template used in composition.Returns theMacroObjectMap
of macro values bound to this message.Returns theRecipient.Sendable
to whom the message will be sent.void
send()
Sends the composed message to the resolved recipient, if valid.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.setMacro
(K macro, Duration duration, ChronoUnit precision) Associates a duration with the given macro key, using a defined precision.setMacro
(K macro, V value) Associates a macro key with a value for later substitution during message rendering.
-
Method Details
-
setMacro
Associates a macro key with a value for later substitution during message rendering.- Type Parameters:
K
- the enum type of the macroV
- the value type- Parameters:
macro
- the macro key to assignvalue
- the value to associate with the macro- Returns:
- the same
Message
instance, for fluent chaining
-
setMacro
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 macroV
- the value type- Parameters:
quantity
- the quantity associated with the valuemacro
- the macro keyvalue
- the object to associate- Returns:
- the same
Message
instance, for fluent chaining
-
setMacro
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 keyduration
- theDuration
to be formatted and resolvedprecision
- theChronoUnit
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 theRecordKey
identifying the message template used in composition.- Returns:
- the message key
-
getRecipient
Recipient.Sendable getRecipient()Returns theRecipient.Sendable
to whom the message will be sent.- Returns:
- the message recipient
-
getObjectMap
MacroObjectMap getObjectMap()Returns theMacroObjectMap
of macro values bound to this message.- Returns:
- the macro object map
-
empty
Returns an emptyMessage
instance that performs no action when sent. Used as a fallback when message construction fails.- Returns:
- an
InvalidMessage
representing an inert or failed message
-