Class TransactionProcessor

java.lang.Object
com.siperf.amistream.connection.both.transcation.TransactionProcessor
Direct Known Subclasses:
ClientTransactionProcessor

public class TransactionProcessor extends Object
This class is responsible for processing transactions and handling various stages of transaction life cycle. It provides mechanisms to start, update, handle errors, and track the execution state of a transaction.

The class processes messages, manages the timer for transaction execution, and detects stalled or erroneous transactions.

  • Field Details

    • log

      protected static final org.slf4j.Logger log
      Logger to log events and warnings related to the transaction.
  • Constructor Details

  • Method Details

    • processStart

      public void processStart()
      Starts the transaction processing.

      This method can be overridden to define specific behavior when the transaction starts.

    • processMessage

      public void processMessage(AmiMessage amiMessage)
      Processes an incoming AMI message.

      This method is used to handle messages related to the transaction.

      Parameters:
      amiMessage - the AmiMessage that will be processed.
    • processUpdate

      public void processUpdate(long ms)
      Updates the transaction processing state based on the time passed since the transaction started.

      The method checks if the transaction is stalled by comparing the elapsed time with the maximum allowed execution time.

      Parameters:
      ms - the current system time in milliseconds.
    • stop

      protected void stop()
      Stops the transaction gracefully with the state Transaction.FinalState.OK.
    • processError

      protected void processError()
      Handles an error condition by stopping the transaction with the state Transaction.FinalState.ERROR.
    • processUnexpectedMessage

      protected void processUnexpectedMessage()
      Handles an unexpected message condition by stopping the transaction with the state Transaction.FinalState.UNEXPECTED_MESSAGE.
    • processStalledTransaction

      public void processStalledTransaction()
      Processes a stalled transaction. The transaction is stopped with the state Transaction.FinalState.STALLED. A warning message is logged indicating that the maximum execution time has been exceeded.
    • processConnectionLost

      public void processConnectionLost()
      Handles a connection lost scenario by stopping the transaction with the state Transaction.FinalState.ERROR.
    • onStop

      protected void onStop()
      Internal method that can be overridden to perform actions when the transaction processing is stopped.

      This method serves as a hook for additional cleanup or finalization tasks.

    • waitForCondition

      public void waitForCondition(boolean waitForCompletion, long timeout)
      Waits for a specific condition to be met in the transaction, such as completion.

      This method blocks until either the condition is met or the timeout expires.

      Parameters:
      waitForCompletion - true if waiting for the transaction to be completed, otherwise false.
      timeout - the maximum time (in milliseconds) to wait for the condition to be met.