Module: skyring/lib/server/node

Represents a participant in the Hashring


new (require("skyring/lib/server/node"))( [host] [, port] [, name] [, app])

Parameters:
Name Type Argument Default Description
host String <optional>

host name for the node to listen on - 127.0.0.1 must be used for localhost ( not 0.0.0.0)

port Number <optional>

Port number for the node to listen on in the ring

name String <optional>
'ringpop'

name of the active ring to join

app String <optional>
timers

app name of the active ring

Source:

Requires

  • module:path
  • module:events
  • module:dns
  • module:@skyringringpop
  • module:tchannel
  • module:debug
  • module:keef

Members


<static, readonly> name

Properties:
Name Type Description
name String

The name of the node

Source:

Methods


close(callback)

Removes itself from the ring and closes and connections

Parameters:
Name Type Description
callback function

A callback function to call when the ring is closed

Source:

handle(handler)

Adds a request handler to the active ringpop instance

Parameters:
Name Type Description
handler function

A request handler for incoming requests from the ring

Source:

handleOrProxy(key, req, res)

Determines if this instance is responsible for a specific key. proxies the request if it is not

Parameters:
Name Type Description
key String

The key to use to do a node lookup in the ring

req http.IncomingMessage | module:skyring/lib/server/mock.Request

an http request object

res http.ServerResponse | module:skyring/lib/server/mock.Response

an http response object

Source:
Returns:
Type
Boolean
Example
const handle = node.handleOrProxy('foobar', req, res)
if (!handle) return;
// deal with request

join( [seeds], callback)

Does the work of configuring tchannel and joining itself into a ringpop ring

Parameters:
Name Type Argument Description
seeds Array.<String> <optional>

An array of node addresses to use as boot strapping nodes

callback function

Function to call when the node has completed the bootstrap process

Source:
Example
node.join(['node-1:5555', '172.10.0.4:4563'], (err) => {
if (err) throw err
 })

leave(callback)

Deprecated: use close method

Parameters:
Name Type Description
callback function

Callback function to call when the eviction process is complete

Deprecated:
  • 10.0.0
Source:

lookup(key)

Lookup the address of the server responsible for a given key

Parameters:
Name Type Description
key String

The key to look up

Source:
Returns:

A server address

Type
String

owns(key)

Determines if this node is responsible for a specific key

Parameters:
Name Type Description
key String

The key to use

Source:
Returns:
Type
Boolean