/** * The main method that creates new instances in a separate context. * * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance to register the class loader with * @param \AppserverIo\Appserver\Core\Api\Node\ManagerNodeInterface $managerConfiguration The manager configuration * * @return void */ public static function visit(ApplicationInterface $application, ManagerNodeInterface $managerConfiguration) { // create the initial context instance $initialContext = new NamingContext(); $initialContext->injectApplication($application); // initialize the stackable storage $data = new StackableStorage(); $servlets = new StackableStorage(); $initParameters = new StackableStorage(); $servletMappings = new GenericStackable(); $securedUrlConfigs = new StackableStorage(); $sessionParameters = new StackableStorage(); // initialize the servlet locator $servletLocator = new ServletLocator(); // initialize the servlet manager $servletManager = new ServletManager(); $servletManager->injectData($data); $servletManager->injectServlets($servlets); $servletManager->injectApplication($application); $servletManager->injectInitialContext($initialContext); $servletManager->injectInitParameters($initParameters); $servletManager->injectResourceLocator($servletLocator); $servletManager->injectServletMappings($servletMappings); $servletManager->injectSecuredUrlConfigs($securedUrlConfigs); $servletManager->injectSessionParameters($sessionParameters); $servletManager->injectDirectories($managerConfiguration->getDirectories()); // attach the instance $application->addManager($servletManager, $managerConfiguration); }
/** * The main method that creates new instances in a separate context. * * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance to register the class loader with * @param \AppserverIo\Appserver\Core\Api\Node\ManagerNodeInterface $managerConfiguration The manager configuration * * @return void */ public static function visit(ApplicationInterface $application, ManagerNodeInterface $managerConfiguration) { // create the initial context instance $initialContext = new NamingContext(); $initialContext->injectApplication($application); // create the storage for the reflection classes and the application specific aliases $reflectionClasses = new GenericStackable(); $namingDirectoryAliases = new GenericStackable(); // create and initialize the DI provider instance $provider = new Provider(); $provider->injectApplication($application); $provider->injectInitialContext($initialContext); $provider->injectReflectionClasses($reflectionClasses); $provider->injectNamingDirectoryAliases($namingDirectoryAliases); // attach the instance $application->addManager($provider, $managerConfiguration); }
/** * The main method that creates new instances in a separate context. * * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance to register the class loader with * @param \AppserverIo\Appserver\Core\Api\Node\ManagerNodeInterface $managerConfiguration The manager configuration * * @return void */ public static function visit(ApplicationInterface $application, ManagerNodeInterface $managerConfiguration) { // load the registered loggers $loggers = $application->getInitialContext()->getLoggers(); // initialize the bean locator $beanLocator = new BeanLocator(); // create the initial context instance $initialContext = new NamingContext(); $initialContext->injectApplication($application); // initialize the stackable for the data, the stateful + singleton session beans and the naming directory $data = new StackableStorage(); $instances = new GenericStackable(); $statefulSessionBeans = new StackableStorage(); $singletonSessionBeans = new StackableStorage(); // initialize the default settings for the stateful session beans $statefulSessionBeanSettings = new DefaultStatefulSessionBeanSettings(); $statefulSessionBeanSettings->mergeWithParams($managerConfiguration->getParamsAsArray()); // we need a factory instance for the stateful session bean instances $statefulSessionBeanMapFactory = new StatefulSessionBeanMapFactory($statefulSessionBeans); $statefulSessionBeanMapFactory->injectLoggers($loggers); $statefulSessionBeanMapFactory->start(); // create an instance of the object factory $objectFactory = new GenericObjectFactory(); $objectFactory->injectInstances($instances); $objectFactory->injectApplication($application); $objectFactory->start(); // add a garbage collector and timer service workers for each application $garbageCollector = new StandardGarbageCollector(); $garbageCollector->injectApplication($application); $garbageCollector->start(); // initialize the bean manager $beanManager = new BeanManager(); $beanManager->injectData($data); $beanManager->injectApplication($application); $beanManager->injectResourceLocator($beanLocator); $beanManager->injectObjectFactory($objectFactory); $beanManager->injectInitialContext($initialContext); $beanManager->injectGarbageCollector($garbageCollector); $beanManager->injectStatefulSessionBeans($statefulSessionBeans); $beanManager->injectSingletonSessionBeans($singletonSessionBeans); $beanManager->injectDirectories($managerConfiguration->getDirectories()); $beanManager->injectStatefulSessionBeanSettings($statefulSessionBeanSettings); $beanManager->injectStatefulSessionBeanMapFactory($statefulSessionBeanMapFactory); // attach the instance $application->addManager($beanManager, $managerConfiguration); }
/** * Creates a new naming context and add's it to the passed manager. * * @param \AppserverIo\Psr\Application\ManagerInterface $manager The manager to add the naming context to * * @return void */ public static function visit(ManagerSettingsAwareInterface $manager) { // load the path to the web application $application = $manager->getApplication(); $webappPath = $application->getWebappPath(); // initialize the variable for the properties $properties = null; // load the configuration base directory if ($baseDirectory = $manager->getManagerSettings()->getBaseDirectory()) { // look for naming context properties in the manager's base directory $propertiesFile = DirectoryKeys::realpath(sprintf('%s/%s/%s', $webappPath, $baseDirectory, NamingContextFactory::CONFIGURATION_FILE)); // load the properties from the configuration file if (file_exists($propertiesFile)) { $properties = Properties::create()->load($propertiesFile); } } // create the initial context instance $initialContext = new InitialContext($properties); $initialContext->injectApplication($application); // set the initial context in the manager $manager->injectInitialContext($initialContext); }
/** * We process the timer here. * * @return void */ public function run() { try { // register the default autoloader require SERVER_AUTOLOADER; // register shutdown handler register_shutdown_function(array(&$this, "shutdown")); // we need to register the class loaders again $application = $this->application; $application->registerClassLoaders(); // load application and message instance $message = $this->message; // load class name and session ID from remote method $queueProxy = $message->getDestination(); $sessionId = $message->getSessionId(); // lookup the queue and process the message if ($queue = $application->search('QueueContextInterface')->locate($queueProxy)) { // the queues receiver type $queueType = $queue->getType(); // create an intial context instance $initialContext = new InitialContext(); $initialContext->injectApplication($application); // lookup the bean instance $instance = $initialContext->lookup($queueType); // inject the application to the receiver and process the message $instance->onMessage($message, $sessionId); } // mark the job finished $this->finished = true; } catch (\Exception $e) { $application->getInitialContext()->getSystemLogger()->error($e->__toString()); } }
/** * Checks if the resource identifier will be initialized propertly * from a URL with app scope without interface. * * @return void */ public function testPopulateAppScopeWithoutInterface() { // populate the identifier with the data of the passed URL $resourceIdentifier = $this->initialContext->prepareResourceIdentifier(InitialContextTest::IDENTIFIER_APP); // check the data from the resource identifier $this->assertNull($resourceIdentifier->getContextName()); $this->assertSame(InitialContextTest::INDEX_FILE, $resourceIdentifier->getIndexFile()); $this->assertSame(InitialContextTest::CLASS_NAME, $resourceIdentifier->getClassName()); $this->assertSame(EnterpriseBeanResourceIdentifier::LOCAL_INTERFACE, $resourceIdentifier->getInterface()); }
/** * Responsible for invoking the timeout method on the target object. * * The timerservice implementation invokes this method as a callback when a timeout occurs for the * passed timer. The timerservice implementation will be responsible for passing the correct * timeout method corresponding to the <code>timer</code> on which the timeout has occurred. * * @param \AppserverIo\Psr\EnterpriseBeans\TimerInterface $timer The timer that is passed to timeout * @param \AppserverIo\Lang\Reflection\MethodInterface $timeoutMethod The timeout method * * @return void */ public function callTimeout(TimerInterface $timer, MethodInterface $timeoutMethod = null) { // synchronize the application instance and register the class loaders $application = $this->getApplication(); $application->registerClassLoaders(); // initialize the initial context instance $initialContext = new InitialContext(); $initialContext->injectApplication($application); // lookup the enterprise bean using the initial context $instance = $initialContext->lookup($this->getTimedObjectId()); // check if the timeout method has been passed if ($timeoutMethod != null) { // if yes, invoke it on the proxy $callback = array($instance, $timeoutMethod->getMethodName()); call_user_func_array($callback, array($timer)); return; } // check if we've a default timeout method if ($this->defaultTimeoutMethod != null) { // if yes, invoke it on the proxy $callback = array($instance, $this->defaultTimeoutMethod->getMethodName()); call_user_func_array($callback, array($timer)); return; } }