new Connection(ipc, node, optsopt)
Connection abstraction class. Handles reconnection logic when the client IPC socket disconnects, internal message buffering during reconnection, and state management for safe connection closure.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ipc |
IPC | IPC module to create connection over. |
|||||||||
node |
Clusterluck.Node | Node this connection communicates with. |
|||||||||
opts |
Object |
<optional> |
Options object for connection. Properties
|
- Source:
Methods
active() → {Boolean}
Returns whether this connection has been stopped or not.
- Source:
Returns:
Whether this connection is active or not.
- Type
- Boolean
connecting() → {Boolean}
Returns whether this connection is in a reconnection state or not.
- Source:
Returns:
Whether this connection is in the middle of reconnection logic.
- Type
- Boolean
idle() → {Boolean}
Returns whether this connection is in an idle state.
- Source:
Returns:
Whether this connection is currently idle.
- Type
- Boolean
initiateStream(stream) → {Clusterluck.Connection}
Marks message stream stream
in order to indicate to this connection beforehand that it is not
in an idle state.
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
stream |
Object | Message stream to mark. Properties
|
- Source:
Returns:
This instance.
maxLen(lenopt) → {Number}
Acts as a getter/setter for the max length of the internal message queue
for this IPC socket connection.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
len |
Number |
<optional> |
Number to set maximum message queue length to. |
- Source:
Returns:
The maximum message queue length of this IPC socket.
- Type
- Number
node() → {Clusterluck.Node}
Acts as a getter for the node this connection communicates with.
- Source:
Returns:
Node this instance communicates with.
- Type
- Clusterluck.Node
queue() → {Queue}
Acts as a getter for the internal message buffer.
- Source:
Returns:
Internal message buffer of this instance.
- Type
- Queue
send(event, data) → {Clusterluck.Connection}
Sends message data
under event event
through this IPC socket.
Parameters:
Name | Type | Description |
---|---|---|
event |
String | Event to identify IPC message with. |
data |
Object | Data to send with this IPC message. |
- Source:
Returns:
This instance.
start()
Initializes IPC client socket to node
, along with listeners for socket disconnects.
- Source:
stop(forceopt) → {Clusterluck.Connection}
Closes IPC client socket to node
. Can be done synchronously using the force option, or asynchronously by waiting for an idle/connected state to occur.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
force |
Boolean |
<optional> |
Whether to forcibly close this connection or not. If true, will bypass waiting for an 'idle' state, immediately flushing the internal message buffer and clobeering state about which streams are still active over this connection. Otherwise, this will asynchronously close, waiting for all messages and streams to finish first. |
- Source:
Returns:
This instance.