KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > StandAloneAppClientModulesManager


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.server;
25
26 import com.sun.enterprise.admin.event.AdminEventListenerException;
27 import com.sun.enterprise.admin.event.AdminEventListenerRegistry;
28 import com.sun.enterprise.admin.event.BaseDeployEvent;
29 import com.sun.enterprise.admin.event.DeployEventListenerHelper;
30 import com.sun.enterprise.admin.event.ModuleDeployEvent;
31 import com.sun.enterprise.admin.event.ModuleDeployEventListener;
32 import com.sun.enterprise.appclient.jws.AppclientJWSSupportManager;
33 import com.sun.enterprise.config.ConfigException;
34 import com.sun.enterprise.deployment.backend.DeployableObjectType;
35 import com.sun.enterprise.deployment.node.J2EEDocumentBuilder;
36 import com.sun.enterprise.instance.AppclientModulesManager;
37 import com.sun.enterprise.management.StateManageable;
38 import com.sun.enterprise.util.i18n.StringManager;
39 import com.sun.logging.LogDomains;
40 import java.util.Hashtable JavaDoc;
41 import java.util.logging.Level JavaDoc;
42 import java.util.logging.Logger JavaDoc;
43 import javax.management.MBeanException JavaDoc;
44
45
46 /**
47  * AppClientModules Manager acts as a listener for the deployment events.
48  *
49  * @author Sreenivas Munnangi
50  * @since JDK1.4
51  */

52
53 class StandAloneAppClientModulesManager extends AbstractManager
54     implements ModuleDeployEventListener {
55
56     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER);
57     private static StringManager localStrings = StringManager.getManager(
58             "com.sun.enterprise.server");
59
60     /**
61      * Application Client Modules Manager
62      */

63     StandAloneAppClientModulesManager(
64     AppclientModulesManager acModuleManager, ClassLoader JavaDoc sharedCL) {
65
66     super(sharedCL, acModuleManager);
67
68         AdminEventListenerRegistry.addModuleDeployEventListener(this);
69
70         /* Make sure the manager is alive to receive all start-up load events. */
71         AppclientJWSSupportManager.getInstance();
72
73     }
74
75     /**
76      * Invoked when a standalone application client module is deployed.
77      */

78     public synchronized void moduleDeployed(ModuleDeployEvent event)
79         throws AdminEventListenerException {
80
81
82         boolean jsr77 = false;
83
84         if (_logger.isLoggable(Level.FINEST)) {
85             _logger.log(Level.FINEST,
86                 "In StandAloneAppClientModulesManager moduleDeployed");
87             _logger.log(Level.FINEST, "ModuleType=" + event.getModuleType());
88         }
89
90         if (event.getModuleType().equals(event.TYPE_APPCLIENT)) {
91
92             DeployEventListenerHelper.getDeployEventListenerHelper().synchronize(event);
93
94             String JavaDoc modID = event.getModuleName();
95
96             if (_logger.isLoggable(Level.FINEST)) {
97                 _logger.log(Level.FINEST, "modID=" + modID);
98             }
99
100             try {
101                 // refreshes the config context with the context from this event
102
this.configManager.refreshConfigContext(event.getConfigContext());
103
104                 // set jsr77 flag
105
// which is used to signify if the event is deploy or undeploy
106
// to create or delete jsr77 mBeans
107
String JavaDoc action = event.getAction();
108                 if ((action.equals(BaseDeployEvent.DEPLOY)) ||
109                         (action.equals(BaseDeployEvent.REDEPLOY))) {
110                     jsr77 = true;
111                 }
112
113                 if (!moduleDeployed(jsr77, modID)) {
114
115                     // throw an exception if load fails
116
String JavaDoc msg = localStrings.getString("appClientModule deploy failed",
117                             modID);
118                     throw new AdminEventListenerException(msg);
119                 }
120             } catch (ConfigException ce) {
121                 throw new AdminEventListenerException(ce.getMessage());
122             }
123         }
124     }
125
126
127     /**
128      * Invoked when a standalone application client module is undeployed.
129      */

130
131     public synchronized void moduleUndeployed(ModuleDeployEvent event)
132         throws AdminEventListenerException {
133
134         boolean jsr77 = false;
135
136         if (_logger.isLoggable(Level.FINEST)) {
137             _logger.log(Level.FINEST,
138                 "In StandAloneAppClientModulesManager moduleUndeployed");
139         }
140
141         String JavaDoc action = event.getAction();
142
143         if ((action.equals(BaseDeployEvent.UNDEPLOY)) ||
144                 (action.equals(BaseDeployEvent.REDEPLOY))) {
145             jsr77 = true;
146         }
147
148         try {
149             if (event.getModuleType().equals(event.TYPE_APPCLIENT)) {
150                 String JavaDoc modID = event.getModuleName();
151
152                 if (_logger.isLoggable(Level.FINEST)) {
153                     _logger.log(Level.FINEST, "UnDeploying module: " + modID);
154                 }
155
156                 // unload and throw exception if it fails
157
if (!moduleUndeployed(jsr77, modID)) {
158                     String JavaDoc msg = localStrings.getString("appclient.appclient_undeployed_failed",
159                             modID);
160                     throw new AdminEventListenerException(msg);
161                 }
162
163             }
164         } catch (Exception JavaDoc e) {
165             throw new AdminEventListenerException(e.getMessage());
166         }
167
168     }
169
170
171     /**
172      * Invoked when a standalone application client module is redeployed.
173      */

