The SIG object is the representation of a signal. Every SIG object is represented as an index, with each index being a valid indexable value. By default a SIG will generate it's index based simply on the value of the function get_class. The SIG object allows for unique signals by creating a child of SIG with the property of _unique set as true. .. note:: When a SIG is declared unique any index assigned to the SIG on construct will be ignored.
Since: 0.3.0
Inheritance: use trait State
Ejemplo n.º 1
0
 /**
  * Deletes a signal from the database.
  *
  * @param  object  $signal  \XPSPL\SIG
  *
  * @return  void
  */
 public function delete_signal(\XPSPL\SIG $signal)
 {
     if ($this->offsetExists($signal->get_index())) {
         $this->offsetUnset($signal->get_index());
         return;
     }
     return;
 }
Ejemplo n.º 2
0
 /**
  * Socket signals use the connection and socket hash for an index.
  *
  * For global socket signal the info can be left null.
  * 
  * @return  void
  */
 public function __construct($connection = null, $socket = null)
 {
     if (null !== $socket) {
         $this->socket = $socket;
     }
     parent::__construct();
     if (null === $connection) {
         return;
     }
     $this->_index = spl_object_hash($connection) . '.' . get_class($this);
 }
Ejemplo n.º 3
0
 /**
  * Construct new finished signal.
  *
  * @param  object  \ftp\SIG_Upload
  */
 public function __construct(\ftp\SIG_Upload $sig_upload, $index = null)
 {
     $this->_ftp_sig = $sig_upload;
     parent::__construct($index);
 }
Ejemplo n.º 4
0
 /**
  * Executes a processes database.
  *
  * If XPSPL_EXHAUSTION_PURGE is true processes will be purged once they
  * reach exhaustion.
  *
  * @param  object  $sig \XPSPL\SIG
  * @param  object  $db  \XPSPL\database\Processes
  *
  * @return  void
  */
 private function _processes_execute(SIG $signal, Processes $db)
 {
     if (XPSPL_DEBUG) {
         logger(XPSPL_LOG)->debug(sprintf('%s Process DB Executing %s processes', $db, $db->count()));
     }
     $db->reset();
     foreach ($db as $_process) {
         # Always check state first
         if ($signal->get_state() === STATE_HALTED) {
             break;
         }
         # n+1 constant
         if ($_process instanceof Processes) {
             if (XPSPL_DEBUG) {
                 logger(XPSPL_LOG)->debug('Descending into a sub-database executing ' . $_process->count() . ' processes');
             }
             $this->_processes_execute($signal, $_process);
         } else {
             if (XPSPL_DEBUG) {
                 logger(XPSPL_LOG)->debug(sprintf('Executing Process %s', get_class($_process) . ' : ' . $_process));
             }
             $_process->decrement_exhaust();
             if (XPSPL_THREAD_SUPPORT && $_process->threads_enabled()) {
                 // DO NOT EXECUTE THE SAME PROCESS WHILE ANOTHER IS RUNNING
                 $_running = False;
                 foreach ($this->active_threads as $_key => $_thread) {
                     if ($_thread[0] === $_process) {
                         $_running = True;
                     }
                 }
                 if ($_running) {
                     continue;
                 }
                 $thread = $_process->get_thread($signal);
                 $this->active_threads[] = [$_process, $thread];
                 $thread->start();
                 if (XPSPL_DEBUG) {
                     logger(XPSPL_LOG)->debug(sprintf('Starting thread %s %s', end($this->active_threads)[1], get_class($_process) . ' : ' . $_process));
                 }
             } else {
                 if (false === $this->_process_exec($signal, $_process->get_function())) {
                     if (XPSPL_DEBUG) {
                         logger(XPSPL_LOG)->debug(sprintf('Halting Signal %s due to false return from %s', $signal, get_class($_process) . ' : ' . $_process));
                     }
                     $signal->halt();
                 }
             }
             if ($_process->is_exhausted()) {
                 if (XPSPL_DEBUG) {
                     logger(XPSPL_LOG)->debug(sprintf('Process %s Exhausted', get_class($_process) . ' : ' . $_process));
                 }
                 $db->delete($_process);
             }
         }
     }
 }