Class PreparedTxnState

java.lang.Object
org.apache.kafka.clients.producer.PreparedTxnState

public class PreparedTxnState extends Object
Class containing the state of a transaction after it has been prepared for a two-phase commit. This state includes the producer ID and epoch, which are needed to commit or abort the transaction.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new empty PreparedTxnState
    PreparedTxnState(String serializedState)
    Creates a new PreparedTxnState from a serialized string representation
  • Method Summary

    Modifier and Type
    Method
    Description
    short
     
    boolean
     
    int
     
    boolean
    Checks if this preparedTxnState represents an initialized transaction with a valid producer ID that is not -1 (the uninitialized value).
    long
     
    Returns a serialized string representation of this transaction state.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PreparedTxnState

      public PreparedTxnState()
      Creates a new empty PreparedTxnState
    • PreparedTxnState

      public PreparedTxnState(String serializedState)
      Creates a new PreparedTxnState from a serialized string representation
      Parameters:
      serializedState - The serialized string to deserialize.
      Throws:
      IllegalArgumentException - if the serialized string is not in the expected format
  • Method Details

    • producerId

      public long producerId()
    • epoch

      public short epoch()
    • hasTransaction

      public boolean hasTransaction()
      Checks if this preparedTxnState represents an initialized transaction with a valid producer ID that is not -1 (the uninitialized value).
      Returns:
      true if the state has an initialized transaction, false otherwise.
    • toString

      public String toString()
      Returns a serialized string representation of this transaction state. The format is "producerId:epoch" for an initialized state, or an empty string for an uninitialized state (where producerId and epoch are both -1).
      Overrides:
      toString in class Object
      Returns:
      a serialized string representation
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object