KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > management > systemstate > SystemStateImpl


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: SystemStateImpl.java 154 26 avr. 2006 ofabre $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.management.systemstate;
23
24 import java.util.List JavaDoc;
25
26 import org.objectweb.fractal.fraclet.annotation.FractalComponent;
27 import org.objectweb.fractal.fraclet.annotation.Interface;
28 import org.objectweb.fractal.fraclet.annotation.LifeCycle;
29 import org.objectweb.fractal.fraclet.annotation.LifeCycleType;
30 import org.objectweb.fractal.fraclet.annotation.Monolog;
31 import org.objectweb.fractal.fraclet.annotation.Provides;
32 import org.objectweb.fractal.fraclet.annotation.Requires;
33 import org.objectweb.petals.jbi.management.deployment.DeploymentService;
34 import org.objectweb.petals.jbi.management.service.InstallationService;
35 import org.objectweb.petals.jbi.management.service.LifeCycleManagerService;
36 import org.objectweb.petals.jbi.management.service.ManagementException;
37 import org.objectweb.petals.repository.RepositoryService;
38 import org.objectweb.petals.util.LoggingUtil;
39 import org.objectweb.util.monolog.api.Logger;
40
41 /**
42  * Allows to persist component, shared library and service assembly states and
43  * restore them after petals system shutdown or crash.
44  *
45  * @author Olivier Fabre - EBM Websourcing
46  */

47 @FractalComponent
48 @Provides(interfaces=@Interface(name="service",signature=org.objectweb.petals.jbi.management.systemstate.SystemState.class))
49 public class SystemStateImpl implements SystemState {
50
51     /**
52      * JBI Container :: Deployment Service
53      */

54     @Requires(name="deployment",signature=org.objectweb.petals.jbi.management.deployment.DeploymentService.class)
55     protected DeploymentService deploymentService;
56
57     /**
58      * JBI Container :: Installation Service
59      */

60     @Requires(name="installation",signature=org.objectweb.petals.jbi.management.service.InstallationService.class)
61     protected InstallationService installationService;
62
63     /**
64      * logger wrapper
65      */

66     protected LoggingUtil log;
67
68     /**
69      * Monolog Logger instance.
70      */

71     @Monolog(name="logger")
72     protected Logger logger;
73
74     /**
75      * JBI Container :: JMX Agent Admin
76      */

77     @Requires(name="lifecyclemanager",signature=org.objectweb.petals.jbi.management.service.LifeCycleManagerService.class)
78     protected LifeCycleManagerService managerService;
79
80     /**
81      * Platform Component :: Repository Service
82      */

83     @Requires(name="repository",signature=org.objectweb.petals.repository.RepositoryService.class)
84     protected RepositoryService repositorySrv;
85
86     protected StateStorage stateStorage;
87
88     protected SystemRecovery systemRecovery;
89
90     public ComponentState createComponentStateHolder(String JavaDoc componentName,
91             String JavaDoc installURL, String JavaDoc zipURL, String JavaDoc installState,
92             String JavaDoc lifecycleState) throws Exception JavaDoc {
93         return stateStorage.createComponentStateHolder(componentName,
94                 installURL, zipURL, installState, lifecycleState);
95     }
96
97     public ServiceAssemblyState createServiceAssemblyStateHolder(String JavaDoc saName,
98             String JavaDoc installURL, String JavaDoc zipURL, String JavaDoc lifecycleState)
99         throws Exception JavaDoc {
100         return stateStorage.createServiceAssemblyStateHolder(saName,
101                 installURL, zipURL, lifecycleState);
102     }
103
104     public SharedLibraryState createSharedLibraryStateHolder(String JavaDoc slName,
105             String JavaDoc installURL, String JavaDoc zipURL) throws Exception JavaDoc {
106         return stateStorage.createSharedLibraryStateHolder(slName, installURL,
107                 zipURL);
108     }
109
110     public ComponentState deleteComponentStateHolder(String JavaDoc componentName)
111         throws Exception JavaDoc {
112         return stateStorage.deleteComponentStateHolder(componentName);
113     }
114
115     public ServiceAssemblyState deleteServiceAssemblyStateHolder(String JavaDoc saName)
116         throws Exception JavaDoc {
117         return stateStorage.deleteServiceAssemblyStateHolder(saName);
118     }
119
120     public SharedLibraryState deleteSharedLibraryStateHolder(String JavaDoc slName)
121         throws Exception JavaDoc {
122         return stateStorage.deleteSharedLibraryStateHolder(slName);
123     }
124
125     public boolean recoverAllComponent() throws ManagementException {
126         return systemRecovery.recoverAllComponent();
127     }
128
129     public boolean recoverAllEntities() throws ManagementException {
130         log.start();
131         boolean result = false;
132
133         recoverAllSharedLibrary();
134         recoverAllComponent();
135         recoverAllServiceAssembly();
136         result = true;
137
138         log.end();
139         return result;
140     }
141
142     public boolean recoverAllServiceAssembly() throws ManagementException {
143         return systemRecovery.recoverAllServiceAssembly();
144     }
145
146     public boolean recoverAllSharedLibrary() throws ManagementException {
147         return systemRecovery.recoverAllSharedLibrary();
148     }
149
150     public List JavaDoc<ComponentState> retrieveAllComponentStates() {
151         return stateStorage.retrieveAllComponentStates();
152     }
153
154     public List JavaDoc<ServiceAssemblyState> retrieveAllServiceAssemblyStates() {
155         return stateStorage.retrieveAllServiceAssemblyStates();
156     }
157
158     // ----------------------------------------------------------------------
159
// Fractal BindingController implementation
160
// ----------------------------------------------------------------------
161

162     public List JavaDoc<SharedLibraryState> retrieveAllSharedLibraryStates() {
163         return stateStorage.retrieveAllSharedLibraryStates();
164     }
165
166     // ----------------------------------------------------------------------
167
// Fractal LifecycleController implementation
168
// ----------------------------------------------------------------------
169

170     public void updateComponentInstallationState(String JavaDoc componentName,
171             String JavaDoc installState) throws Exception JavaDoc {
172         stateStorage.updateComponentInstallationState(componentName,
173                 installState);
174
175     }
176
177     public void updateComponentLifeCycleState(String JavaDoc componentName,
178             String JavaDoc lifecycleState) throws Exception JavaDoc {
179         stateStorage.updateComponentLifeCycleState(componentName,
180                 lifecycleState);
181
182     }
183
184     public void updateServiceAssemblyState(String JavaDoc saName, String JavaDoc lifecycleState)
185         throws Exception JavaDoc {
186         stateStorage.updateServiceAssemblyState(saName, lifecycleState);
187
188     }
189
190     @LifeCycle(on=LifeCycleType.START)
191     protected void start() {
192         log = new LoggingUtil(logger);
193         log.start();
194
195         stateStorage = new StateStorage();
196
197         try {
198             stateStorage.init();
199         } catch (Exception JavaDoc e) {
200             String JavaDoc msg = "SystemState component can't be correctly initiated : "
201                     + "StateStorage init failed !";
202             log.error(msg, e);
203             throw new RuntimeException JavaDoc(msg);
204         }
205
206         systemRecovery = new SystemRecovery(installationService, logger,
207                 deploymentService, managerService, stateStorage, repositorySrv);
208
209         log.end();
210     }
211
212     @LifeCycle(on=LifeCycleType.STOP)
213     protected void stop() {
214         log.start();
215
216         logger = null;
217
218         log.end();
219     }
220 }
221
Popular Tags