Class TransactionProcessor
java.lang.Object
com.siperf.amistream.connection.both.transcation.TransactionProcessor
- Direct Known Subclasses:
ClientTransactionProcessor
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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.slf4j.LoggerLogger to log events and warnings related to the transaction. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTransactionProcessor(Transaction transaction) Constructs a new instance ofTransactionProcessor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidonStop()Internal method that can be overridden to perform actions when the transaction processing is stopped.voidHandles a connection lost scenario by stopping the transaction with the stateTransaction.FinalState.ERROR.protected voidHandles an error condition by stopping the transaction with the stateTransaction.FinalState.ERROR.voidprocessMessage(AmiMessage amiMessage) Processes an incoming AMI message.voidProcesses a stalled transaction.voidStarts the transaction processing.protected voidHandles an unexpected message condition by stopping the transaction with the stateTransaction.FinalState.UNEXPECTED_MESSAGE.voidprocessUpdate(long ms) Updates the transaction processing state based on the time passed since the transaction started.protected voidstop()Stops the transaction gracefully with the stateTransaction.FinalState.OK.voidwaitForCondition(boolean waitForCompletion, long timeout) Waits for a specific condition to be met in the transaction, such as completion.
-
Field Details
-
log
protected static final org.slf4j.Logger logLogger to log events and warnings related to the transaction.
-
-
Constructor Details
-
TransactionProcessor
Constructs a new instance ofTransactionProcessor.- Parameters:
transaction- theTransactionto be processed by this processor.
-
-
Method Details
-
processStart
public void processStart()Starts the transaction processing.This method can be overridden to define specific behavior when the transaction starts.
-
processMessage
Processes an incoming AMI message.This method is used to handle messages related to the transaction.
- Parameters:
amiMessage- theAmiMessagethat 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 stateTransaction.FinalState.OK. -
processError
protected void processError()Handles an error condition by stopping the transaction with the stateTransaction.FinalState.ERROR. -
processUnexpectedMessage
protected void processUnexpectedMessage()Handles an unexpected message condition by stopping the transaction with the stateTransaction.FinalState.UNEXPECTED_MESSAGE. -
processStalledTransaction
public void processStalledTransaction()Processes a stalled transaction. The transaction is stopped with the stateTransaction.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 stateTransaction.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-trueif waiting for the transaction to be completed, otherwisefalse.timeout- the maximum time (in milliseconds) to wait for the condition to be met.
-