Class TransactionsTable

java.lang.Object
com.siperf.amistream.connection.both.transcation.TransactionsTable

public class TransactionsTable extends Object
A class that manages a collection of 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 Details

    • TransactionsTable

      public TransactionsTable()
      Constructs a new TransactionsTable instance 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

      public void addTransaction(Transaction transaction)
      Adds a new transaction to the table.
      Parameters:
      transaction - the Transaction to be added.
    • setShadingTransaction

      public Transaction setShadingTransaction(Transaction transaction)
      Sets the shading transaction, which is a special transaction to be processed separately.
      Parameters:
      transaction - the Transaction to be set as the shading transaction.
      Returns:
      the same shading Transaction object that was passed as the parameter.
    • getShadingTransaction

      public Transaction getShadingTransaction()
      Retrieves the currently set shading transaction, if any.
      Returns:
      the current shading Transaction, or null if no shading transaction is set.
    • getTransactionToProcess

      public Transaction getTransactionToProcess(AmiMessage amiMessage)
      Retrieves the transaction to process based on the given AmiMessage.

      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 the AmiMessage.

      Parameters:
      amiMessage - the AmiMessage containing the action ID to find the corresponding transaction.
      Returns:
      the Transaction to process, or null if no matching transaction is found.
    • getTransactionsToUpdate

      @Deprecated public Collection<Transaction> getTransactionsToUpdate()
      Deprecated.
      Use update(long, ExpirableObjectIterationTask) instead. Retrieves all transactions that need to be updated.
      Returns:
      a collection of Transaction objects that need to be updated.
    • removeTransaction

      public void removeTransaction(Transaction transaction)
      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 - the Transaction to 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 Transaction objects that have been removed, or null if none were expired.