/** * Deploys the message queues. * * @param \AppserverIo\Psr\Application\ApplicationInterface|\AppserverIo\Psr\Naming\NamingDirectoryInterface $application The application instance * * @return void */ protected function registerMessageQueues(ApplicationInterface $application) { // build up META-INF directory var $metaInfDir = $this->getWebappPath() . DIRECTORY_SEPARATOR . 'META-INF'; // check if we've found a valid directory if (is_dir($metaInfDir) === false) { return; } // initialize the array for the creating the subdirectories $this->directories = new GenericStackable(); $this->directories[] = $application->getNamingDirectory(); // check META-INF + subdirectories for XML files with MQ definitions /** @var \AppserverIo\Appserver\Core\Api\DeploymentService $service */ $service = $application->newService('AppserverIo\\Appserver\\Core\\Api\\DeploymentService'); $xmlFiles = $service->globDir(AppEnvironmentHelper::getEnvironmentAwareGlobPattern($this->getWebappPath(), 'META-INF' . DIRECTORY_SEPARATOR . 'message-queues')); // load the configuration service instance /** @var \AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */ $configurationService = $application->newService('AppserverIo\\Appserver\\Core\\Api\\ConfigurationService'); // load the container node to initialize the system properties /** @var \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $containerNode */ $containerNode = $application->getContainer()->getContainerNode(); // gather all the deployed web applications foreach ($xmlFiles as $file) { try { // validate the file here, but skip if the validation fails $configurationService->validateFile($file, null, true); // load the system properties $properties = $service->getSystemProperties($containerNode); // append the application specific properties $properties->add(SystemPropertyKeys::WEBAPP, $webappPath = $application->getWebappPath()); $properties->add(SystemPropertyKeys::WEBAPP_NAME, basename($webappPath)); $properties->add(SystemPropertyKeys::WEBAPP_CACHE, $application->getCacheDir()); $properties->add(SystemPropertyKeys::WEBAPP_SESSION, $application->getSessionDir()); // create a new message queue node instance and replace the properties $messageQueuesNode = new MessageQueuesNode(); $messageQueuesNode->initFromFile($file); $messageQueuesNode->replaceProperties($properties); // register the entity managers found in the configuration foreach ($messageQueuesNode->getMessageQueues() as $messageQueueNode) { $this->registeMessageQueue($messageQueueNode); } } catch (InvalidConfigurationException $e) { // try to load the system logger instance /** @var \Psr\Log\LoggerInterface $systemLogger */ if ($systemLogger = $this->getApplication()->getInitialContext()->getSystemLogger()) { $systemLogger->error($e->getMessage()); $systemLogger->critical(sprintf('Persistence configuration file %s is invalid, needed queues might be missing.', $file)); } } catch (\Exception $e) { // try to load the system logger instance /** @var \Psr\Log\LoggerInterface $systemLogger */ if ($systemLogger = $this->getApplication()->getInitialContext()->getSystemLogger()) { $systemLogger->error($e->__toString()); } } } }
/** * Deploys the entity manager described by the passed XML node. * * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance * @param \AppserverIo\Appserver\Core\Api\PersistenceUnitNodeInterface $persistenceUnitNode The XML node that describes the entity manager * * @return void */ public function registerEntityManager(ApplicationInterface $application, PersistenceUnitNodeInterface $persistenceUnitNode) { // initialize the the entity manager instance $this->entityManagers[$lookupName = $persistenceUnitNode->getName()] = $persistenceUnitNode; // bind the callback for the entity manager instance to the // naming directory => necessary for DI provider $application->getNamingDirectory()->bind(sprintf('php:global/%s/%s', $application->getUniqueName(), $lookupName), array(&$this, 'lookup'), array($lookupName)); }
/** * Deploys the message queues. * * @param \AppserverIo\Psr\Application\ApplicationInterface|\AppserverIo\Psr\Naming\NamingDirectoryInterface $application The application instance * * @return void */ protected function registerMessageQueues(ApplicationInterface $application) { // build up META-INF directory var $metaInfDir = $this->getWebappPath() . DIRECTORY_SEPARATOR . 'META-INF'; // check if we've found a valid directory if (is_dir($metaInfDir) === false) { return; } // check META-INF + subdirectories for XML files with MQ definitions /** @var \AppserverIo\Appserver\Core\Api\DeploymentService $service */ $service = $application->newService('AppserverIo\\Appserver\\Core\\Api\\DeploymentService'); $xmlFiles = $service->globDir($metaInfDir . DIRECTORY_SEPARATOR . 'message-queues.xml'); // initialize the array for the creating the subdirectories $this->directories = new GenericStackable(); $this->directories[] = $application->getNamingDirectory(); // gather all the deployed web applications foreach ($xmlFiles as $file) { try { // try to initialize a SimpleXMLElement $sxe = new \SimpleXMLElement($file, null, true); $sxe->registerXPathNamespace('a', 'http://www.appserver.io/appserver'); // lookup the MessageQueue's defined in the passed XML node if (($nodes = $sxe->xpath('/a:message-queues/a:message-queue')) === false) { continue; } // validate the file here, if it is not valid we can skip further steps try { /** @var \AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */ $configurationService = $application->newService('AppserverIo\\Appserver\\Core\\Api\\ConfigurationService'); $configurationService->validateFile($file, null, true); } catch (InvalidConfigurationException $e) { /** @var \Psr\Log\LoggerInterface $systemLogger */ $systemLogger = $this->getApplication()->getInitialContext()->getSystemLogger(); $systemLogger->error($e->getMessage()); $systemLogger->critical(sprintf('Message queue configuration file %s is invalid, needed queues might be missing.', $file)); return; } // iterate over all found queues and initialize them foreach ($nodes as $node) { $this->registeMessageQueue($node); } // if class can not be reflected continue with next class } catch (\Exception $e) { // log an error message $application->getInitialContext()->getSystemLogger()->error($e->__toString()); // proceed with the next queue continue; } } }