Class LeaseDTO

java.lang.Object
com.reve.balancemanager.lease.LeaseDTO
Direct Known Subclasses:
LeaseDTOImpl

public abstract class LeaseDTO extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract double
    addLocalBalance(double extraLease)
    Extra amount left at the end of the call is added to the lease (make sure to provide +ve value).
    abstract 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.
    abstract long
     
    abstract double
     
    abstract double
     
    protected static void
     
    static LeaseDTO
     
    abstract double
    getLease(double lease, LeaseResponse response, boolean partialEnabled)
    Try to get a lease from this account balance.
    abstract long
    Get the timestamp in millis when last time this instance was synced with slaved.
    protected abstract double
    increaseRedis(double amount)
     
    protected abstract double
    increaseRedisold(double amount)
    Call hincrByFloat method in JedisCluster instance.
    abstract void
    init(long accountId, double availableLocalBalance, BalanceManager balanceManager)
    This initialization is useful when take-over is happening.
    abstract void
    init(long accountId, BalanceManager balanceManager)
    Initialize a LeaseDTO instance for the given account id
    protected abstract void
     
    abstract boolean
     
    abstract void
    onProcessShutdown(boolean returnBalance)
    Do all the task required to do while the application is shutting down.
    abstract double
    A percentage of available balance for this account will be returned to redis cluster when this method is called.
    abstract void
    setFrozen(boolean frozen)
    Setter for freeze/unfreeze state of an account
    abstract void
    setLocalBalanceSyncTime(long localBalanceSyncTime)
    Set the timestamp in millis when last time this instance was synced with slaved.
    abstract boolean
    Check and assign values in #localBalanceSyncTime.
    abstract void
    After completing account freeze request we must set available redis amount to 0.
    abstract void
    updateInformation(byte[] data, int offset, int length)
    We have received information from master, Now we will update this LeaseDTO with this latest attributes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LeaseDTO

      public LeaseDTO()
  • Method Details

    • init

      public abstract void init(long accountId, BalanceManager balanceManager)
      Initialize a LeaseDTO instance for the given account id
      Parameters:
      accountId - Account id for balance information
      balanceManager - Parent BalanceManager instance from where this LeaseDTO instance is being maintained.
    • init

      public abstract void init(long accountId, double availableLocalBalance, BalanceManager balanceManager)
      This initialization is useful when take-over is happening. In that case, we have account id and available local balance of that account. So we will not load it into cluster this time.
      Parameters:
      accountId - 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.
    • getLease

      public abstract double getLease(double lease, LeaseResponse response, boolean partialEnabled)
      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
      response - 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.
      Returns:
      the exact amount that lease was possible for. 0 when no balance available for this client
    • insertBMidIntoRedis

      protected abstract void insertBMidIntoRedis() throws Exception
      Throws:
      Exception
    • increaseRedisold

      protected abstract double increaseRedisold(double amount) throws Exception
      Call hincrByFloat method in JedisCluster instance. with given amount.
      Parameters:
      amount - this amount will be increased in redis
      Returns:
      the remaining amount in redis
      Throws:
      Exception
    • increaseRedis

      protected abstract double increaseRedis(double amount) throws Exception
      Throws:
      Exception
    • addLocalBalance

      public abstract double addLocalBalance(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
      Returns:
      the available local balance after the operation is done.
    • returnAvailableBalancePercentage

      public abstract double returnAvailableBalancePercentage(double percentage)
      A percentage of available balance for this account will be returned to redis cluster when this method is called.
      Parameters:
      percentage - What percentage of the available will be returned. For a full return percentage will be 100
      Returns:
      the available local balance after the operation is done.
    • updateAvailableRedisAmount

      public abstract void updateAvailableRedisAmount()
      After completing account freeze request we must set available redis amount to 0. So, that balance mismatch detection method works properly. This method provides us with that facility.
    • getAccountId

      public abstract long getAccountId()
      Returns:
      The accountId for which lease is taken/calculated
    • getAvailableLocalBalance

      public abstract double getAvailableLocalBalance()
      Returns:
      the amount available in local balance
    • getAvailableRedisBalance

      public abstract double getAvailableRedisBalance()
      Returns:
      the amount available in redis
    • setFrozen

      public abstract void setFrozen(boolean frozen)
      Setter for freeze/unfreeze state of an account
      Parameters:
      frozen - Boolean to freeze or unfreeze account
    • isFrozen

      public abstract boolean isFrozen()
    • syncBalance

      public abstract boolean syncBalance()
      Check and assign values in #localBalanceSyncTime.
      Returns:
      true, if balance sync is required for this LeaseDTO. Otherwise, return false
    • getLocalBalanceSyncTime

      public abstract long getLocalBalanceSyncTime()
      Get the timestamp in millis when last time this instance was synced with slaved.
      Returns:
      the timestamp in millis when last time this instance was synced with slaved.
    • setLocalBalanceSyncTime

      public abstract void setLocalBalanceSyncTime(long localBalanceSyncTime)
      Set the timestamp in millis when last time this instance was synced with slaved.
      Parameters:
      localBalanceSyncTime - timestamp in milliseconds to be set
    • appendAttributes

      public abstract 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. Sequence of the items to be added will be same as the sequence of the definition of the constants in the class LeaseDTOConstants
      Parameters:
      data - byte array where this LeaseDTO information will be appended.
      index - starting index of the byte array where this instance should be appended.
      Returns:
      the new index after appending this instance.
    • updateInformation

      public abstract void updateInformation(byte[] data, int offset, int length)
      We have received information from master, Now we will update this LeaseDTO with this latest attributes.
      Parameters:
      data - byte array received from master.
      offset - starting index of the byte array.
      length - length of the byte array that contains valid information.
    • onProcessShutdown

      public abstract void onProcessShutdown(boolean returnBalance)
      Do all the task required to do while the application is shutting down.
      Parameters:
      returnBalance - 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.
    • getInstance

      public static LeaseDTO getInstance()
    • getClassReference

      protected static void getClassReference()