Package balance
Class LeaseDTO
java.lang.Object
balance.LeaseDTO
This class is responsible for caching balance, taking advanced loan from mysql, giving lease when needed,
syncing the balance information between mysql and redis cluster
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringRedis cluster balance field constant key.static final long -
Constructor Summary
ConstructorsConstructorDescriptionLeaseDTO(long accountID, BalanceManager balanceManager) Create aLeaseDTOinstance for the given account id -
Method Summary
Modifier and TypeMethodDescriptionvoiddecreaseLeaseAmount(double extraLease) Extra amount left at the end of the call is added to the lease (make sure to provide +ve value).doubledoublegetLease(double lease) Try to get a lease from this account balance.doublevoidreturnAvailableBalancePercentage(double percentage) AsLeaseDTOis taking lease in chunk amount of from redis Even if all of them are not used.
-
Field Details
-
BALANCE_FIELD
Redis cluster balance field constant key.- See Also:
-
WAIT_TIME_FULL_RELEASE
public static final long WAIT_TIME_FULL_RELEASE- See Also:
-
-
Constructor Details
-
LeaseDTO
Create aLeaseDTOinstance for the given account id- Parameters:
accountID- Account id for balance informationbalanceManager- ParentBalanceManagerinstance from where thisLeaseDTOinstance is being maintained.
-
-
Method Details
-
getLease
public double getLease(double lease) Try to get a lease from this account balance. If possible take that lease of given amount. If full amount not possible then try to take lease of possible amount. If that is even not possible then return with zero lease- Parameters:
lease- The amount to be added to the lease- Returns:
- the exact amount that lease was possible for. 0 when no balance available for this client
-
decreaseLeaseAmount
public void decreaseLeaseAmount(double extraLease) Extra amount left at the end of the call is added to the lease (make sure to provide +ve value). The optional total bill, if present, is also queued to be updated in the db at next update cycle.- Parameters:
extraLease- remaining lease amount. make sure that it's +ve
-
getLeasedBalance
public double getLeasedBalance()- Returns:
- the amount of available local balance
-
returnAvailableBalancePercentage
public void returnAvailableBalancePercentage(double percentage) AsLeaseDTOis taking lease in chunk amount of from redis Even if all of them are not used. So this method will return all the remaining lease amount to redis cluster. -
getAvailableLocalBalance
public double getAvailableLocalBalance()
-