RiakCluster Class
Provides the RiakCluster class and its Builder.
Instances of this class maintain a set of RiakNode objects and executes commands on them.
options is an object with the following defaults:
{
nodes: [defaultRiakNode],
executionAttempts: 3,
nodeManager: RoundRobinNodeManager,
queueCommands: false,
queueMaxDepth: unlimited
}
The defaultRiakNode is a RiakNode connected to 127.0.0.1:8087
As a convenience a builder class is provided.
var nodeTemplate = new RiakNode.Builder().withMinConnections(10);
var nodeAddys = ['192.168.1.1', '192.168.1.2'];
var arrayOfNodes = RiakNode.buildNodes(nodeAddys, nodeTemplate);
var myCluster = new RiakCluster.Builder().withRiakNodes(arrayOfNodes).build();
Constructor
RiakCluster
-
options
Parameters:
-
options
Object- the options to use.
-
nodes
RiakNode[]An array of (unstarted) RiakNode objects.
-
[executionAttempts=3]
Number optionalNumber of times to retry commands on failure.
-
[nodeManager=RoundRobinNodeManager]
Object optionalSet the NodeManager for this cluster.
-
[queueCommands=false]
Boolean optionalSet whether to queue commands or not if no RiakNodes are available.
-
[queueMaxDepth=unlimited]
Number optionalThe maximum number of commands to queue if queueCommands is set. Default is unlimited.
-
[queueSubmitInterval=500]
Number optionalThe duration in milliseconds between queue submission attempts. Default is 500.
Methods
addNode
-
node
Add a RiakNode to this cluster.
Parameters:
-
node
RiakNodethe (unstarted) RiakNode to add.
execute
-
riakCommand
-
[previous]
Execute a command on this RiakCluster.
Selects a RiakNode from the cluster and executes the command on it.
Parameters:
-
riakCommand
Object- the command to execute.
-
[previous]
RiakNode optionalthe previous node this command was attempted on
getNodeIndex
-
node
Get a RiakNode index from this cluster.
Parameters:
-
node
RiakNode | String- the node for getting the index. May be supplied as a RiakNode instance or IP|hostname[:port]
Returns:
- The node index in this cluster. Returns -1 if the node does not exist.
removeNode
-
node
Remove a RiakNode from this cluster. The node being removed will also be stopped.
Parameters:
-
node
RiakNode | String- the node to remove. May be supplied as a RiakNode instance or IP|hostname[:port]
Returns:
- true if the node was removed.
start
-
[callback]
Start this RiakCluster
Parameters:
-
[callback]
Function optional- a callback for when cluster is started.
-
[err]
Object optional- will be set to an error if one occurred.
-
[cluster]
Object optional- will be set to the cluster object.
stop
-
callback
Stop this RiakCluster
Parameters:
-
callback
Function- called when cluster completely stopped.
-
[err]
Object optional- set to an error if one occurrs during start.
-
[state]
Object optional- the state of the cluster at shutdown.
Properties
State
Object
final
static
The state of this cluster.
If listening for stateChange events, a numeric value will be sent that can be compared to:
RiakCluster.State.CREATED
RiakCluster.State.RUNNING
RiakCluster.State.SHUTTING_DOWN
RiakCluster.State.SHUTDOWN
See: stateChange
Events
nodeStateChange
This event is fired when the state of any RiakNode in the cluster changes.
Event Payload:
-
node
Object- the RiakNode object whose state changed
-
state
Number- the RiakNode.State
stateChange
This event is fired when the state of the RiakCluster changes. See: RiakCluster.State
Event Payload:
-
state
Number- the new RiakCluster.State