callosum-server-slots

Server slot management for Callosum: a self-balancing distributed services protocol

callosum-server-slots

Stability: 1 - Experimental

Server slot management for Callosum: a self-balancing distributed services protocol.

var CallosumServerSlots = require('callosum-server-slots');
var callosumServerSlots = new CallosumServerSlots();
 
callosumServerSlots.on('error', function (error) {
    console.log(error); 
});
 
var slot = callosumServerSlots.get();
// after the slot is no longer used 
callosumServerSlots.put(slot);
npm test

Server slot management for Callosum: a self-balancing distributed services protocol.

The slot manganger will always return the lowest available slot. For example, the following sequence of commands and their results is guaranteed:

var assert = require('assert');
var CallosumServerSlots = require('callosum-server-slots');
var callosumServerSlots = new CallosumServerSlots();
 
callosumServerSlots.on('error', function (error) {
    console.log(error); 
});
 
var slotA = callosumServerSlots.get();
assert.ok(slotA == 0);
 
var slotB = callosumServerSlots.get();
assert.ok(slotB == 1);
 
var slotC = callosumServerSlots.get();
assert.ok(slotC == 2);
 
callosumServerSlots.put(slotA);
var slotD = callosumServerSlots.get();
assert.ok(slotD == 0);
 
var slotE = callosumServerSlots.get();
assert.ok(slotE == 3);

Public API

Creates a new CallosumServerSlots instance.

  • Return: Integer Next lowest available slot.
  • slot: Integer Slot number previously gotten from this instance.

Puts back the slot so that it is available for retrieval again.

  • function (error) {}
    • error: Object An error that occurred.

Emitted when CallosumServerSlots encounters an error. If no handler is registered, an exception will be thrown.