callosum-client-tcp
Stability: 1 - Experimental
TCP Client for Callosum: a self-balancing distributed services protocol.
Usage
var CallosumClient = ;var callosumClient = MAX_SLOTS: 100; callosumClient; // add a connection to the connection pool// client will either hang on to the connection or close it if it is not neededcallosumClient; var socket = callosumClient;// socket is either a connection that is available or undefined callosumClient;// return a previously leased connection to the client pool
Tests
npm test
Overview
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.
Documentation
CallosumClient
Public API
- new CallosumClient([options])
- callosumClient.getConnection()
- callosumClient.newConnection(slot, socket)
- callosumClient.returnConnection(socket)
new CallosumClient([options])
options
: Object (Default: {})MAX_SLOTS
: Integer (Default: 100) Number of connection slots to maintain.
Creates a new instance of CallosumClient.
callosumClient.getConnection()
- 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, undefined
is returned.
callosumClient.insertSocket(slot, socket)
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.
callosumClient.newConnection(slot, socket)
slot
: Integer Slot number.socket
: Socket object Socket.
New connection (from a rover) is available for the client to keep or discard.
callosumClient.returnConnection(socket)
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.