Classes

NodeManager

Class representing a node manager.

Signature

export declare class NodeManager

JSDoc

@classNodeManager

Properties

readonly manager: Hoshimi;

The manager for the node.

@type{Hoshimi}@readonly
readonly nodes: Collection<string, NodeStructure>;

The nodes for the manager.

@type{Collection<string, Node>}@readonly

Methods

delete(node: NodeIdentifier): boolean;

Delete the node.

Parameters

node
The node or node id to delete.

Returns

If the node was deleted.

Examples

const node = manager.nodeManager.get("node1");
if (node) manager.nodeManager.delete(node.id); // true if the node was deleted
get(node: NodeIdentifier): NodeStructure | undefined;

Get the node by id.

Parameters

node
The node or node id to get.

Returns

The node or undefined if not found.

Examples

const node = manager.nodeManager.get("node1");
if (node) {
	console.log(node.id); // node1
} else {
	console.log("Node not found");
}
create(options: NodeOptions): NodeStructure;

Create a new node.

Parameters

options
The options for the node.

Returns

The created node.

Examples

```ts
const node = manager.nodeManager.create({
	host: "localhost",
	port: 2333,
	password: "password",
	secure: false,
});

console.log(node.id); // localhost:2333
destroy(node: NodeIdentifier): void;

Destroy a node.

Parameters

node
The node or node id to destroy.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) node.destroy();
reconnect(node: NodeIdentifier): void;

Reconnect a node.

Parameters

node
The node or node id to reconnect.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) node.reconnect();
disconnect(node: NodeIdentifier): void;

Disconnect a node.

Parameters

node
The node or node id to disconnect.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) node.disconnect();
connect(node: NodeIdentifier): void;

Connect a node.

Parameters

node
The node or node id to connect.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) node.connect();
getLeastUsed(sortType?: NodeSortFilter): NodeStructure;

Get the least used node.

Returns

The least used node.

Examples

const node = manager.nodeManager.getLeastUsed();
if (node) {
	console.log(node.id); // node1
	console.log(node.penalties); // the penalties of the node
	console.log(node.state); // the state of the node
}
reconnectAll(): void;

Reconnect the nodes.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) node.reconnectAll();
disconnectAll(): void;

Disconnect the nodes.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) node.disconnectAll();
connectAll(): void;

Connect the nodes.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) node.connect();
destroyAll(): void;

Destroy the nodes.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) node.destroy();