Cluster

Inherits from: Object
Instance variables: seeds, members, process, running, onUpBlock, onDownBlock, reconnectInterval, failedSeeds, sentinelName, ring

Automated cluster membership management. Connects to seed nodes, monitors them for failure, and delivers membership events when nodes join or leave.

Built on existing primitives: Node connect:, process monitors, and the NodeHealthMonitor heartbeat system.

Example
"Create a cluster from seed addresses"
| cluster <Cluster> |
cluster := Cluster seeds: #('host1:8081' 'host2:8081').
cluster start.

cluster members.    "Array of live Node values"
cluster size.       "Number of live members"

"Register event handlers"
cluster onMemberUp: [:node | ('joined: ', node addr) println].
cluster onMemberDown: [:addr | ('left: ', addr) println].

cluster stop

Class Methods

uncategorized

class seeds:

Create a cluster from an array of seed addresses (e.g., 'host:port').

Instance Methods

uncategorized

addFailed:
connectSeed:
handleDown:
isConnected:

Return true if the given address is a live member.

members

Return an Array of currently live Node values.

nodeFor:

Return the node responsible for the given key using consistent hashing. Returns a Node, or nil if the cluster is empty.

Example
| cluster <Cluster> node <Node> |
cluster := Cluster seeds: #('host1:8081' 'host2:8081').
node := cluster nodeFor: 'user-123'.
nodesFor:count:

Return N nodes responsible for the given key (for replication). Returns an Array of Nodes.

notifyDown:
notifyUp:
onMemberDown:

Register a block to call when a member leaves. Block receives the address string.

onMemberUp:

Register a block to call when a new member joins. Block receives the Node.

primInit:
printString
reconnectFailed
reconnectInterval

Return the reconnect interval in milliseconds.

reconnectInterval:

Set the reconnect interval in milliseconds.

ring

Return the underlying HashRing.

runLoop
size

Return the number of live members.

start

Start the cluster membership manager.

stop

Stop the cluster and disconnect from all peers.