public class LeaseDTOImpl extends LeaseDTO implements Serializable
| Constructor and Description |
|---|
LeaseDTOImpl() |
| Modifier and Type | Method and Description |
|---|---|
double |
addLocalBalance(double extraLease)
Extra amount left at the end of the call is added to the lease (make sure to provide +ve
value).
|
int |
appendAttributes(byte[] data,
int index)
Append all the required attributes into the given byte array, so that it can be sent to the slave.
|
long |
getAccountId() |
double |
getAvailableLocalBalance() |
double |
getAvailableRedisBalance() |
double |
getLease(double lease,
LeaseResponse response,
boolean partialEnabled)
Try to get a lease from this account balance.
|
long |
getLocalBalanceSyncTime()
Get the timestamp in millis when last time this instance was synced with slaved.
|
protected double |
increaseRedis(double amount)
Call hincrByFloat method in
JedisCluster instance. |
protected double |
increaseRedisUnused(double amount)
Call hincrByFloat method in
JedisCluster instance. |
void |
init(long accountId,
BalanceManager balanceManager)
Initialize a
LeaseDTO instance for the given account id |
void |
init(long accountId,
double availableLocalBalance,
BalanceManager balanceManager)
This initialization is useful when take-over is happening.
|
boolean |
isFrozen() |
void |
onProcessShutdown(boolean returnBalance)
Do all the task required to do while the application is shutting down.
|
double |
returnAvailableBalancePercentage(double percentage)
A percentage of available balance for this account will be returned to redis cluster when this method is called.
|
void |
setFrozen(boolean frozen)
Setter for freeze/unfreeze state of an account
|
void |
setLocalBalanceSyncTime(long localBalanceSyncTime)
Set the timestamp in millis when last time this instance was synced with slaved.
|
boolean |
syncBalance()
Check and assign values in
localBalanceSyncTime. |
String |
toString()
For debugging purpose
|
void |
updateInformation(byte[] data,
int offset,
int length)
We have received information from master, Now we will update this
LeaseDTO with this latest attributes. |
getClassReference, getInstancepublic void init(long accountId,
BalanceManager balanceManager)
LeaseDTO instance for the given account idinit in class LeaseDTOaccountId - Account id for balance informationbalanceManager - Parent BalanceManager instance from where this LeaseDTO instance is being
maintained.public void init(long accountId,
double availableLocalBalance,
BalanceManager balanceManager)
init in class LeaseDTOaccountId - The account ID for which this instance belongs to.availableLocalBalance - At the time take-over what was the available local balance.balanceManager - Parent BalanceManager instance from where this LeaseDTO instance is being
maintained.public double getLease(double lease,
LeaseResponse response,
boolean partialEnabled)
getLease in class LeaseDTOlease - The amount to be added to the leaseresponse - The response value will be updated into this instance. This instance must be passed from the
caller, and values will be updated here.partialEnabled - if caller can be happy with partial lease, then this value must be true.protected double increaseRedis(double amount)
JedisCluster instance. with given amount.increaseRedis in class LeaseDTOamount - this amount will be increased in redisprotected double increaseRedisUnused(double amount)
JedisCluster instance. with given amount.amount - this amount will be increased in redispublic double addLocalBalance(double extraLease)
addLocalBalance in class LeaseDTOextraLease - remaining lease amount. make sure that it's +vepublic double returnAvailableBalancePercentage(double percentage)
returnAvailableBalancePercentage in class LeaseDTOpercentage - What percentage of the available will be returned. For a full return percentage will be 100public long getAccountId()
getAccountId in class LeaseDTOpublic double getAvailableLocalBalance()
getAvailableLocalBalance in class LeaseDTOpublic double getAvailableRedisBalance()
getAvailableRedisBalance in class LeaseDTOpublic void setFrozen(boolean frozen)
public String toString()
public boolean syncBalance()
localBalanceSyncTime.syncBalance in class LeaseDTOLeaseDTO. Otherwise, return falsepublic long getLocalBalanceSyncTime()
getLocalBalanceSyncTime in class LeaseDTOpublic void setLocalBalanceSyncTime(long localBalanceSyncTime)
setLocalBalanceSyncTime in class LeaseDTOlocalBalanceSyncTime - timestamp in milliseconds to be setpublic int appendAttributes(byte[] data,
int index)
LeaseDTOConstantsappendAttributes in class LeaseDTOdata - byte array where this LeaseDTO information will be appended.index - starting index of the byte array where this instance should be appended.public void updateInformation(byte[] data,
int offset,
int length)
LeaseDTO with this latest attributes.updateInformation in class LeaseDTOdata - byte array received from master.offset - starting index of the byte array.length - length of the byte array that contains valid information.public void onProcessShutdown(boolean returnBalance)
onProcessShutdown in class LeaseDTOreturnBalance - If we want all the local balance to return in redis cluster then this value should be true,
otherwise this value should be false. If the application is running in standalone or running
as master this value should be true. It is considered that if the application is running in
redundancy mode only master should return balance in redis cluster and slave should not.Copyright © 2023. All rights reserved.