Master
Master
Properties
instance
public Master $instance
config
public Config $config
tasks
Main task queue.
public array $tasks
protocol
public Protocol $protocol
pcntlSignals
Signals that we will capture.
public array $pcntlSignals = array (
'SIGINT' => 'SIGINT',
'SIGHUP' => 'SIGHUP',
'SIGTERM' => 'SIGTERM',
'SIGQUIT' => 'SIGQUIT',
)
cluster
public Cluster $cluster
silent
Enable silent mode.
private bool $silent
running
private bool $running
shutdown
public int $shutdown
tags
Task tags.
private array $tags
start
Epoch of when Warlock was started.
private int $start
time
Epoch of the last time stuff was processed.
private int $time
pid
Current process id.
private int $pid
pidfile
Current process id file.
private string $pidfile
tv
Default select() timeout.
private int $tv = 1
stats
private $stats = array (
'clients' => 0,
0 => NULL,
'processed' => 0,
1 => NULL,
'execs' => 0,
2 => NULL,
'lateExecs' => 0,
3 => NULL,
'failed' => 0,
4 => NULL,
'tasks' => 0,
5 => NULL,
'processes' => 0,
6 => NULL,
'retries' => 0,
7 => NULL,
'limitHits' => 0,
8 => NULL,
'events' => 0,
9 => NULL,
'subscriptions' => 0,
10 => NULL,
)
rrd
private Metric $rrd
log
private Logger $log
services
Application services.
private array $services
subscriptions
The wait queue. Clients subscribe to events and are added to this array.
private array $subscriptions
events
The Event queue. Holds active events waiting to be seen.
private array $events
globals
The global event queue. Holds details about tasks that need to start up to process global events.
private array $globals
master
The main socket for listening for incomming connections.
private $master
streams
Currently connected stream resources we are listening for data on.
private $streams
clients
Currently connected clients.
private $clients
admins
private array $admins
kvStore
public KVStore $kvStore
exitCodes
private array $exitCodes = array (
1 =>
array (
'lvl' => 'W_ERR',
'msg' => 'Service failed to start because the application failed to decode the start payload.',
),
2 =>
array (
'lvl' => 'W_ERR',
'msg' => 'Service failed to start because the application runner does not understand the start payload type.',
),
3 =>
array (
'lvl' => 'W_ERR',
'msg' => 'Service failed to start because service class does not exist.',
),
4 =>
array (
'lvl' => 'W_WARN',
'msg' => 'Service exited because it lost the control channel.',
'restart' => true,
),
5 =>
array (
'lvl' => 'W_WARN',
'msg' => 'Dynamic service failed to start because it has no runOnce() method!',
),
6 =>
array (
'lvl' => 'W_INFO',
'msg' => 'Service exited because it\\\'s source file was modified.',
'restart' => true,
'reset' => true,
),
7 =>
array (
'lvl' => 'W_WARN',
'msg' => 'Service exited due to an exception.',
'restart' => true,
),
)
Methods
__construct
Warlock server constructor.
public __construct(string $env = 'APPLICATION_ENV', bool $silent = false): void
The constructor here is responsible for setting up internal structures, initialising logging, RRD logging, redirecting output to log files and configuring error and exception handling.
Parameters
Parameter | Type | Description |
---|---|---|
$env | string | |
$silent | bool | By default, log output will be displayed on the screen. Silent mode will redirect all |
log output to a file. |
__destruct
Final cleanup of the PID file and logs the exit.
public __destruct(): void
__errorHandler
public __errorHandler(int $errno, string $errstr, ?string $errfile, ?int $errline): bool
Parameters
Parameter | Type | Description |
---|---|---|
$errno | int | |
$errstr | string | |
$errfile | string | |
$errline | int |
__exceptionHandler
public __exceptionHandler(\Throwable $e): void
Parameters
Parameter | Type | Description |
---|---|---|
$e | \Throwable |
__signalHandler
private __signalHandler(int $signo, mixed $siginfo): void
Parameters
Parameter | Type | Description |
---|---|---|
$signo | int | |
$siginfo | mixed |
loadConfig
public loadConfig(): false
shutdown
Initiate a server shutdown.
public shutdown(?int $delay): bool
Because this server manages running services, it's not really a good idea to just simply exist abruptly. This method will initiate a server shutdown which will nicely stop all services and once all services stop, the server will terminate safely.
Parameters
Parameter | Type | Description |
---|---|---|
$delay | int | how long in seconds before the shutdown should commence |
getRuntimePath
Returns the application runtime directory.
public getRuntimePath(NULL $suffix, boolean $create_dir = false): void
The runtime directory is a place where Hazaar will keep files that it needs to create during normal operation. For example, cached views, and backend applications.
Parameters
Parameter | Type | Description |
---|---|---|
$suffix | NULL | An optional suffix to tack on the end of the path |
$create_dir | boolean | if the runtime directory does not yet exist, try and create it (requires write permission) |
bootstrap
Prepares the server ready to get up and running.
public bootstrap(): void
Bootstrapping the server allows us to restart an existing server instance without having to reinstantiate it which allows the server to essentially restart itself in memory.
run
The main server run loop.
public run(): void
This method will not return for as long as the server is running. While it is running it will process tasks, monitor services and distribute server signals.
authorise
public authorise(Client $client, string $key): bool
Parameters
Parameter | Type | Description |
---|---|---|
$client | Client | |
$key | string |
disconnect
public disconnect(mixed $stream): bool
Parameters
Parameter | Type | Description |
---|---|---|
$stream | mixed |
processCommand
Process administative commands for a client.
public processCommand(Client $client, mixed $command, mixed $payload): void
Parameters
Parameter | Type | Description |
---|---|---|
$client | Client | |
$command | mixed | |
$payload | mixed |
trigger
public trigger(string $eventID, mixed $data, ?string $clientID, ?string $triggerID): bool
Parameters
Parameter | Type | Description |
---|---|---|
$eventID | string | |
$data | mixed | |
$clientID | string | |
$triggerID | string |
subscribe
Subscribe a client to an event.
public subscribe(Client $client, string $eventID, ?array $filter): bool
Parameters
Parameter | Type | Description |
---|---|---|
$client | Client | The client to subscribe |
$eventID | string | The event ID to subscribe to |
$filter | array | Any event filters |
unsubscribe
Unsubscibe a client from an event.
public unsubscribe(Client $client, string $eventID): bool
Parameters
Parameter | Type | Description |
---|---|---|
$client | Client | The client to unsubscribe |
$eventID | string | The event ID to unsubscribe from |
announce
public announce(): void
clientAdd
public clientAdd(mixed $stream, ?Client $client): false
Parameters
Parameter | Type | Description |
---|---|---|
$stream | mixed | |
$client | Client |
clientReplace
public clientReplace(mixed $stream, ?Client $client): bool
Parameters
Parameter | Type | Description |
---|---|---|
$stream | mixed | |
$client | Client |
clientRemove
Removes a client from a stream.
public clientRemove(mixed $stream): void
Because a client can have multiple stream connections (in legacy mode) this removes the client reference for that stream. Once there are no more references left the client is completely removed.
Parameters
Parameter | Type | Description |
---|---|---|
$stream | mixed |
isRunning
Check if the server is already running.
private isRunning(): bool
This checks if the PID file exists, grabs the PID from that file and checks to see if a process with that ID is actually running.
clientGet
Retrieve a client object for a stream resource.
private clientGet(mixed $stream): ?Client
Parameters
Parameter | Type | Description |
---|---|---|
$stream | mixed | The stream resource |
clientProcess
private clientProcess(mixed $stream): bool
Parameters
Parameter | Type | Description |
---|---|---|
$stream | mixed |
clientCheck
private clientCheck(): void
getStatus
private getStatus(bool $full = true): void
Parameters
Parameter | Type | Description |
---|---|---|
$full | bool |
spawn
private spawn(Client $client, string $name, array $options): string
Parameters
Parameter | Type | Description |
---|---|---|
$client | Client | |
$name | string | |
$options | array |
kill
private kill(Client $client, string $name): bool
Parameters
Parameter | Type | Description |
---|---|---|
$client | Client | |
$name | string |
signal
private signal(Client $client, string $eventID, string $service, mixed $data): bool
Parameters
Parameter | Type | Description |
---|---|---|
$client | Client | |
$eventID | string | |
$service | string | |
$data | mixed |
scheduleRunner
private scheduleRunner(int $start, \stdClass $exec, Struct\Application $application, ?string $tag, bool $overwrite = false): string
Parameters
Parameter | Type | Description |
---|---|---|
$start | int | |
$exec | \stdClass | |
$application | Struct\Application | |
$tag | string | |
$overwrite | bool |
taskCancel
private taskCancel(string $taskID): bool
Parameters
Parameter | Type | Description |
---|---|---|
$taskID | string |
taskProcess
Main process loop.
private taskProcess(): int
This method will monitor and manage queued running tasks.
taskMonitor
private taskMonitor(Task $task): void
Parameters
Parameter | Type | Description |
---|---|---|
$task | Task |
taskQueueAdd
private taskQueueAdd(Task $task): void
Parameters
Parameter | Type | Description |
---|---|---|
$task | Task |
eventCleanup
private eventCleanup(): void
fieldExists
private fieldExists(array $search, \stdClass $array): bool
Parameters
Parameter | Type | Description |
---|---|---|
$search | array | |
$array | \stdClass |
getFieldValue
private getFieldValue(array $search, \stdClass $array): mixed
Parameters
Parameter | Type | Description |
---|---|---|
$search | array | |
$array | \stdClass |
eventFilter
Tests whether a event should be filtered.
private eventFilter(mixed $event, ?array $filter): bool
Returns true if the event should be filtered (skipped), and false if the event should be processed.
Parameters
Parameter | Type | Description |
---|---|---|
$event | mixed | the event to check |
$filter | array | the filter rule to test against |
eventProcess
Process the event queue for a specified client.
private eventProcess(Client $client, string $eventID, ?array $filter): bool
This method is executed when a client connects to see if there are any events waiting in the event queue that the client has not yet seen. If there are, the first event found is sent to the client, marked as seen and then processing stops.
Parameters
Parameter | Type | Description |
---|---|---|
$client | Client | |
$eventID | string | |
$filter | array |
subscriptionProcess
Process all subscriptions for a specified event.
private subscriptionProcess(string $eventID, ?string $triggerID): bool
This method is executed when a event is triggered. It is responsible for sending events to clients that are waiting for the event and marking them as seen by the client.
Parameters
Parameter | Type | Description |
---|---|---|
$eventID | string | |
$triggerID | string |
serviceEnable
private serviceEnable(string $name): bool
Parameters
Parameter | Type | Description |
---|---|---|
$name | string |
serviceDisable
private serviceDisable(string $name): bool
Parameters
Parameter | Type | Description |
---|---|---|
$name | string |
private (mixed $value): void
Parameters
Parameter | Type | Description |
---|---|---|
$value | mixed |
rotateLogFiles
private rotateLogFiles(int $logfiles = 0): bool
Parameters
Parameter | Type | Description |
---|---|---|
$logfiles | int |
Generated by Hazaar API Doc Generator