Class PubSubPublisher

java.lang.Object
java.lang.Thread
com.reve.balancemanager.pubsub.PubSubPublisher
All Implemented Interfaces:
Runnable

public class PubSubPublisher extends Thread
Publisher class to publish messages in Redis cluster pubsub
  • Constructor Details

    • PubSubPublisher

      public PubSubPublisher(String identifier, com.reve.redis.cluster.ClusterObserver clusterObserver)
  • Method Details

    • run

      public void run()
      Thread run method.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • publishEmptyLeaseStatus

      public void publishEmptyLeaseStatus(long accountID)
      Whenever Balance manager detects zero balance in redis cache, it transmits a warning to all Balance manager. So other balance manager can return some of their local money in redis, and this one can take it.
      Parameters:
      accountID - Account ID for which balance goes to zero in redis.
    • publishNegativeRedisBalance

      public void publishNegativeRedisBalance(long accountID)
      Whenever Balance is getting negative in redis. Then Balance manager broadcasts negative balance status in Channels.BALANCE_SYNC_CHANNEL channel. So that other balance manager can back balance to redis.
      Parameters:
      accountID - who is affected by negative balance.
    • publishAccountValidationStatus

      public void publishAccountValidationStatus(long accountID, LeaseDTOStatus status)
      Whenever any accountID that is unknown/newly introduced to DB at first. Then Balance manager broadcasts account validation status in Channels.ACCOUNT_VALIDATION_CHANNEL channel. So that other balance manager can update the account status.
      Parameters:
      accountID - whose status is changed.
      status - 1 if valid, 0 otherwise.
    • ackFreezeRequest

      public void ackFreezeRequest(long accountID)
      For some reason like balance mismatch between redis and mysql in some point, we may need to freeze the account and match the balance in redis and mysql. So whenever any freeze request is received, we must send an ACK to notify that this BM has received this request, and it is processing.
      Parameters:
      accountID - Account ID for which freeze request was received.
    • publishCompletedFreeze

      public void publishCompletedFreeze(long accountID)
      For some reason like balance mismatch between redis and mysql in some point, we may need to freeze the account and match the balance in redis and mysql. So whenever any freeze request is received, we must freeze all transaction as well as drop all the call of that account make the bill. Then we must notify that my side of freezing this account is done.
      Parameters:
      accountID - Account ID for which freeze request was received.
    • publishCompletedUnfreeze

      public void publishCompletedUnfreeze(long accountID)
      When balance matching is done by mitigation process, it will send an unfreeze request. We must respond to that.
      Parameters:
      accountID - Account ID for which unfreeze request was received.
    • publishFreezeRequest

      public void publishFreezeRequest(long accountID)
      Publish a MessageType.FREEZE_REQUEST message in Channels.BALANCE_FREEZE_CHANNEL to freeze the given account ID. Once we send this message, the receiver on the other end will send an MessageType.ACK_FREEZE_REQUEST immediately. And then the receiver will do whatever it required at their end to freeze the request.
      Parameters:
      accountID - Account ID for which freeze request to be sent.
    • publishUnfreezeRequest

      public void publishUnfreezeRequest(long accountID)
      Publish a MessageType.UNFREEZE_REQUEST message in Channels.BALANCE_FREEZE_CHANNEL to un-freeze the given account ID. Once we send this message, the receiver on the other end will do whatever it required at their end to un-freeze the request.
      Parameters:
      accountID - Account ID for which un-freeze request to be sent.
    • shutDown

      public void shutDown()
      Shutdown this thread