API Docs for: 2.2.2
Show:

RiakCluster Class

Module: Core

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();

See RiakCluster.Builder

Constructor

RiakCluster

(
  • options
)

Parameters:

  • options Object
    • the options to use.
    • nodes RiakNode[]

      An array of (unstarted) RiakNode objects.

    • [executionAttempts=3] Number optional

      Number of times to retry commands on failure.

    • [nodeManager=RoundRobinNodeManager] Object optional

      Set the NodeManager for this cluster.

    • [queueCommands=false] Boolean optional

      Set whether to queue commands or not if no RiakNodes are available.

    • [queueMaxDepth=unlimited] Number optional

      The maximum number of commands to queue if queueCommands is set. Default is unlimited.

    • [queueSubmitInterval=500] Number optional

      The duration in milliseconds between queue submission attempts. Default is 500.

Item Index

Properties

Methods

addNode

(
  • node
)

Add a RiakNode to this cluster.

Parameters:

  • node RiakNode

    the (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 optional

    the previous node this command was attempted on

getNodeIndex

(
  • node
)
RiakNode

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:

RiakNode:
  • The node index in this cluster. Returns -1 if the node does not exist.

removeNode

(
  • node
)
Boolean

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:

Boolean:
  • 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:

stateChange

This event is fired when the state of the RiakCluster changes. See: RiakCluster.State

Event Payload: