Class ClusterObserver

java.lang.Object
com.reve.redis.cluster.ClusterObserver

public class ClusterObserver extends Object
This class holds all the information about a cluster. #TODO This cluster should be Thread which constantly monitors but not yet implemented.
  • Constructor Details

    • ClusterObserver

      public ClusterObserver(String entryNodeAddress, String redisPassword)
      Create an observer instance
      Parameters:
      entryNodeAddress - HOST:PORT for the entry node, this node will be treated as the nearest node.
      redisPassword - password for entering to this cluster. This is actually the password for the entryNodeAddress
    • ClusterObserver

      public ClusterObserver(String redisHost, int redisPort, String redisPassword)
      Create an observer instance
      Parameters:
      redisHost - Ip address for the entry node, this node will be treated as the nearest node.
      redisPort - port for the entry node
      redisPassword - password for entering to this cluster. This is actually the password for the entryNodeAddress
    • ClusterObserver

      public ClusterObserver(String redisHost, int redisPort, String redisPassword, int maxConnectionCount)
      Create an observer instance
      Parameters:
      redisHost - Ip address for the entry node, this node will be treated as the nearest node.
      redisPort - port for the entry node
      redisPassword - password for entering to this cluster. This is actually the password for the entryNodeAddress
      maxConnectionCount - number of maximum connection to the cluster
  • Method Details

    • setSslConfiguration

      public void setSslConfiguration(com.reve.websocket.ssl.SSLConfiguration sslConfiguration)
      If ssl enabled for this redis cluster, then an instance of SSLConfiguration must be set before creating any connection to the cluster
      Parameters:
      sslConfiguration - SSL related configurations that are needed to connect to the redis cluster
    • loadClusterNodes

      public void loadClusterNodes()
      Reads the cluster and saves all the nodes running in this cluster
    • getClusterConnection

      public redis.clients.jedis.JedisCluster getClusterConnection()
      Get an instance of JedisCluster. An instance can be returned from freeConnections if available any, otherwise, it may create a new one and return. One who is calling this method to get a JedisCluster must ensure that the instance is returned to free pool by calling freeConnection(JedisCluster) method once the caller is done with the instance. If this is not strictly followed, there is a change it may create huge amount of JedisCluster and cause a connection exhaust error.
      Returns:
      the instance of JedisCluster ready to use for executing commands to redis.
    • getClusterNodes

      public ArrayList<Node> getClusterNodes()
      Returns:
      the list of all cluster Node
    • getMyNode

      public Node getMyNode()
      My node is the cluster Node this ClusterObserver treating as the closest node This value is configured by user
      Returns:
      the nearest Node
    • freeConnection

      public void freeConnection(redis.clients.jedis.JedisCluster jedisCluster)
      Whenever we are done with a JedisCluster instance. We must return it to free pool, so that it can be re-used some other times. This method does save the free connection to a pool for re-use.
      Parameters:
      jedisCluster - the instance of JedisCluster to be freed.
    • getSlotKeysForTable

      public Set<String> getSlotKeysForTable(String tableName)
      Get the slot key list for the specified table. Each instance of SBC can have one slot key for a table. So in that case a table will end up having multiple slot keys mapped for it
      Parameters:
      tableName - table name for which slot key is needed
      Returns:
      returns a HashSet<String> containing the slot keys if this table already have some slot keys Otherwise it will return null
    • saveSlotKeyForTable

      public boolean saveSlotKeyForTable(String tableName, String slotKey)
      Save a slot key for the table specified. This method will also save the in my node table -> slotKey map if the given slot key belongs to myNode
      Parameters:
      tableName - Name of the table this slot key has been mapped for
      slotKey - The slot key which has been mapped
      Returns:
      true if was successfully added to the list otherwise false
    • onClose

      public void onClose()
      When any application getting shutdown this method should be called. It will close all the connection with redis and free necessary resources.