public class BalanceManager extends Object
CLIENT_BALANCE_TABLE table.
Maintains elastic property to sync balance in between mysql and redis cluster.| Modifier and Type | Field and Description |
|---|---|
static String |
CLIENT_BALANCE_TABLE
Mysql table name where balance information can be found
|
static String |
TOKENIZER |
| Constructor and Description |
|---|
BalanceManager(String redisHost,
int redisPort,
String redisPass)
Create an instance of
BalanceManager. |
| Modifier and Type | Method and Description |
|---|---|
cluster.ClusterObserver |
getClusterObserver()
Getter for
clusterObserver |
double |
getDefaultLeaseChunkAmount() |
double |
getLease(long accountId,
double leaseAmount)
Try to get a lease from this account balance.
|
void |
getLeasesFromOtherBMs(long accountID) |
double |
getPercentageToRelease() |
PubSubPublisher |
getPubSubPublisher() |
double |
getThresholdToReleaseFullAmount() |
void |
onProcessShutdown()
We have taken advanced amount from redis cluster, so
When system is getting shut down, all the available cached balance should be returned to redis,
otherwise some money will be lost.
|
double |
readFromDb(long accountId)
If the given accountId is not present in redis then it will be loaded from mysql database and be saved in redis cluster.
|
void |
returnLease(long accountId,
double leaseAmount)
Extra amount left at the end of the call is added to the lease (make sure to provide +ve
value).
|
void |
setDefaultLeaseChunkAmount(double defaultLeaseChunkAmount) |
void |
setPercentageToRelease(double percentageToRelease) |
void |
setThresholdToReleaseFullAmount(double thresholdToReleaseFullAmount) |
public static final String TOKENIZER
public static final String CLIENT_BALANCE_TABLE
public BalanceManager(String redisHost, int redisPort, String redisPass)
BalanceManager. This instance should be singleton.redisHost - Redis cluster server ip address where balance information will be cached. This cluster node
must be a master node in cluster.redisPort - Redis cluster server port where balance information will be cached.redisPass - Auth Password for redis clusterpublic double readFromDb(long accountId)
accountId - Account ID for which balance information will be loaded into redis.public double getLease(long accountId,
double leaseAmount)
accountId - The account id lease needed fromleaseAmount - The amount to be added to the leasepublic void returnLease(long accountId,
double leaseAmount)
accountId - Account id the lease should be returned toleaseAmount - remaining lease amount. make sure that it's +vepublic void getLeasesFromOtherBMs(long accountID)
public void onProcessShutdown()
public cluster.ClusterObserver getClusterObserver()
clusterObserverClusterObserver instance that was used to cache balance information.public double getDefaultLeaseChunkAmount()
public void setDefaultLeaseChunkAmount(double defaultLeaseChunkAmount)
defaultLeaseChunkAmount - sets the default lease amount balance manager takes from redispublic double getThresholdToReleaseFullAmount()
public void setThresholdToReleaseFullAmount(double thresholdToReleaseFullAmount)
public double getPercentageToRelease()
public void setPercentageToRelease(double percentageToRelease)
public PubSubPublisher getPubSubPublisher()
Copyright © 2021. All rights reserved.