Package com.reve.redis.cluster
Class ClusterObserver
java.lang.Object
com.reve.redis.cluster.ClusterObserver
This class holds all the information about a cluster.
#TODO This cluster should be Thread which constantly monitors but not yet implemented.
-
Constructor Summary
ConstructorsConstructorDescriptionClusterObserver(String redisHost, int redisPort, String redisPassword) Create an observer instanceClusterObserver(String redisHost, int redisPort, String redisPassword, int maxConnectionCount) Create an observer instanceClusterObserver(String entryNodeAddress, String redisPassword) Create an observer instance -
Method Summary
Modifier and TypeMethodDescriptionvoidfreeConnection(redis.clients.jedis.JedisCluster jedisCluster) Whenever we are done with aJedisClusterinstance.redis.clients.jedis.JedisClusterGet an instance ofJedisCluster.My node is the clusterNodethisClusterObservertreating as the closest node This value is configured by usergetSlotKeysForTable(String tableName) Get the slot key list for the specified table.voidReads the cluster and saves all the nodes running in this clustervoidonClose()When any application getting shutdown this method should be called.booleansaveSlotKeyForTable(String tableName, String slotKey) Save a slot key for the table specified.voidsetSslConfiguration(com.reve.websocket.ssl.SSLConfiguration sslConfiguration) If ssl enabled for this redis cluster, then an instance ofSSLConfigurationmust be set before creating any connection to the cluster
-
Constructor Details
-
ClusterObserver
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 theentryNodeAddress
-
ClusterObserver
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 noderedisPassword- password for entering to this cluster. This is actually the password for theentryNodeAddress
-
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 noderedisPassword- password for entering to this cluster. This is actually the password for theentryNodeAddressmaxConnectionCount- 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 ofSSLConfigurationmust 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 ofJedisCluster. An instance can be returned fromfreeConnectionsif available any, otherwise, it may create a new one and return. One who is calling this method to get aJedisClustermust ensure that the instance is returned to free pool by callingfreeConnection(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 ofJedisClusterand cause a connection exhaust error.- Returns:
- the instance of
JedisClusterready to use for executing commands to redis.
-
getClusterNodes
- Returns:
- the list of all cluster
Node
-
getMyNode
My node is the clusterNodethisClusterObservertreating 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 aJedisClusterinstance. 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 ofJedisClusterto be freed.
-
getSlotKeysForTable
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 -
saveSlotKeyForTable
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 forslotKey- 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.
-