|
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); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|