Class - XPSPL\Processor

Processor

The brainpower of XPSPL.

As of v0.3.0 the loop is now run in respect to the currently available handles, this prevents the processor from running contionusly forever when there isn’t anything that it needs to do.

To achieve this the processor uses routines for calculating when to run and shutdowns when no more are available.

The queue storage has also been improved in 0.3.0, previously the storage used a non-index and index based storage, the storage now uses only a single array.

Methods

__construct

__construct([$signal_history = true])

Starts the processor.

Parameters:boolean – Store a history of all signals.
Return type:void

_register_error_handler

_register_error_handler()

Registers the processor error signal handler.

TODO Create a suitable error handler

Return type:void

erase_history

erase_history()

Cleans out the event history.

Return type:void

loop

loop([$ttr = false])

Start the event loop.

Parameters:null|integer – Number of milliseconds to run the loop.
Return type:void

_routine

_routine()

Runs the complex signal routine for the processor loop.

Return type:boolean|array

get_routine

get_routine()

Returns the current routine object.

Return type:null|object

has_signal_exhausted

has_signal_exhausted($signal)

Determines if the given signal has exhausted.

Parameters:string|integer|object
Return type:boolean

queue_exhausted

queue_exhausted($queue)

Determine if all queue handles are exhausted.

Parameters:object – XPSPLQueue
Return type:boolean

remove_handle

remove_handle($signal, $handle)

Removes a signal handler.

Parameters:
  • mixed – Signal instance or signal.
  • mixed – Handle instance or identifier.
Return type:

void

flush

flush()

Empties the storage, history and clears the current state.

Return type:void

listen

listen($listener)

Registers an object listener.

Parameters:object – XPSPLListener
Return type:void

signal

signal($signal, $handle)

Creates a new signal handler.

Parameters:
  • string|int|object – Signal to attach the handle.
  • object – Signal handler
Return type:

object|boolean Handle, boolean if error

register_signal

register_signal($signal)

Registers a signal a new signal

Parameters:string|integer|object – Signal
Return type:boolean|object false|XPSPLQueue

search_signals

search_signals($signal[, $index = false])

Searches for a signal in storage returning its storage queue if found, optionally the index can be returned.

Parameters:
  • string|int|object – Signal to search for.
  • boolean – Return the index of the signal.
Return type:

null|object null|Queue

evaluate_signals

evaluate_signals($signal)

Runs the evaluation for the registered complex signals using the given signal.

Parameters:string|object|int – Signal to evaluate
Return type:array|null [[[signal, queue], eval_return]]

_event

_event($signal[, $event = false[, $ttl = false]])

Loads an event for the current signal.

Parameters:
  • int|string|object
  • object – XPSPLEvent
  • int|null – Event TTL
Return type:

object XPSPLEvent

_event_exit

_event_exit($event)

Exits the event from the processor.

Parameters:object – XPSPLEvent

emit

emit($signal[, $event = false[, $ttl = false]])

Emits a signal.

Parameters:
  • mixed – Signal instance or signal.
  • object – XPSPLEvent
Return type:

object Event

_execute

_execute($signal, $queue, $event[, $interrupt = true])

Executes a queue.

This will monitor the event status and break on a HALT or ERROR state.

Executes interruption functions before and after queue execution.

Parameters:
  • object – Signal instance.
  • object – Queue instance.
  • object – Event instance.
  • boolean – Run the interrupt functions.
Return type:

void

_queue_execute

_queue_execute($queue, $event)

Executes a queue.

If XPSPL_EXHAUSTION_PURGE is true handles will be purged once they reach exhaustion.

Parameters:
  • object – XPSPLQueue
  • object – XPSPLEvent
Return type:

void

_func_exec

_func_exec($function, $event)

Executes a callable processor function.

Parameters:
  • callable – Function to execute
  • object – Event context to execute within
Return type:

boolean

signal_history

signal_history()

Retrieves the signal history.

Return type:array

shutdown

shutdown()

Sends the processor the shutdown signal.

Return type:void

event_analysis

event_analysis()

Returns a json encoded array of the event history.

Return type:string

before

before($signal, $handle)

Registers a function to interrupt the signal stack before a signal fires, allowing for manipulation of the event beore it is passed to handles.

Parameters:
  • string|object – Signal instance or class name
  • object – Handle to execute
Return type:

boolean True|False false is failure

after

after($signal, $handle)

Registers a function to interrupt the signal stack after a signal fires, allowing for manipulation of the event after it is passed to handles.

Parameters:
  • string|object – Signal instance or class name
  • object – Handle to execute
Return type:

boolean True|False false is failure

_signal_interrupt

_signal_interrupt($signal, $handle[, $interrupt = false])

Registers a function to interrupt the signal stack before or after a signal fires.

Parameters:
  • string|object
  • object – Handle to execute
  • int|null – Interuption location. INTERUPT_PRE|INTERUPT_POST
Return type:

boolean True|False false is failure

_interrupt

_interrupt($signal, $type, $event)

Handle signal interuption functions.

Parameters:
  • object – Signal
  • int – Interupt type
Return type:

boolean

clean

clean([$history = false])

Cleans any exhausted signals from the processor.

Parameters:boolean – Erase any history of the signals cleaned.
Return type:void

delete_signal

delete_signal($signal[, $history = false])

Delete a signal from the processor.

Parameters:
  • string|object|int – Signal to delete.
  • boolean – Erase any history of the signal.
Return type:

boolean

erase_signal_history

erase_signal_history($signal)

Erases any history of a signal.

Parameters:string|object – Signal to be erased from history.
Return type:void

save_signal_history

save_signal_history($flag)

Sets the flag for storing the event history.

Note that this will delete the current if reset.

Parameters:boolean
Return type:void

current_signal

current_signal([$offset = 1])

Returns the current signal in execution.

Parameters:integer – In memory hierarchy offset +/-.
Return type:object

current_event

current_event([$offset = false])

Returns the current event.

Parameters:integer – In memory hierarchy offset +/-.
Return type:object XPSPLEvent

Constants

HASH_STORAGE

Storage container node indices

COMPLEX_STORAGE

INTERRUPT_STORAGE

INTERRUPT_PRE

Interuption Types

INTERRUPT_POST

Last updated on 02/01/13 07:27am