WorkerCluster

class WorkerCluster(threads: Int, parts: Int? = null, flags: Flags = Flags.defaults(), module: String? = null)

A distributed solver on the threads of Node.js (worker_threads): the catalog on the calling thread, the workers on threads threads, each loading this module (module, this very file by default) and running a site of its own, a delegate of the one of the calling thread (see Site.delegate), over the messages between threads: the cluster lends the workers of its threads to the sites it is federated with. The theory is split into at most parts partitions if given, as many as the workers of the threads and of the sites it is federated with otherwise (see listen and connect); the graph is labelled as the standard solver does with flags. The threads keep Node.js running only while an evaluation is pending; close stops them.

Constructors

Link copied to clipboard
constructor(threads: Int, parts: Int? = null, flags: Flags = Flags.defaults(), module: String? = null)

Properties

Link copied to clipboard

The code the sites linking to this cluster present, if it requires one: four digits, random

Link copied to clipboard

The flags of the solver, the initial ones those given: those set apply from the next evaluation on, the graph built anew, the links and the peers of the cluster kept

Link copied to clipboard

The name of the site of the cluster, as its beacons tell the sites nearby: the name of its host by default

Link copied to clipboard

The sites heard on the local network, not linked to this cluster (see discover)

Link copied to clipboard
var onNearbyChanged: () -> Unit?

Called whenever the sites heard on the local network change

Link copied to clipboard
var onPeersChanged: () -> Unit?

Called whenever a site joins or leaves the peers of the cluster, its threads included

Link copied to clipboard

The sites the cluster is federated with, its threads included

Link copied to clipboard

Whether the sites linking to this cluster must present its code, or the token of a pairing made with it: refused otherwise, and after a few wrong codes from an address its codes are refused for a while

Link copied to clipboard

The cluster as a solver of arg2p: any goal, its solutions and their graphs, the answers of queries

Link copied to clipboard

What the federation does, as the cluster knows it: the sites, and the last evaluation it answered (see Site.stats)

Functions

Link copied to clipboard
fun add(clause: String)

Adds clause, as Prolog text, to the theory

Link copied to clipboard
fun close()

Closes the links to the other sites, and stops the threads

Link copied to clipboard
fun connect(url: String, code: String? = null): Promise<Unit>

Federates the cluster with the site listening at url (ws://host:port), presenting code if it requires one

Link copied to clipboard
fun discover(beaconPort: Int = Beacons.PORT, requireCode: Boolean = false): Promise<Int>

Federates the cluster with the clusters of the local network that discover the others as well, as they come (see Beacons): it listens (on an ephemeral port, if it did not already), and its beacons go to beaconPort. With requireCode (see requiresCode), the clusters heard are nearby alone, linked to once paired by hand (pair), and linked again with no code from then on. The port it listens on, once its beacons start.

Link copied to clipboard
fun listen(port: Int = 0): Promise<Int>

Accepts the links of other sites (on any platform) over WebSockets, on port (an ephemeral port for 0): the port taken

Link copied to clipboard
fun load(theory: String)

Replaces the theory with theory, as Prolog text

Link copied to clipboard

A new code, the one before refused from now on (the pairings made stay)

Link copied to clipboard
fun pair(site: String, code: String): Promise<Unit>

Links this cluster to site, nearby, presenting code: the two paired, linked again with no code while they run; rejected if it refuses the code (or no site nearby is site)

Link copied to clipboard
fun reset()

Forgets the theory

Link copied to clipboard

The arguments for statement, as Prolog text, by label