Class Transaction
java.lang.Object
com.siperf.commons.data.expirable.ExpirableObject
com.siperf.amistream.connection.both.transcation.Transaction
- All Implemented Interfaces:
Expirable
- Direct Known Subclasses:
ClientAmiTransaction,ServerAmiTransaction
Represents a transaction in the system that can be started, stopped, and tracked.
A transaction has a lifecycle with states such as started, stopped, and completed. It also has a defined expiration time after which it is considered expired if not completed.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnum representing the possible final states of a transaction. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longTimer tracking the execution time of the transactionprotected longTime when the transaction was finished (in milliseconds)protected static final org.slf4j.LoggerLogger for logging transaction-related eventsprotected StringName of the transactionprotected TransactionProcessorProcessor associated with the transactionprotected longTime when the transaction was started (in milliseconds) -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTransaction(Id id) Constructs a newTransactionwith the specified unique identifier. -
Method Summary
Modifier and TypeMethodDescriptionlongGets the execution time of the transaction.longlonggetId()getName()longbooleanisActive()Checks if the transaction is still active (i.e., it has started but not finished).booleanChecks if the transaction has been completed (i.e., it has both started and finished).booleanChecks if the transaction result isTransaction.FinalState.OK.voidstart()Starts the transaction.voidstop(Transaction.FinalState finalState) Stops the transaction with the specified final state.voidstopOk()Stops the transaction with the final state set toTransaction.FinalState.OK.Methods inherited from class com.siperf.commons.data.expirable.ExpirableObject
getCreatedAt, getExpireAt, isExpired, isExpired
-
Field Details
-
log
protected static final org.slf4j.Logger logLogger for logging transaction-related events -
name
Name of the transaction -
startedAt
protected volatile long startedAtTime when the transaction was started (in milliseconds) -
finishedAt
protected volatile long finishedAtTime when the transaction was finished (in milliseconds) -
executionTimer
protected volatile long executionTimerTimer tracking the execution time of the transaction -
processor
Processor associated with the transaction
-
-
Constructor Details
-
Transaction
Constructs a newTransactionwith the specified unique identifier.The transaction is initialized with the current time and a default expiration time.
- Parameters:
id- the unique identifier for this transaction
-
-
Method Details
-
getId
-
getName
-
getStartedAt
public long getStartedAt() -
getFinishedAt
public long getFinishedAt() -
getExecutionTimer
public long getExecutionTimer() -
getFinalState
-
getProcessor
-
start
public void start()Starts the transaction. If the transaction is already started, a log is generated and the start attempt is ignored.The method also initializes the execution timer and invokes the
TransactionProcessor.processStart()method. -
stopOk
public void stopOk()Stops the transaction with the final state set toTransaction.FinalState.OK. -
stop
Stops the transaction with the specified final state.The method ensures that the transaction can only be stopped once and that the final state is set accordingly. It also invokes the
TransactionProcessor.onStop()method.- Parameters:
finalState- the final state of the transaction upon stopping
-
isActive
public boolean isActive()Checks if the transaction is still active (i.e., it has started but not finished).- Returns:
trueif the transaction is active, otherwisefalse
-
getExecutionTime
public long getExecutionTime()Gets the execution time of the transaction.If the transaction has not started or has been finished, appropriate values are returned.
- Returns:
- the execution time in milliseconds, or
0if the transaction has not started
-
isCompleted
public boolean isCompleted()Checks if the transaction has been completed (i.e., it has both started and finished).- Returns:
trueif the transaction is completed, otherwisefalse
-
isResultOK
public boolean isResultOK()Checks if the transaction result isTransaction.FinalState.OK.- Returns:
trueif the final state of the transaction isTransaction.FinalState.OK, otherwisefalse
-