Class AckResult

java.lang.Object
com.tnsai.communication.AckResult

public class AckResult extends Object
Result of an acknowledgment operation.

Contains the acknowledgment status, timing information, and any error details if the acknowledgment failed.

Usage Example


 AckResult result = future.get();

 if (result.isAcknowledged()) {
     System.out.println("Ack received in " + result.getLatency().toMillis() + "ms");
 } else if (result.isTimedOut()) {
     System.out.println("Timeout after " + result.getAttempts() + " attempts");
 } else {
     System.out.println("NACK: " + result.getErrorReason().orElse("Unknown"));
 }
 
  • Method Details

    • acknowledged

      public static AckResult acknowledged(String correlationId, Instant sentAt, AgentMessage ackMessage)
      Creates a successful acknowledgment result.
    • acknowledged

      public static AckResult acknowledged(String correlationId, Instant sentAt, int attempts, AgentMessage ackMessage)
      Creates a successful acknowledgment result with attempt count.
    • negativeAck

      public static AckResult negativeAck(String correlationId, Instant sentAt, String reason, AgentMessage nackMessage)
      Creates a negative acknowledgment result.
    • timeout

      public static AckResult timeout(String correlationId, Instant sentAt, int attempts)
      Creates a timeout result.
    • error

      public static AckResult error(String correlationId, Instant sentAt, String reason)
      Creates an error result.
    • getCorrelationId

      public String getCorrelationId()
      Returns the correlation ID.
    • getStatus

      public AckResult.Status getStatus()
      Returns the acknowledgment status.
    • isAcknowledged

      public boolean isAcknowledged()
      Checks if the message was acknowledged positively.
    • isNegativeAck

      public boolean isNegativeAck()
      Checks if the message was negatively acknowledged.
    • isTimedOut

      public boolean isTimedOut()
      Checks if the acknowledgment timed out.
    • isError

      public boolean isError()
      Checks if there was an error.
    • getSentAt

      public Instant getSentAt()
      Returns the time when the message was sent.
    • getReceivedAt

      public Instant getReceivedAt()
      Returns the time when the acknowledgment was received.
    • getLatency

      public Duration getLatency()
      Returns the latency (time between send and receive).
    • getAttempts

      public int getAttempts()
      Returns the number of attempts made.
    • getErrorReason

      public Optional<String> getErrorReason()
      Returns the error reason if any.
    • getAckMessage

      public Optional<AgentMessage> getAckMessage()
      Returns the acknowledgment message if available.
    • toString

      public String toString()
      Overrides:
      toString in class Object