callosum-client-tcp

TCP client for Callosum: a self-balancing distributed services protocol

callosum-client-tcp

Stability: 1 - Experimental

TCP Client for Callosum: a self-balancing distributed services protocol.

var CallosumClient = require('callosum-client-tcp');
var callosumClient = new CallosumClient({MAX_SLOTS: 100});
 
callosumClient.on('error', function (error) {
    console.log(error);
});
 
// add a connection to the connection pool 
// client will either hang on to the connection or close it if it is not needed 
callosumClient.newConnection(slot, socket);
 
var socket = callosumClient.getConnection();
// socket is either a connection that is available or  
 
callosumClient.returnConnection(socket);
// return a previously leased connection to the client pool 
 
npm test

TCP Client for Callosum: a self-balancing distributed services protocol. It servers as a connection pool.

Open available connections are maintained internally via two heap data structures. The min heap data structure is maintained in order to provide a connection from the pool with the lowest slot value. The max heap data structure is maintained in order to enable rapid checking and replacing of a connection with a high slot value if a new connection with a lower slot value becomes available.

Public API

  • options: Object (Default: {})
    • MAX_SLOTS: Integer (Default: 100) Number of connection slots to maintain.

Creates a new instance of CallosumClient.

  • Return: Socket object
    • _destroyed: Boolean CAUTION: reserved for internal use
    • _destroySocket: Function CAUTION: reserved for internal use
    • _leased: Boolean CAUTION: reserved for internal use
    • _slot: Integer CAUTION: reserved for internal use

Returns next available socket with lowest slot number. If no sockets are available, is returned.

CAUTION: reserved for internal use

  • slot: Integer Slot number.
  • socket: Socket object Socket.

Internal bookkeeping of the socket via a min heap and a max heap with event listeners for socket destruction.

  • slot: Integer Slot number.
  • socket: Socket object Socket.

New connection (from a rover) is available for the client to keep or discard.

  • socket: Socket object
    • _destroyed: Boolean CAUTION: reserved for internal use
    • _destroySocket: Function CAUTION: reserved for internal use
    • _leased: Boolean CAUTION: reserved for internal use
    • _slot: Integer CAUTION: reserved for internal use

When the user of the socket is finished with it, instead of closing it, this method allows the socket to be handed back to Callosum.