Class MysqlBalanceUpdater

java.lang.Object
java.lang.Thread
com.reve.balancemanager.db.MysqlBalanceUpdater
All Implemented Interfaces:
Runnable

public class MysqlBalanceUpdater extends Thread
Updates client balance in mysql periodically
  • Constructor Details

    • MysqlBalanceUpdater

      public MysqlBalanceUpdater(boolean redundancy, BalanceManager balanceManager)
      Create the instance
      Parameters:
      redundancy - If redundancy is running for this BalanceManager then mysql balance update will be as fast as possible, without any sleep. otherwise, mysql update will be periodical
      balanceManager - the instance of BalanceManager who owns this thread.
  • Method Details

    • run

      public void run()
      Continuously updates mysql balance without any sleep if some data are available to be updated in mysql, and they are successfully updated then it will not sleep and try again. This case defines that SBC is now handling calls, so mysql balance should be updated as early as possible. So no sleep for this case. If fails to update mysql balance or no data is available to be updated in mysql it will sleep for sometimes and try again.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • addOrgBilledAmount

      public void addOrgBilledAmount(long orgClientID, double billedAmount)
      Adds billed amount to total bill for corresponding account id
      Parameters:
      orgClientID - originating client id for which bill should be added
      billedAmount - billed amount that should be added
    • addTerBilledAmount

      public double addTerBilledAmount(long terClientID, double billedAmount)
      Adds billed amount to total billed amount for corresponding account id
      Parameters:
      terClientID - terminating account id for which bill has happened
      billedAmount - billed amount that should be added in total bill
      Returns:
      the total amount available in the map for this client after adding the given amount.
    • immediateDatabaseBalanceUpdate

      public void immediateDatabaseBalanceUpdate(long accountID)
      When this account maintenance is needed and mysql balance need to be updated immediately, this method does that
      Parameters:
      accountID - for which balance should be updated in mysql immediately
    • getMysqlBalance

      public double getMysqlBalance(long accountID)
    • shutDown

      public void shutDown()
      Shutting down this thread. This call is important at process shutdown as all clients balance will be updated in mysql immediately. This thread should be shut down when all other billing thread are already shut down. Otherwise, balance mismatch may occur