174
175     public synchronized void moduleRedeployed(ModuleDeployEvent event)
176         throws AdminEventListenerException {
177
178         if (_logger.isLoggable(Level.FINEST)) {
179             _logger.log(Level.FINEST,
180                 "In StandAloneAppClientModulesManager moduleRedeployed");
181         }
182
183         if (event.getModuleType().equals(event.TYPE_APPCLIENT)) {
184
185             String JavaDoc modID = event.getModuleName();
186
187             if (_logger.isLoggable(Level.FINEST)) {
188                 _logger.log(Level.FINEST, "ReDeploying module: " + modID);
189             }
190
191             moduleUndeployed(event);
192             moduleDeployed(event);
193         }
194     }
195
196     /**
197      * Invoked when a standalone application client module is enabled.
198      */

199     public synchronized void moduleEnabled(ModuleDeployEvent event)
200         throws AdminEventListenerException {
201
202         if (_logger.isLoggable(Level.FINEST)) {
203             _logger.log(Level.FINEST,
204                 "In StandAloneAppClientModulesManager moduleEnabled");
205         }
206
207     // for an application client module
208
// the operations enable/disable or start/stop do not make sense
209

210     return;
211     }
212
213
214     /**
215      * Invoked when a standalone application client module is disabled.
216      */

217
218     public synchronized void moduleDisabled(ModuleDeployEvent event)
219         throws AdminEventListenerException {
220
221         if (_logger.isLoggable(Level.FINEST)) {
222             _logger.log(Level.FINEST,
223                 "In StandAloneAppClientModulesManager moduleDisabled");
224         }
225
226     // for an application client module
227
// the operations enable/disable or start/stop do not make sense
228

229     return;
230     }
231
232
233     /**
234      * Deployed event handling
235      */

236
237     private boolean moduleDeployed(boolean jsr77, String JavaDoc modID) {
238
239     boolean result = false;
240         boolean loadJSR77 = jsr77 || loadJSR77(modID, DeployableObjectType.CAR);
241     try {
242             AbstractLoader modLoader = getLoader(modID);
243
244             // create root mBean for this module
245
if (loadJSR77) {
246                 try {
247                     modLoader.createRootMBean();
248                 } catch (MBeanException JavaDoc mbe) {
249                     _logger.log(Level.WARNING,
250                         "core.error_while_creating_jsr77_root_mbean",mbe);
251                 }
252             }
253
254             result = modLoader.load(loadJSR77);
255             if (result) {
256                 this.id2loader.put(modID, modLoader);
257             }
258     } catch (Exception JavaDoc ce) {
259             _logger.log(Level.WARNING,
260                 "core.error_while_loading_application_client_module",ce);
261             result = false;
262     }
263
264         return result;
265     }
266
267
268     /**
269      * Undeployed event handling
270      */

271
272     private boolean moduleUndeployed(boolean jsr77, String JavaDoc modID) {
273
274     boolean result = false;
275         try {
276             ApplicationClientModuleLoader modLoader =
277                 (ApplicationClientModuleLoader) this.id2loader.remove(modID);
278
279             if (modLoader == null) {
280                 return true;
281             }
282
283             // delete root mBean for this module
284
if (jsr77) {
285                 try {
286                     modLoader.deleteRootMBean();
287                 } catch (MBeanException JavaDoc mbe) {
288                     _logger.log(Level.WARNING,
289                         "core.error_while_deleting_jsr77_root_mbean",mbe);
290                     }
291             }
292
293             result = modLoader.unload(jsr77);
294
295         } catch (Exception JavaDoc ce) {
296             _logger.log(Level.WARNING,
297                     "core.error_while_unloading_application_client_module",ce);
298             result = false;
299     }
300
301         return result;
302     }
303
304     /**
305      * Returns loader
306      */

307
308     protected AbstractLoader getLoader(String JavaDoc moduleId) {
309     return new ApplicationClientModuleLoader(
310             moduleId,
311             this.parentClassLoader,
312             (AppclientModulesManager) this.configManager);
313     }
314
315  
316 /**
317      * Invoked when a reference is created from a
318      * server instance (or cluster) to a particular module.
319      *
320      * @throws AdminEventListenerException when the listener is unable to
321      * process the event.
322      */

323     public void moduleReferenceAdded(ModuleDeployEvent event)
324             throws AdminEventListenerException {
325                 
326 }
327
328     /**
329      * Invoked when a reference is removed from a
330      * server instance (or cluster) to a particular module.
331      *
332      * @throws AdminEventListenerException when the listener is unable to
333      * process the event.
334      */

335     public void moduleReferenceRemoved(ModuleDeployEvent event)
336             throws AdminEventListenerException {
337                 
338     }
339
340 }
341
Popular Tags