Class TransactionsTable
Transaction objects, providing functionality
to add, remove, retrieve, and update transactions. It also allows handling shading transactions
and managing expired transactions with automatic cleanup.
This class internally uses an ExpirableObjectsMap to store transactions, and provides
methods to handle adding, removing, and processing transactions as well as setting and getting
a shading transaction.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTransaction(Transaction transaction) Adds a new transaction to the table.Retrieves the currently set shading transaction, if any.Deprecated.getTransactionToProcess(AmiMessage amiMessage) Retrieves the transaction to process based on the givenAmiMessage.voidremoveTransaction(Transaction transaction) Removes a specified transaction from the table.setShadingTransaction(Transaction transaction) Sets the shading transaction, which is a special transaction to be processed separately.update(long timestamp, ExpirableObjectIterationTask<Transaction> iterationTask) Updates all transactions and removes expired transactions based on the given timestamp.
-
Constructor Details
-
TransactionsTable
public TransactionsTable()Constructs a newTransactionsTableinstance with the default settings.The constructor initializes the internal map with a basket size of 1024, an increment of 256 for basket size, and a rearrange factor of 0.8f.
-
-
Method Details
-
addTransaction
Adds a new transaction to the table.- Parameters:
transaction- theTransactionto be added.
-
setShadingTransaction
Sets the shading transaction, which is a special transaction to be processed separately.- Parameters:
transaction- theTransactionto be set as the shading transaction.- Returns:
- the same shading
Transactionobject that was passed as the parameter.
-
getShadingTransaction
Retrieves the currently set shading transaction, if any.- Returns:
- the current shading
Transaction, ornullif no shading transaction is set.
-
getTransactionToProcess
Retrieves the transaction to process based on the givenAmiMessage.This method checks whether there is a shading transaction set; if so, it returns that transaction. If the shading transaction is
null, it attempts to find the transaction by its action ID from theAmiMessage.- Parameters:
amiMessage- theAmiMessagecontaining the action ID to find the corresponding transaction.- Returns:
- the
Transactionto process, ornullif no matching transaction is found.
-
getTransactionsToUpdate
Deprecated.Useupdate(long, ExpirableObjectIterationTask)instead. Retrieves all transactions that need to be updated.- Returns:
- a collection of
Transactionobjects that need to be updated.
-
removeTransaction
Removes a specified transaction from the table.If the given transaction is the shading transaction, it will be set to
null. Otherwise, the transaction is removed from the internal map of transactions.- Parameters:
transaction- theTransactionto remove from the table.
-
update
public List<Transaction> update(long timestamp, ExpirableObjectIterationTask<Transaction> iterationTask) Updates all transactions and removes expired transactions based on the given timestamp.The method will iterate over all transactions and apply the specified iteration task. It will also handle removing any expired transactions from the internal map.
- Parameters:
timestamp- the current timestamp to use for updating transactions.iterationTask- the task to be applied to each transaction during the update.- Returns:
- a list of expired
Transactionobjects that have been removed, ornullif none were expired.
-
update(long, ExpirableObjectIterationTask)instead.