AppserverIo\Appserver\MessageQueue\QueueWorker::injectApplication PHP Метод

injectApplication() публичный Метод

Inject the application instance the worker is bound to.
public injectApplication ( AppserverIo\Psr\Application\ApplicationInterface $application ) : void
$application AppserverIo\Psr\Application\ApplicationInterface The application instance
Результат void
    public function injectApplication(ApplicationInterface $application)
    {
        $this->application = $application;
    }

Usage Example

Пример #1
0
 /**
  * This method will be invoked before the while() loop starts and can be used
  * to implement some bootstrap functionality.
  *
  * @return void
  */
 public function bootstrap()
 {
     // register the default autoloader
     require SERVER_AUTOLOADER;
     // synchronize the application instance and register the class loaders
     $application = $this->application;
     $application->registerClassLoaders();
     // create a reference to the workers/messages
     $workers = $this->workers;
     $messages = $this->messages;
     $queueSettings = $this->queueSettings;
     // try to load the profile logger
     if ($this->profileLogger = $application->getInitialContext()->getLogger(LoggerUtils::PROFILE)) {
         $this->profileLogger->appendThreadContext(sprintf('message-queue-%s', $this->getName()));
     }
     // prepare the storages
     $jobsToExceute = array();
     // initialize the counter for the storages
     $counter = 0;
     // create a separate queue for each priority
     foreach (PriorityKeys::getAll() as $priorityKey) {
         // create the containers for the worker
         $jobsToExceute[$counter] = new GenericStackable();
         // initialize and start the queue worker
         $queueWorker = new QueueWorker();
         $queueWorker->injectMessages($messages);
         $queueWorker->injectApplication($application);
         $queueWorker->injectPriorityKey($priorityKey);
         $queueWorker->injectQueueSettings($queueSettings);
         // attach the storages
         $queueWorker->injectJobsToExecute($jobsToExceute[$counter]);
         // start the worker instance
         $queueWorker->start();
         // add the queue instance to the module
         $workers[$this->uniqueWorkerName($priorityKey)] = $queueWorker;
         // raise the counter
         $counter++;
     }
 }