callosum-server-slots

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

npm install callosum-server-slots
2 downloads in the last week
4 downloads in the last month

callosum-server-slots

Stability: 1 - Experimental

NPM version

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

Usage

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

Tests

npm test

Overview

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

Documentation

CallosumServerSlots

Public API

new CallosumServerSlots()

Creates a new CallosumServerSlots instance.

callosumServerSlots.get()

  • Return: Integer Next lowest available slot.

callosumServerSlots.put(slot)

  • slot: Integer Slot number previously gotten from this instance.

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

Event error

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

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

npm loves you