Completed
Pull Request — master (#1105)
by Tim
42:55
created

BeanManagerFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 73
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A visit() 0 62 1
1
<?php
2
3
/**
4
 * \AppserverIo\Appserver\PersistenceContainer\BeanManagerFactory
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Bernhard Wick <[email protected]>
15
 * @author    Tim Wagner <[email protected]>
16
 * @copyright 2015 TechDivision GmbH <[email protected]>
17
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
 * @link      https://github.com/appserver-io/appserver
19
 * @link      http://www.appserver.io
20
 */
21
22
namespace AppserverIo\Appserver\PersistenceContainer;
23
24
use AppserverIo\Storage\StackableStorage;
25
use AppserverIo\Storage\GenericStackable;
26
use AppserverIo\Psr\Application\ApplicationInterface;
27
use AppserverIo\Appserver\Core\Api\Node\ManagerNodeInterface;
28
use AppserverIo\Appserver\Core\Interfaces\ManagerFactoryInterface;
29
use AppserverIo\Appserver\PersistenceContainer\GarbageCollectors\StandardGarbageCollector;
30
use AppserverIo\Appserver\PersistenceContainer\RemoteMethodInvocation\RemoteProxyGenerator;
31
use AppserverIo\Appserver\PersistenceContainer\GarbageCollectors\StartupBeanTaskGarbageCollector;
32
33
/**
34
 * The bean manager handles the message and session beans registered for the application.
35
 *
36
 * @author    Bernhard Wick <[email protected]>
37
 * @author    Tim Wagner <[email protected]>
38
 * @copyright 2015 TechDivision GmbH <[email protected]>
39
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
40
 * @link      https://github.com/appserver-io/appserver
41
 * @link      http://www.appserver.io
42
 */
43
class BeanManagerFactory implements ManagerFactoryInterface
44
{
45
46
    /**
47
     * The main method that creates new instances in a separate context.
48
     *
49
     * @param \AppserverIo\Psr\Application\ApplicationInterface         $application          The application instance to register the class loader with
50
     * @param \AppserverIo\Appserver\Core\Api\Node\ManagerNodeInterface $managerConfiguration The manager configuration
51
     *
52
     * @return void
53
     */
54
    public static function visit(ApplicationInterface $application, ManagerNodeInterface $managerConfiguration)
55
    {
56
57
        // initialize the bean locator
58
        $beanLocator = new BeanLocator();
59
60
        // initialize the proxy generator
61
        $remoteProxyGenerator = new RemoteProxyGenerator();
62
        $remoteProxyGenerator->injectApplication($application);
63
64
        // initialize the request context
65
        $requestContext = array();
66
67
        // initialize the stackable for the data, the stateful + singleton session beans and the naming directory
68
        $data = new StackableStorage();
69
        $instances = new GenericStackable();
70
        $startupBeanTasks = new GenericStackable();
71
        $singletonSessionBeans = new StackableStorage();
72
        $statefulSessionBeans = new StatefulSessionBeanMap();
73
74
        // initialize the default settings for the stateful session beans
75
        $beanManagerSettings = new BeanManagerSettings();
76
        $beanManagerSettings->mergeWithParams($managerConfiguration->getParamsAsArray());
77
78
        // create an instance of the object factory
79
        $objectFactory = new GenericObjectFactory();
80
        $objectFactory->injectInstances($instances);
81
        $objectFactory->injectApplication($application);
82
        $objectFactory->start();
83
84
        // add a garbage collector and timer service workers for each application
85
        $garbageCollector = new StandardGarbageCollector();
86
        $garbageCollector->injectApplication($application);
87
        $garbageCollector->start();
88
89
        // add a garbage collector for the startup bean tasks
90
        $startupBeanTaskGarbageCollector = new StartupBeanTaskGarbageCollector();
91
        $startupBeanTaskGarbageCollector->injectApplication($application);
92
        $startupBeanTaskGarbageCollector->start();
93
94
        // initialize the bean manager
95
        $beanManager = new BeanManager();
96
        $beanManager->injectData($data);
97
        $beanManager->injectApplication($application);
98
        $beanManager->injectResourceLocator($beanLocator);
99
        $beanManager->injectObjectFactory($objectFactory);
100
        $beanManager->injectRequestContext($requestContext);
101
        $beanManager->injectStartupBeanTasks($startupBeanTasks);
102
        $beanManager->injectGarbageCollector($garbageCollector);
103
        $beanManager->injectManagerSettings($beanManagerSettings);
104
        $beanManager->injectRemoteProxyGenerator($remoteProxyGenerator);
105
        $beanManager->injectStatefulSessionBeans($statefulSessionBeans);
0 ignored issues
show
Bug introduced by
$statefulSessionBeans of type AppserverIo\Appserver\Pe...\StatefulSessionBeanMap is incompatible with the type AppserverIo\Storage\StorageInterface expected by parameter $statefulSessionBeans of AppserverIo\Appserver\Pe...tStatefulSessionBeans(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

105
        $beanManager->injectStatefulSessionBeans(/** @scrutinizer ignore-type */ $statefulSessionBeans);
Loading history...
106
        $beanManager->injectSingletonSessionBeans($singletonSessionBeans);
107
        $beanManager->injectDirectories($managerConfiguration->getDirectories());
108
        $beanManager->injectStartupBeanTaskGarbageCollector($startupBeanTaskGarbageCollector);
109
110
        // create the naming context and add it the manager
111
        $contextFactory = $managerConfiguration->getContextFactory();
112
        $contextFactory::visit($beanManager);
113
114
        // attach the instance
115
        $application->addManager($beanManager, $managerConfiguration);
0 ignored issues
show
Bug introduced by
The method addManager() does not exist on AppserverIo\Psr\Application\ApplicationInterface. It seems like you code against a sub-type of AppserverIo\Psr\Application\ApplicationInterface such as AppserverIo\Appserver\Application\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

115
        $application->/** @scrutinizer ignore-call */ 
116
                      addManager($beanManager, $managerConfiguration);
Loading history...
116
    }
117
}
118