Package com.tnsai.communication
Class AcknowledgedMessage
java.lang.Object
com.tnsai.communication.AcknowledgedMessage
A message that requires acknowledgment from the receiver.
Wraps an AgentMessage with acknowledgment metadata including
correlation ID, timeout, and retry configuration.
Usage Example
// Create an acknowledged message
AcknowledgedMessage ackMsg = AcknowledgedMessage.builder()
.message(originalMessage)
.timeout(Duration.ofSeconds(30))
.maxRetries(3)
.build();
// Send with acknowledgment
CompletableFuture<AckResult> future = agent.sendWithAck(ackMsg);
future.thenAccept(result -> {
if (result.isAcknowledged()) {
System.out.println("Message acknowledged!");
}
});
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for AcknowledgedMessage. -
Method Summary
Modifier and TypeMethodDescriptionstatic AcknowledgedMessage.Builderbuilder()Creates a new builder for AcknowledgedMessage.Returns additional acknowledgment metadata.Returns the correlation ID for tracking this acknowledgment.Returns when this message was created.Returns when this message expires (createdAt + timeout).intReturns the maximum number of retries on timeout.Returns the underlying agent message.Returns remaining time before timeout.Returns the acknowledgment timeout duration.booleanChecks if this message has expired (timeout exceeded).static AcknowledgedMessageof(AgentMessage message) Creates an AcknowledgedMessage wrapping the given message with default settings.static AcknowledgedMessageof(AgentMessage message, Duration timeout) Creates an AcknowledgedMessage with a specific timeout.Returns the wrapped message with correlation ID added to metadata.toString()
-
Method Details
-
getCorrelationId
Returns the correlation ID for tracking this acknowledgment.- Returns:
- the correlation ID
-
getMessage
Returns the underlying agent message.- Returns:
- the wrapped message
-
getTimeout
Returns the acknowledgment timeout duration.- Returns:
- the timeout
-
getMaxRetries
public int getMaxRetries()Returns the maximum number of retries on timeout.- Returns:
- max retries (0 means no retries)
-
getCreatedAt
Returns when this message was created.- Returns:
- creation timestamp
-
getExpiresAt
Returns when this message expires (createdAt + timeout).- Returns:
- expiration timestamp
-
getAckSpec
Returns additional acknowledgment metadata.- Returns:
- acknowledgment metadata
-
isExpired
public boolean isExpired()Checks if this message has expired (timeout exceeded).- Returns:
- true if expired
-
getRemainingTime
Returns remaining time before timeout.- Returns:
- remaining duration, or Duration.ZERO if expired
-
builder
Creates a new builder for AcknowledgedMessage.- Returns:
- a new builder
-
of
Creates an AcknowledgedMessage wrapping the given message with default settings.- Parameters:
message- the message to wrap- Returns:
- a new AcknowledgedMessage
-
of
Creates an AcknowledgedMessage with a specific timeout.- Parameters:
message- the message to wraptimeout- the acknowledgment timeout- Returns:
- a new AcknowledgedMessage
-
toMessageWithCorrelation
Returns the wrapped message with correlation ID added to metadata.- Returns:
- message with correlation metadata
-
toString
-