Priority database for signal processes.
Inheritance: extends XPSPL\Database
Beispiel #1
0
 /**
  * Installs a new process into the database.
  *
  * @param  object  $process  \XPSPL\Process
  *
  * @return  void
  */
 public function install(\XPSPL\Process $process)
 {
     if (XPSPL_DEBUG) {
         logger(XPSPL_LOG)->debug(sprintf('%s process install', $process));
     }
     $priority = $process->get_priority();
     if ($this->offsetExists($priority)) {
         if ($this->offsetGet($priority) instanceof Processes) {
             if (XPSPL_DEBUG) {
                 logger(XPSPL_LOG)->debug(sprintf('%s sub-database root', $this->offsetGet($priority)));
                 logger(XPSPL_LOG)->debug(sprintf('%s next priority', $this->offsetGet($priority)->end()->get_priority() + 1));
             }
             $process->set_priority($this->offsetGet($priority)->end()->get_priority() + 1);
             $this->offsetGet($priority)->install($process);
         } else {
             if (XPSPL_DEBUG) {
                 logger(XPSPL_LOG)->debug(sprintf('%s create sub-database', $this->offsetGet($priority)));
             }
             $this->offsetGet($priority)->set_priority(XPSPL_SUBDATABASE_DEFAULT_PRIORITY);
             $db = new Processes();
             $db->install($this->offsetGet($priority));
             $this->offsetUnset($priority);
             $this->offsetSet($priority, $db);
             $this->install($process);
         }
     } else {
         if (XPSPL_DEBUG) {
             // var_dump($this->_storage);
             logger(XPSPL_LOG)->debug(sprintf('%s process installed NODE_COUNT(%s)', $process, $this->count()));
         }
         // var_dump($priority);
         // var_dump($process);
         $this->_storage[$priority] = $process;
     }
 }
Beispiel #2
0
 /**
  * Emits a signal.
  *
  * @param  object  $signal  \XPSPL\SIG
  *
  * @return  object  Event
  */
 public function emit(SIG $signal)
 {
     if (XPSPL_DEBUG) {
         logger(XPSPL_LOG)->debug(sprintf('%s emitted', $signal));
     }
     // Store the history of the signal
     if (false !== $this->_history) {
         $this->_history[] = [$signal, microtime()];
     }
     // Set child status
     if (count($this->_signal) > 1) {
         $signal->set_parent($this->current_signal());
     }
     // Check if signal is installed
     $memory = $this->find_signal_database($signal);
     if (null === $memory) {
         $memory = new \XPSPL\database\Processes();
     } else {
         if (XPSPL_DEBUG) {
             logger(XPSPL_LOG)->debug('Signal with no installed processes emitted');
         }
     }
     // Evaluate complex signals
     $evaluated = $this->evaluate_signals($signal);
     if (null !== $evaluated) {
         foreach ($evaluated as $_db) {
             $memory->merge($_db);
         }
     }
     // Execute if we have processes
     if ($memory->count() > 0) {
         // Set as currently executing signal
         $this->_signal[] = $signal;
         // Execute
         $this->_execute($signal, $memory);
         // Remove once finished
         array_pop($this->_signal);
     }
     return $signal;
 }
Beispiel #3
0
 /**
  * Determine if the given database processes are exhausted.
  *
  * @param  object  $queue  \XPSPL\database\Processes
  *
  * @return  boolean
  */
 public function are_processes_exhausted(\XPSPL\database\Processes $database)
 {
     if ($database->count() === 0) {
         return true;
     }
     $database->reset();
     while ($database->valid()) {
         if ($database->current() instanceof \XPSPL\database\Processes) {
             if (!$this->are_processes_exhausted($database->current())) {
                 return false;
             }
         } elseif (!$database->current()->is_exhausted()) {
             return false;
         }
         $database->next();
     }
     return true;
 }