Package com.reve.balancemanager.db
Class MysqlBalanceUpdater
java.lang.Object
java.lang.Thread
com.reve.balancemanager.db.MysqlBalanceUpdater
- All Implemented Interfaces:
Runnable
Updates client balance in mysql periodically
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionMysqlBalanceUpdater(boolean redundancy, BalanceManager balanceManager) Create the instance -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOrgBilledAmount(long orgClientID, double billedAmount) Adds billed amount to total bill for corresponding account iddoubleaddTerBilledAmount(long terClientID, double billedAmount) Adds billed amount to total billed amount for corresponding account iddoublegetMysqlBalance(long accountID) voidimmediateDatabaseBalanceUpdate(long accountID) When this account maintenance is needed and mysql balance need to be updated immediately, this method does thatvoidrun()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.voidshutDown()Shutting down this thread.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Constructor Details
-
MysqlBalanceUpdater
Create the instance- Parameters:
redundancy- If redundancy is running for thisBalanceManagerthen mysql balance update will be as fast as possible, without any sleep. otherwise, mysql update will be periodicalbalanceManager- the instance ofBalanceManagerwho 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. -
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 addedbilledAmount- 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 happenedbilledAmount- 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
-