abstract class SystemDaemonThreaded extends SystemDaemon

Base Class for a Threaded System Daemon

Constants

private THREAD_CONFIG_CHECK_INTERVAL

Properties

array $cmd_params from  SystemDaemon
string $daemon_name from  SystemDaemon
string $module_name from  SystemDaemon
mixed $view from  SystemDaemon
int $sleep_between_process from  SystemDaemon
int $process_counter from  SystemDaemon
mixed $mod_registry from  SystemDaemon
mixed $shutdown from  SystemDaemon
string $sleeping from  SystemDaemon
array $messages from  SystemDaemon
protected float|int $requestCacheClearingTime from  SystemDaemon
protected int $lastRequestCacheClearingTime from  SystemDaemon
protected int $maxThreadCount
protected $threadLifetimeCycles

Methods

__construct()

put your comment there.

__destruct()

No description

void
afterThreadFinished(string $threadIdentifier, int $threadProcessId, int $exitStatus)

Gets called if a thread finishes It can be used e.g. to clean up unfinished work in case of an ABORTED exit status

void
beforeNewThreadStart(string $threadIdentifier, array $threadOptions)

Gets calles before a Thread is being started Use this place to e.g. initialize/update static caches which can be reused in each thread to avoid init within each thread

void
beforeProcess()

Gets called during each management process loop It can be used e.g. to clean up unfinished work in case of an ABORTED exit status

beginThread()

Gets called within a thread before running the execite loop

endThread()

Gets called within a thread before stopping thread

int
getRequiredThreadCount()

Returns the number of required Threads By default this is the maximum number of configured threads but best-practise is to make this adaptive by your workload and use your queue length to adjust the thread count to reduce the number of running threads during low load situations

array
getThreadConfig()

Returns an array with all threads which should run and their options By default we use the configured number of Max Threads

halt()

No description

bool
handleProcessThread(string $threadIdentifier, array $threadOptions)

Default Entry Point for each Thread which covers the basic abort checks and thread lifetime handling

bool
isShutdown()

Returns true if the daemon process is in the shutdown phase to be ended

void
load_module_instances(mixed $module)

No description

message(string $message, string $level = Logger::INFO)

Daemon message

onStartup()

Gets called once on daemon startup Use this place to prepare daemon

void
onThreadError(string $threadIdentifier, int $threadProcessId, int $exitStatus)

Gets called if a thread exits with an error code It can be used e.g. to clean up unfinished work in case of an ABORTED exit status

process()

Main Daemon Process used to orchestrate all working threads Important: Must not contain any blocking operations

bool
processThread(string $threadIdentifier, array $threadOptions)

No description

registerSignalHandler()

No description

static 
restart_all()

Restart all Daemons

signalHandler(int $signo, mixed $siginfo)

No description

start()

No description

static 
start_all(bool $if_running_on_this_node = false)

Start all Daemons

static 
stop_all(bool $if_running_on_this_node = false)

Stop all Daemons

Details

in SystemDaemon at line 102
__construct()

put your comment there.

..

in SystemDaemon at line 359
__destruct()

No description

at line 222
void afterThreadFinished(string $threadIdentifier, int $threadProcessId, int $exitStatus)

Gets called if a thread finishes It can be used e.g. to clean up unfinished work in case of an ABORTED exit status

Parameters

string $threadIdentifier
int $threadProcessId
int $exitStatus

Return Value

void

at line 210
void beforeNewThreadStart(string $threadIdentifier, array $threadOptions)

Gets calles before a Thread is being started Use this place to e.g. initialize/update static caches which can be reused in each thread to avoid init within each thread

Parameters

string $threadIdentifier
array $threadOptions

Return Value

void

at line 241
void beforeProcess()

Gets called during each management process loop It can be used e.g. to clean up unfinished work in case of an ABORTED exit status

Return Value

void

at line 31
beginThread()

Gets called within a thread before running the execite loop

at line 38
endThread()

Gets called within a thread before stopping thread

at line 199
int getRequiredThreadCount()

Returns the number of required Threads By default this is the maximum number of configured threads but best-practise is to make this adaptive by your workload and use your queue length to adjust the thread count to reduce the number of running threads during low load situations

Return Value

int

Number of Threads

at line 181
array getThreadConfig()

Returns an array with all threads which should run and their options By default we use the configured number of Max Threads

Return Value

array

Thread Configuration - keyed array with the threadIdentifier as key and an assoc array with the threadOptions

in SystemDaemon at line 332
halt()

No description

at line 60
final bool handleProcessThread(string $threadIdentifier, array $threadOptions)

Default Entry Point for each Thread which covers the basic abort checks and thread lifetime handling

Parameters

string $threadIdentifier
array $threadOptions

Return Value

bool

in SystemDaemon at line 224
bool isShutdown()

Returns true if the daemon process is in the shutdown phase to be ended

Return Value

bool

in SystemDaemon at line 165
void load_module_instances(mixed $module)

No description

Parameters

mixed $module

Return Value

void

Exceptions

Exception

in SystemDaemon at line 309
message(string $message, string $level = Logger::INFO)

Daemon message

Parameters

string $message

Message

string $level

Logger::XXXX

in SystemDaemon at line 324
onStartup()

Gets called once on daemon startup Use this place to prepare daemon

at line 233
void onThreadError(string $threadIdentifier, int $threadProcessId, int $exitStatus)

Gets called if a thread exits with an error code It can be used e.g. to clean up unfinished work in case of an ABORTED exit status

Parameters

string $threadIdentifier
int $threadProcessId
int $exitStatus

Return Value

void

at line 101
final process()

Main Daemon Process used to orchestrate all working threads Important: Must not contain any blocking operations

at line 50
abstract bool processThread(string $threadIdentifier, array $threadOptions)

No description

Parameters

string $threadIdentifier
array $threadOptions

Return Value

bool

Return true

in SystemDaemon at line 367
protected registerSignalHandler()

No description

in SystemDaemon at line 110
static restart_all()

Restart all Daemons

in SystemDaemon at line 381
signalHandler(int $signo, mixed $siginfo)

No description

Parameters

int $signo
mixed $siginfo

in SystemDaemon at line 183
start()

No description

in SystemDaemon at line 125
static start_all(bool $if_running_on_this_node = false)

Start all Daemons

Parameters

bool $if_running_on_this_node

True will only start daemons which are known to have run on this node before they were stopped

in SystemDaemon at line 145
static stop_all(bool $if_running_on_this_node = false)

Stop all Daemons

Parameters

bool $if_running_on_this_node

True will only stop daemons which are known to run on this node