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 operation is added to the available local balance.
|
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() |
long |
getLastLeaseServedTime() |
double |
getLease(double lease,
LeaseResponse response,
boolean partialEnabled,
boolean needExactAmount)
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)
use lua script in
JedisCluster instance. |
protected double |
increaseRedisold(double amount)
Deprecated.
|
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.
|
protected void |
insertBMidIntoRedis()
insert
balanceManager identifier into redis BalanceManager.BM_ID_FIELD field via Lua script |
boolean |
isMitigationRunning() |
boolean |
isValidAccountID()
It is getter method of validAccountID property.
|
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 |
setAccountIDValidationStatus(boolean status)
It is setter method of validAccountID property.
|
void |
setLocalBalanceSyncTime(long localBalanceSyncTime)
Set the timestamp in millis when last time this instance was synced with slaved.
|
void |
setMitigationRunning(boolean mitigationRunning)
Setter for freeze/unfreeze state of an account
|
boolean |
syncBalance()
Check and assign values in
localBalanceSyncTime. |
String |
toString()
For debugging purpose
|
void |
updateAvailableRedisAmount()
After completing account freeze request we must set available redis amount to 0.
|
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,
boolean needExactAmount)
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.needExactAmount - if true, attempts to allocate the exact lease amount, and don't keep any local balance; if false, allows chunk-based adjustment and also uses local balance mechanism.protected void insertBMidIntoRedis()
throws Exception
balanceManager identifier into redis BalanceManager.BM_ID_FIELD field via Lua scriptinsertBMidIntoRedis in class LeaseDTOException@Deprecated protected double increaseRedisold(double amount) throws Exception
JedisCluster instance. with given amount.increaseRedisold in class LeaseDTOamount - this amount will be increased in redisExceptionprotected double increaseRedis(double amount)
throws Exception
JedisCluster instance. with given amount.increaseRedis in class LeaseDTOamount - this amount will be increased in redisExceptionpublic double addLocalBalance(double extraLease)
local available balance will accumulate gradually but lease-request-gap is getter than threshold e.g. termination accountID. So we must return some value to redis and decrease the local balance.
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 void updateAvailableRedisAmount()
updateAvailableRedisAmount in class LeaseDTOpublic long getAccountId()
getAccountId in class LeaseDTOpublic double getAvailableLocalBalance()
getAvailableLocalBalance in class LeaseDTOpublic double getAvailableRedisBalance()
getAvailableRedisBalance in class LeaseDTOpublic boolean isMitigationRunning()
isMitigationRunning in class LeaseDTOpublic void setMitigationRunning(boolean mitigationRunning)
setMitigationRunning in class LeaseDTOmitigationRunning - Boolean to freeze or unfreeze accountpublic 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 long getLastLeaseServedTime()
getLastLeaseServedTime in class LeaseDTOpublic boolean isValidAccountID()
isValidAccountID in class LeaseDTOpublic void setAccountIDValidationStatus(boolean status)
setAccountIDValidationStatus in class LeaseDTOstatus - true, if accountID is known to mysql, false otherwise.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 © 2025. All rights reserved.