Master
Master
- Full name:
\Hazaar\Warlock\Server\Master
Properties
instance
Singleton instance.
public static ?\Hazaar\Warlock\Server\Master $instance
- This property is static.
config
public static \Hazaar\Warlock\Config $config
- This property is static.
tasks
Main task queue.
public \Hazaar\Warlock\Server\Task[] $tasks
protocol
public static \Hazaar\Warlock\Protocol $protocol
- This property is static.
pcntlSignals
Signals that we will capture.
public array<int,string> $pcntlSignals
cluster
public ?\Hazaar\Warlock\Server\Cluster $cluster
silent
Enable silent mode.
private bool $silent
running
private bool $running
shutdown
private ?int $shutdown
tags
Task tags.
private \Hazaar\Warlock\Server\Task[] $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
stats
private array<string,int> $stats
rrd
private \Hazaar\File\Metric $rrd
log
private \Hazaar\Warlock\Server\Logger $log
services
Application services.
private \Hazaar\Warlock\Server\Task\Service[] $services
subscriptions
The wait queue. Clients subscribe to events and are added to this array.
private array<string,array> $subscriptions
events
The Event queue. Holds active events waiting to be seen.
private array<string,array> $events
globals
The global event queue. Holds details about tasks that need to start up to process global events.
private array<string,callable> $globals
master
The main socket for listening for incomming connections.
private resource $master
streams
Currently connected stream resources we are listening for data on.
private resource[] $streams
clients
Currently connected clients.
private \Hazaar\Warlock\Server\Client[] $clients
admins
private \Hazaar\Warlock\Server\Client[] $admins
kvStore
private ?\Hazaar\Warlock\Server\KVStore $kvStore
exitCodes
private array<int,array<string,int|string>> $exitCodes
Methods
__construct
Warlock server constructor.
public __construct(string $env = APPLICATION_ENV, bool $silent = false): mixed
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(): mixed
__errorHandler
final public __errorHandler(int $errno, string $errstr, ?string $errfile = null, ?int $errline = null): ?bool
- This method is final.
Parameters:
Parameter | Type | Description |
---|---|---|
$errno | int | |
$errstr | string | |
$errfile | ?string | |
$errline | ?int |
__exceptionHandler
final public __exceptionHandler(\Throwable $e): void
- This method is final.
Parameters:
Parameter | Type | Description |
---|---|---|
$e | \Throwable |
__signalHandler
private static __signalHandler(int $signo, mixed $siginfo): void
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$signo | int | |
$siginfo | mixed |
loadConfig
public loadConfig(): \Hazaar\Warlock\Config|false
shutdown
Initiate a server shutdown.
public shutdown(int $delay = null): 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 |
Return Value:
Returns true unless a shutdown has already been requested
getRuntimePath
Returns the application runtime directory.
public getRuntimePath(mixed $suffix = null, mixed $create_dir = false): string
The runtime directory is a place where HazaarMVC will keep files that it needs to create during normal operation. For example, cached views, and backend applications.
Parameters:
Parameter | Type | Description |
---|---|---|
$suffix | mixed | An optional suffix to tack on the end of the path |
$create_dir | mixed | if the runtime directory does not yet exist, try and create it (requires write permission) |
Return Value:
The path to the runtime directory
Throws:
bootstrap
Prepares the server ready to get up and running.
public bootstrap(): \Hazaar\Warlock\Server\Master
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.
Return Value:
Returns the server instance
run
The main server run loop.
public run(): int
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.
Return Value:
Returns an exit code indicating why the server is exiting. 0 means nice shutdown.
authorise
public authorise(\Hazaar\Warlock\Server\Client $client, string $key): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$client | \Hazaar\Warlock\Server\Client | |
$key | string |
disconnect
public disconnect(resource $stream): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$stream | resource |
processCommand
Process administative commands for a client.
public processCommand(\Hazaar\Warlock\Server\Client $client, mixed $command, mixed& $payload): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$client | \Hazaar\Warlock\Server\Client | |
$command | mixed | |
$payload | mixed |
trigger
public trigger(string $eventID, mixed $data, ?string $clientID = null, ?string $triggerID = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$eventID | string | |
$data | mixed | |
$clientID | ?string | |
$triggerID | ?string |
subscribe
Subscribe a client to an event.
public subscribe(\Hazaar\Warlock\Server\Client $client, string $eventID, array<string,mixed> $filter = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$client | \Hazaar\Warlock\Server\Client | The client to subscribe |
$eventID | string | The event ID to subscribe to |
$filter | array<string,mixed> | Any event filters |
unsubscribe
Unsubscibe a client from an event.
public unsubscribe(\Hazaar\Warlock\Server\Client $client, string $eventID): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$client | \Hazaar\Warlock\Server\Client | The client to unsubscribe |
$eventID | string | The event ID to unsubscribe from |
announce
public announce(): void
clientAdd
public clientAdd(resource $stream, ?\Hazaar\Warlock\Server\Client $client = null): \Hazaar\Warlock\Server\Client|false
Parameters:
Parameter | Type | Description |
---|---|---|
$stream | resource | |
$client | ?\Hazaar\Warlock\Server\Client |
clientReplace
public clientReplace(mixed $stream, ?\Hazaar\Warlock\Server\Client $client = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$stream | mixed | |
$client | ?\Hazaar\Warlock\Server\Client |
clientRemove
Removes a client from a stream.
public clientRemove(mixed $stream): bool
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.
Return Value:
True if the server is running. False otherwise.
clientGet
Retrieve a client object for a stream resource.
private clientGet(resource $stream): ?\Hazaar\Warlock\Server\Client
Parameters:
Parameter | Type | Description |
---|---|---|
$stream | resource | The stream resource |
clientProcess
private clientProcess(resource $stream): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$stream | resource |
clientCheck
private clientCheck(): void
getStatus
private getStatus(bool $full = true): array
Parameters:
Parameter | Type | Description |
---|---|---|
$full | bool |
spawn
private spawn(\Hazaar\Warlock\Server\Client $client, string $name, array $options): false|string
Parameters:
Parameter | Type | Description |
---|---|---|
$client | \Hazaar\Warlock\Server\Client | |
$name | string | |
$options | array |
kill
private kill(\Hazaar\Warlock\Server\Client $client, string $name): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$client | \Hazaar\Warlock\Server\Client | |
$name | string |
signal
private signal(\Hazaar\Warlock\Server\Client $client, string $eventID, string $service, mixed $data = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$client | \Hazaar\Warlock\Server\Client | |
$eventID | string | |
$service | string | |
$data | mixed |
scheduleRunner
private scheduleRunner(int $start, \stdClass $exec, \Hazaar\Warlock\Server\Struct\Application $application, ?string $tag = null, bool $overwrite = false): false|string
Parameters:
Parameter | Type | Description |
---|---|---|
$start | int | |
$exec | \stdClass | |
$application | \Hazaar\Warlock\Server\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(\Hazaar\Warlock\Server\Task $task): void
Parameters:
Parameter | Type | Description |
---|---|---|
$task | \Hazaar\Warlock\Server\Task |
taskQueueAdd
private taskQueueAdd(\Hazaar\Warlock\Server\Task $task): void
Parameters:
Parameter | Type | Description |
---|---|---|
$task | \Hazaar\Warlock\Server\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 = null): 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 |
Return Value:
returns true if the event should be filtered (skipped), and false if the event should be processed
eventProcess
Process the event queue for a specified client.
private eventProcess(\Hazaar\Warlock\Server\Client $client, string $eventID, array $filter = null): 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 | \Hazaar\Warlock\Server\Client | |
$eventID | string | |
$filter | array |
subscriptionProcess
Process all subscriptions for a specified event.
private subscriptionProcess(string $eventID, ?string $triggerID = null): 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 |
callable
private callable(mixed $value): null|array
Parameters:
Parameter | Type | Description |
---|---|---|
$value | mixed |
rotateLogFiles
private rotateLogFiles(int $logfiles): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$logfiles | int |
Automatically generated on 2024-11-14