Exemplo n.º 1
0
Arquivo: Basic.php Projeto: cwcw/cms
 /**
  * Run the controller. Dequeues signals from the SW Engine's internal queue and
  * notifies the listeners that a signal from SW Engine has been received
  *
  * @return void
  */
 public function run()
 {
     $timeout = $this->_options[self::OPT_TIMEOUT];
     Streamwide_Engine_Logger::info('Going to main loop');
     for (;;) {
         // Fetch a new signal from the SW Engine's queue
         $signal = Streamwide_Engine_Signal::dequeue(array('timeout' => $timeout));
         if (false === $signal) {
             continue;
         }
         // Update the loggers event items
         Streamwide_Engine_Logger::updateLogEventItems(array($signal->getPhpId() => $signal->getParams()));
         // Log the received signal
         Streamwide_Engine_Logger::dump($signal->toArray(), 'Received event from SW Engine:');
         if ($signal->getName() === Streamwide_Engine_Signal::CREATE) {
             // We have received a CREATE (new call), we need to create a new application to handle
             // the call
             if (false === ($application = $this->_createNewApplication($signal))) {
                 continue;
             }
             // Add the new application to the controller's running apps storage (will call
             // the application's start method)
             $this->addApp($signal->getPhpId(), $application);
         } else {
             // We have received a signal from SW Engine, we need to notify the listeners
             $event = new Streamwide_Engine_Events_Event($signal->getName());
             $event->setParam('signal', $signal);
             $this->dispatchEvent($event);
         }
     }
 }
Exemplo n.º 2
0
Arquivo: Signal.php Projeto: cwcw/cms
 /**
  * Sends a signal to SW Engine
  *
  * @param integer $retries If as_send_event returns false, we can retry to send the signal
  * @return boolean
  */
 public function send($retries = 0)
 {
     if (!is_int($retries)) {
         $retries = (int) $retries;
     }
     $array = $this->toArray();
     do {
         Streamwide_Engine_Logger::dump($array, 'Sending to SW Engine:');
         $sent = $this->_engineProxy->sendEvent($array);
         Streamwide_Engine_Logger::info(sprintf('Signal "%s" %s sent to SW Engine', $array[self::SIG_NAME], $sent === true ? 'successfully' : 'unsuccessfully'));
         $retries--;
     } while (false === $sent && $retries > 0);
     return $sent;
 }