Ejemplo n.º 1
0
Archivo: Basic.php Proyecto: 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);
         }
     }
 }