KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
25  * @(#) ApplicationManager.java
26  *
27  * Copyright 2000-2001 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  *
31  * This software is the confidential and proprietary information
32  * of iPlanet/Sun Microsystems, Inc. ("Confidential Information").
33  * You shall not disclose such Confidential Infolrmation and shall
34  * use it only in accordance with the terms of the license
35  * agreement you entered into with iPlanet/Sun Microsystems.
36  */

37 package com.sun.enterprise.server;
38
39 import com.sun.enterprise.appclient.jws.AppclientJWSSupportManager;
40 import java.io.File JavaDoc;
41 import java.util.List JavaDoc;
42 import java.util.ArrayList JavaDoc;
43 import java.net.URL JavaDoc;
44 import java.net.MalformedURLException JavaDoc;
45
46 import com.sun.enterprise.instance.AppsManager;
47 import com.sun.enterprise.config.ConfigException;
48
49 import com.sun.enterprise.admin.event.ApplicationDeployEvent;
50 import com.sun.enterprise.admin.event.ApplicationDeployEventListener;
51 import com.sun.enterprise.admin.event.AdminEventListenerRegistry;
52 import com.sun.enterprise.admin.event.AdminEventListenerException;
53 import com.sun.enterprise.admin.event.DeployEventListenerHelper;
54
55 import com.sun.enterprise.instance.InstanceEnvironment;
56 import com.sun.enterprise.security.acl.RoleMapper;
57 import com.sun.enterprise.server.pluggable.ApplicationLoaderFactory;
58 import com.sun.enterprise.server.pluggable.PluggableFeatureFactory;
59
60 import com.sun.enterprise.deployment.Application;
61
62 import com.sun.enterprise.util.i18n.StringManager;
63 import com.sun.enterprise.deployment.backend.Deployer;
64 import com.sun.enterprise.deployment.backend.DeployerFactory;
65 import com.sun.enterprise.deployment.backend.DeploymentRequest;
66 import com.sun.enterprise.deployment.backend.DeploymentCommand;
67 import com.sun.enterprise.deployment.backend.DeployableObjectType;
68 import com.sun.enterprise.deployment.backend.IASDeploymentException;
69 import com.sun.enterprise.deployment.autodeploy.AutoDirReDeployer;
70 import com.sun.enterprise.security.SecurityUtil;
71 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapper;
72 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactory;
73 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactoryMgr;
74 import com.sun.enterprise.security.util.IASSecurityException;
75
76 import com.sun.enterprise.config.ConfigContext;
77
78 import java.util.logging.Logger JavaDoc;
79 import java.util.logging.Level JavaDoc;
80 import com.sun.logging.LogDomains;
81
82 //for jsr77
83
import com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile;
84 import com.sun.enterprise.deployment.node.J2EEDocumentBuilder;
85 import com.sun.enterprise.admin.event.BaseDeployEvent;
86 import java.util.Iterator JavaDoc;
87 import com.sun.enterprise.deployment.EjbBundleDescriptor;
88 import javax.management.MBeanException JavaDoc;
89 //import com.sun.enterprise.management.model.J2EEDeployedObjectMdl;
90
import com.sun.enterprise.management.StateManageable;
91
92
93 /**
94  * Applicaton Manager manages all j2ee application for a server instance.
95  * It also acts as an listener for the deployment events. All the hot
96  * application deployment events are handled in this manager.
97  *
98  * @author Mahesh Kannan
99  * @author Nazrul Islam
100  * @since JDK1.4
101  */

102 public class ApplicationManager extends AbstractManager
103         implements ApplicationDeployEventListener {
104
105     /** logger to log core messages */
106     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER);
107
108     /** local string manager */
109     private static StringManager localStrings =
110                         StringManager.getManager(ApplicationManager.class);
111
112     private static final String JavaDoc RAR = "rar";
113
114     /**
115      * ApplicationManager is responsible for loading all applications in an
116      * instance. It creates a ApplicationLoader for each deployed application.
117      * ApplicationLader is responsible for further loading EJBContainers for
118      * each module in the Application.
119      *
120      * <p>
121      * It is assumed that the next two params are set by the Startup Code.
122      *
123      * @param appsManager The appsManager obtained through
124      * ConfigFactory.createAppsManager(ConfigCtx)
125      * @param commonclassLoader The top level class loader. For now this
126      * can be the MainThread's ClassLoader.
127      */

128     ApplicationManager(AppsManager appsManager,
129             ClassLoader JavaDoc connectorClassLoader) {
130
131         super(connectorClassLoader, appsManager);
132
133         AdminEventListenerRegistry.addApplicationDeployEventListener(this);
134         
135         /* Make sure the manager is alive to receive all start-up load events. */
136         AppclientJWSSupportManager.getInstance();
137     }
138
139     /**
140      * Returns an application loader for the given application id.
141      *
142      * @param id registration name of an application
143      *
144      * @return an application loader for this manager
145      */

146     protected AbstractLoader getLoader(String JavaDoc id) {
147         // get the appropriate loader
148
PluggableFeatureFactory featureFactory =
149             ApplicationServer.getServerContext().getPluggableFeatureFactory();
150         ApplicationLoaderFactory appLoaderFactory =
151             featureFactory.getApplicationLoaderFactory();
152         ApplicationLoader appLoader =
153             appLoaderFactory.createApplicationLoader(id,
154                 this.parentClassLoader,(AppsManager)this.configManager);
155         _logger.log(Level.FINEST,"ApplicationLoader "+appLoader);
156         return appLoader;
157     }
158
159     /**
160      * Loads the given application if enabled.
161      * This adds the application to the reload monitor list.
162      * This gets called when application is deployed.
163      *
164      * @param appID registration name of the application
165      *
166      * @return true if application is loaded successfully
167      */

168     boolean applicationDeployed(String JavaDoc appID) {
169         return applicationDeployed(false, appID, true);
170     }
171
172     /**
173      * Loads the given application if enabled.
174      * This adds the application to the reload monitor list.
175      * This gets called when application is deployed.
176      *
177      * @param appID registration name of the application
178      * @param jsr77 create jsr77 mBeans if it is true
179      *
180      * @return true if application is loaded successfully
181      */

182     boolean applicationDeployed(boolean jsr77, String JavaDoc appID) {
183         return applicationDeployed(jsr77, appID, true);
184     }
185
186     boolean applicationDeployed(boolean jsr77, String JavaDoc appID,
187         ConfigContext dynamicConfigContext)
188     {
189         return applicationDeployed(jsr77, appID, true,
190         dynamicConfigContext);
191     }
192
193     boolean applicationDeployed(boolean jsr77, String JavaDoc appID,
194             ConfigContext dynamicConfigContext, int loadUnloadAction)
195     {
196         return applicationDeployed(jsr77, appID, true,
197             dynamicConfigContext, loadUnloadAction);
198     }
199
200     /**
201      * Loads the given application if enabled.
202      *
203      * @param jsr77 create jsr77 mBeans if it is true
204      * @param appID registration name of the application
205      * @param addToRM if true, adds this application to reload
206      *
207      * @return true if application is loaded successfully
208      */

209     boolean applicationDeployed(boolean jsr77, String JavaDoc appID, boolean addToRM) {
210     return applicationDeployed(jsr77, appID, addToRM, null);
211     }
212     
213     boolean applicationDeployed(boolean jsr77, String JavaDoc appID, boolean addToRM,
214         ConfigContext dynamicConfigContext)
215     {
216         return applicationDeployed(jsr77, appID, addToRM, dynamicConfigContext,
217             Constants.LOAD_ALL);
218     }
219
220       
221     // Depending on the value of loadUnloadAction. we will do different things
222
// 1. LOAD_ALL is for loading regular application
223
// 2. LOAD_RAR is for loading the rar part of the embedded rar
224
// 3. LOAD_REST is for loading the rest part of the embedded rar
225
boolean applicationDeployed(boolean jsr77, String JavaDoc appID, boolean addToRM,
226             ConfigContext dynamicConfigContext, int loadUnloadAction)
227     {
228
229         boolean deployed = false;
230         boolean loadJSR77 = jsr77 || loadJSR77(appID, DeployableObjectType.APP);
231         AbstractLoader appLoader = null;
232         try {
233             if (this.configManager.isSystem(appID)) {
234                     return true;
235             }
236         } catch (ConfigException confEx) {
237              _logger.log(Level.WARNING,
238                          "core.error_while_loading_app", confEx);
239         }
240
241         try {
242             //set default value
243
if (loadUnloadAction == Constants.LOAD_UNSET) {
244                 loadUnloadAction = Constants.LOAD_ALL;
245             }
246
247             boolean handlePreLoadAction =
248                 (loadUnloadAction == Constants.LOAD_ALL ||
249                  loadUnloadAction == Constants.LOAD_RAR);
250
251             boolean handlePostLoadAction =
252                 (loadUnloadAction == Constants.LOAD_ALL ||
253                  loadUnloadAction == Constants.LOAD_REST);
254
255             // adds the app to be monitored if ON
256
if (handlePreLoadAction) {
257                 if (addToRM) {
258                     addToReloadMonitor(appID);
259                 }
260             }
261
262             // Check to see if the app is already loaded. If yes, do not
263
// reload.
264
if (id2loader.get(appID) != null) {
265                     return true;
266             }
267
268             // create new loader for loading rars or loading non-embedded-rar
269
// application
270
// and use the cached loader for the rest of the loading for
271
// embedded rar
272
if (handlePreLoadAction) {
273                 appLoader = getLoader(appID);
274                 /**
275                  *Add the apploader to the map now so that it can be cleaned
276                  *up later even if the load fails.
277                  */

278                 if (loadUnloadAction == Constants.LOAD_ALL) {
279                     id2loader.put(appID, appLoader);
280                 } else if (loadUnloadAction == Constants.LOAD_RAR) {
281                     id2loader.put(appID + RAR, appLoader);
282                 }
283             } else if (loadUnloadAction == Constants.LOAD_REST) {
284                 appLoader = (AbstractLoader) id2loader.remove(appID + RAR);
285                 if (appLoader != null) {
286                     id2loader.put(appID, appLoader);
287                 } else {
288                     return false;
289                 }
290             }
291
292         appLoader.setConfigContext(dynamicConfigContext);
293         appLoader.setLoadUnloadAction(loadUnloadAction);
294
295             // create jsr77 root Mbean for this application
296
// only do this for second part of the loading
297
if (handlePreLoadAction && loadJSR77) {
298                 try {
299                     appLoader.createRootMBean();
300                 } catch (MBeanException JavaDoc mbe) {
301                     _logger.log(Level.WARNING,"core.error_while_creating_jsr77_root_mbean",mbe);
302                 }
303             }
304
305             if (isEnabled(dynamicConfigContext, appID)) {
306
307                 _logger.log(Level.FINEST,
308                     "[ApplicationManager] Application is enabled: " + appID);
309
310
311                 // only do this for first part of the loading
312
if (handlePreLoadAction) {
313                     // set jsr77 state to STARTING
314
try {
315                         appLoader.setState(StateManageable.STARTING_STATE);
316                     } catch (MBeanException JavaDoc mbe) {
317                         _logger.log(Level.WARNING,
318                             "core.error_while_setting_jsr77_state",mbe);
319                     }
320                 }
321
322                 boolean retSts = appLoader.load(jsr77);
323                 deployed = retSts;
324
325                 if (handlePostLoadAction && retSts) {
326
327                     // set jsr77 state to RUNNING
328
try {
329                         appLoader.setState(StateManageable.RUNNING_STATE);
330                     } catch (MBeanException JavaDoc mbe) {
331                         _logger.log(Level.WARNING,
332                         "core.error_while_setting_jsr77_state",mbe);
333                     }
334
335                                     
336                     // application loaded
337
deployed = true;
338
339                     SecurityRoleMapperFactory factory = SecurityRoleMapperFactoryMgr.getFactory();
340
341                     if (factory==null) {
342                         throw new IllegalArgumentException JavaDoc(localStrings.getString(
343                         "enterprise.deployment.deployment.norolemapperfactorydefine",
344                         "This application has no role mapper factory defined"));
345                     }
346
347                 } else if (!retSts) {
348                     if (handlePreLoadAction && loadJSR77) {
349                         // delete leaf and root mBeans for this app
350
try {
351                             appLoader.deleteLeafAndRootMBeans();
352                         } catch (MBeanException JavaDoc mbe) {
353                             _logger.log(Level.WARNING,
354                             "core.error_while_deleting_jsr77_leaf_and_root_mbean",mbe);
355                         }
356                     } else if (!loadJSR77){
357                         // set jsr77 state to FAILED
358
try {
359                             appLoader.setState(StateManageable.FAILED_STATE);
360                         } catch (MBeanException JavaDoc mbe) {
361                             _logger.log(Level.WARNING,
362                             "core.error_while_setting_jsr77_state",mbe);
363                         }
364                     }
365                     /*
366                      *Release the app loader's resources so jar files can be
367                      *closed.
368                      */

369                     try {
370                         appLoader.done();
371                     } catch (Throwable JavaDoc thr) {
372                         String JavaDoc msg = localStrings.getString("core.application_not_loaded", appID);
373                         _logger.log(Level.INFO, msg, thr);
374                     }
375                     _logger.log(Level.WARNING,
376                                 "core.application_not_loaded", appID);
377                 }
378
379             } else {
380                 _logger.log(Level.INFO, "core.application_disabled", appID);
381                 deployed = false;
382             }
383         } catch (ConfigException confEx) {
384             _logger.log(Level.WARNING, "core.error_while_loading_app", confEx);
385         } finally {
386         //To ensure that the config context is not reused...
387
if (appLoader != null) {
388         appLoader.setConfigContext(null);
389         }
390     }
391
392         return deployed;
393     }
394
395
396     /**
397      * Unloads the given application.
398      * This removes the application from reload monitor list.
399      * This gets called when application is undeployed.
400      *
401      * @param appID registration name of the application
402      * @return true if application is unloaded successfully
403      */

404     boolean applicationUndeployed(String JavaDoc appID) {
405         return applicationUndeployed(false, appID, true);
406     }
407
408     /**
409      * Unloads the given application.
410      * This removes the application from reload monitor list.
411      * This gets called when application is undeployed.
412      *
413      * @param jsr77 deletes jsr77 mBeans if it is true
414      * @param appID registration name of the application
415      * @return true if application is unloaded successfully
416      */

417     boolean applicationUndeployed(boolean jsr77, String JavaDoc appID) {
418         return applicationUndeployed(jsr77, appID, true);
419     }
420
421     /**
422      * Unloads the given application.
423      *
424      * @param jsr77 delete jsr77 mBeans if it is true
425      * @param appID registration name of the application
426      * @param clearRM if true, removes this app from reload monitor
427      *
428      * @return true if application is unloaded successfully
429      */

430     boolean applicationUndeployed(boolean jsr77, String JavaDoc appID, boolean clearRM) {
431         return applicationUndeployed(jsr77, appID,clearRM, false);
432     }
433
434     
435     boolean applicationUndeployed(boolean jsr77, String JavaDoc appID, boolean clearRM, boolean cascade) {
436
437             return applicationUndeployed(jsr77, appID,clearRM, cascade, Constants.UNLOAD_ALL);
438         }
439
440     // Depending on the value of loadUnloadAction. we will do different things
441
// 1. UNLOAD_ALL is for unloading regular application
442
// 2. UNLOAD_RAR is for unloading the rar part of the embedded rar
443
// 3. UNLOAD_REST is for unloading the rest part of the embedded rar
444
boolean applicationUndeployed(boolean jsr77, String JavaDoc appID, boolean clearRM, boolean cascade, int loadUnloadAction) {
445
446         //set default value
447
if (loadUnloadAction == Constants.LOAD_UNSET) {
448             loadUnloadAction = Constants.UNLOAD_ALL;
449         }
450
451         boolean handlePreUnloadAction =
452             (loadUnloadAction == Constants.UNLOAD_ALL ||
453              loadUnloadAction == Constants.UNLOAD_REST);
454
455         boolean handlePostUnloadAction =
456             (loadUnloadAction == Constants.UNLOAD_ALL ||
457              loadUnloadAction == Constants.UNLOAD_RAR);
458
459         // removes this app from reload monitor
460
if (handlePreUnloadAction && clearRM) {
461             removeFromReloadMonitor(appID);
462         }
463
464         AbstractLoader appLoader = (AbstractLoader) id2loader.get(appID);
465
466         if (handlePostUnloadAction) {
467             appLoader = (AbstractLoader) id2loader.remove(appID);
468         }
469
470         // application is not in the registry
471
if ((appLoader == null) ||
472             (appLoader != null && appLoader.getApplication() == null)) {
473             return true;
474         }
475
476         appLoader.setCascade(cascade);
477         appLoader.setLoadUnloadAction(loadUnloadAction);
478         Application app = appLoader.getApplication();
479
480         if (handlePreUnloadAction) {
481             // set jsr77 state to STOPPING
482
try {
483                 appLoader.setState(StateManageable.STOPPING_STATE);
484             } catch (MBeanException JavaDoc mbe) {
485                 _logger.log(Level.WARNING,
486                     "core.error_while_setting_jsr77_state",mbe);
487             }
488
489             RoleMapper.removeRoleMapper(app.getRoleMapper().getName());
490
491             if (jsr77) {
492                 //delete jsr77 mbean
493
try {
494                     appLoader.deleteLeafAndRootMBeans();
495                 } catch (MBeanException JavaDoc mbe) {
496                     _logger.log(Level.WARNING,
497                         "core.error_while_deleting_jsr77_leaf_and_root_mbeans",mbe);
498                 }
499             } else {
500                 // set jsr77 state STOPPED
501
try {
502                     appLoader.setState(StateManageable.STOPPED_STATE);
503                 } catch (MBeanException JavaDoc mbe) {
504                     _logger.log(Level.WARNING,
505                        "core.error_while_setting_jsr77_state",mbe);
506                 }
507             }
508         
509         }
510
511         boolean undeployed = appLoader.unload(jsr77);
512
513         if (loadUnloadAction == Constants.UNLOAD_REST) {
514             return undeployed;
515         }
516
517         if (undeployed) {
518             // since web modules are loaded separately,
519
// at this point we can only claim ejbs to be
520
// loaded successfully
521
if (app.getEjbComponentCount() > 0) {
522                 _logger.log(Level.INFO,
523                         "core.application_unloaded_ejb", appID);
524             }
525         } else {
526             _logger.log(Level.INFO,
527                         "core.application_not_unloaded", appID);
528         }
529
530         return undeployed;
531     }
532
533
534     private void holdRequest() { }
535
536     private void holdRequest(String JavaDoc appID) { }
537
538     // ---- START OF MonitorListener METHODS ----------------------------------
539

540     /**
541      * This is a callback from realod monitor. This is called when the
542      * thread detects a change in the $APP_ROOT/.reload file's time stamp.
543      * This method reloads the application.
544      *
545      * <p> The time stamp is set when the callback is made in the entry.
546      *
547      * @param entry monitored entry with a change in time stamp
548      * @return if applicatoin was reloaded successfully
549      */

550     public synchronized boolean reload(MonitorableEntry entry) {
551
552         String JavaDoc appName = entry.getId();
553         boolean status = false;
554
555         try {
556             DeploymentRequest req = new DeploymentRequest(
557                             this.configManager.getInstanceEnvironment(),
558                             DeployableObjectType.APP,
559                             DeploymentCommand.DEPLOY);
560
561             // monitored file points to $APP_ROOT/.reload
562
req.setFileSource(entry.getMonitoredFile().getParentFile());
563
564             // application registration name
565
req.setName(appName);
566
567             // we are always trying a redeployment
568
req.setForced(true);
569             
570             AutoDirReDeployer deployer = new AutoDirReDeployer(req);
571             status = deployer.redeploy();
572
573         }
574         catch (IASDeploymentException de)
575     {
576             _logger.log(Level.WARNING,"core.error_while_redeploying_app",de);
577             return false;
578         }
579         return status;
580     }
581     // ---- END OF MonitorListener METHODS ------------------------------------
582

583
584     // ---- START OF ApplicationDeployEventListener METHODS ------------------
585

586     public synchronized void applicationDeployed(ApplicationDeployEvent event)
587             throws AdminEventListenerException {
588         try {
589             if (_logger.isLoggable(Level.FINEST)) {
590                 _logger.log(Level.FINEST,
591                 "[ApplicationManager] Handling event " + event.toString());
592             }
593
594             DeployEventListenerHelper.getDeployEventListenerHelper().synchronize(event);
595
596             // refreshes the config context with the context from this event
597
this.configManager.refreshConfigContext( event.getConfigContext() );
598
599             // set jsr77 flag
600
boolean jsr77 = false;
601             String JavaDoc action = event.getAction();
602             if ( (action.equals(BaseDeployEvent.DEPLOY)) ||
603                  (action.equals(BaseDeployEvent.REDEPLOY)) ) {
604                 jsr77 = true;
605             }
606
607             String JavaDoc appName = event.getApplicationName();
608
609             //If forceDeploy=true [ie a Redeploy] we need loadEmbeddedRARconfigs
610
//first and then deploy the application. After successful
611
//application Deployment, all embedded connector resources
612
//needs to be loaded
613
ConnectorResourcesLoader connecorResourcesLoader = null;
614             if(event.getForceDeploy()) {
615                 //The undeploy event that had been executed earlier
616
//as part of the deploy --force=true action will remove the
617
//application node from domain.xml.
618
//Therefore refresh the ResourcesUtil singleton with
619
//this event's config context so that it can
620
//find the application node while loading embedded RAR configs
621
//and connector resources.
622
ResourcesUtil.getInstance().setConfigContext(event.getConfigContext());
623                 ResourcesUtil.getInstance().setReinitConfigContext(false);
624                 ServerContext sc = ApplicationServer.getServerContext();
625                 connecorResourcesLoader = new ConnectorResourcesLoader(sc);
626
627                 // do this before loading rar
628
if (event.getLoadUnloadAction() == Constants.LOAD_RAR) {
629                     connecorResourcesLoader.loadEmbeddedRarRAConfigs(appName);
630                 }
631             }
632
633             if (isEnabled(event.getConfigContext(), appName) &&
634                 !applicationDeployed(jsr77, appName, event.getConfigContext(),
635                  event.getLoadUnloadAction()) ) {
636                     
637                 String JavaDoc msg = localStrings.getString(
638                     "applicationmgr.application_deployed_failed", appName);
639                 registerException(event, msg);
640             }
641             
642             // do this after rest of embedded rar is loaded
643
if(event.getLoadUnloadAction() == Constants.LOAD_REST &&
644                 event.getForceDeploy()) {
645                 AbstractLoader appLoader = (AbstractLoader)id2loader.get(appName);
646                 if (appLoader != null) {
647                     Application appDescriptor = appLoader.getApplication();
648                     connecorResourcesLoader.loadEmbeddedRarResources(appName,appDescriptor);
649                 }
650             }
651         } catch (ConfigException ce) {
652             throw new AdminEventListenerException(ce.getMessage());
653         } finally {
654             ResourcesUtil.getInstance().setReinitConfigContext(true);
655         }
656     }
657
658     public synchronized void applicationUndeployed(
659             ApplicationDeployEvent event) throws AdminEventListenerException {
660
661         // set jsr77 flag
662
boolean jsr77 = false;
663         String JavaDoc action = event.getAction();
664         if ( (action.equals(BaseDeployEvent.UNDEPLOY)) ||
665              (action.equals(BaseDeployEvent.REDEPLOY)) ) {
666                 jsr77 = true;
667         }
668
669         try {
670             if (_logger.isLoggable(Level.FINEST)) {
671                 _logger.log(Level.FINEST,
672                     "[ApplicationManager] Handling event " + event.toString());
673             }
674
675             // refreshes the config context with the context from this event
676
this.configManager.refreshConfigContext(
677                             event.getOldConfigContext());
678
679             String JavaDoc appName = event.getApplicationName();
680             //If forceDeploy = true, setcascade as true, so that RA undeployment
681
//removes all deployed connector connection pools,
682
//connector resources, RA configs
683
if(event.getForceDeploy()) {
684                 event.setCascade(true);
685             }
686
687             boolean undeployed = applicationUndeployed(jsr77, appName, true, event.getCascade(), event.getLoadUnloadAction());
688
689             if (!undeployed) {
690                 String JavaDoc msg = localStrings.getString(
691                     "applicationmgr.application_undeployed_failed", appName);
692                 registerException(event, msg);
693             }
694         } catch(ConfigException ce) {
695             throw new AdminEventListenerException(ce.getMessage());
696         }
697     }
698
699     public synchronized void applicationRedeployed(
700             ApplicationDeployEvent event) throws AdminEventListenerException {
701
702         try {
703             if (_logger.isLoggable(Level.FINEST)) {
704                _logger.log(Level.FINEST,
705                     "[ApplicationManager] Handling event " + event.toString());
706             }
707
708             // refreshes the config context with the context from this event
709
this.configManager.refreshConfigContext( event.getConfigContext() );
710
711             String JavaDoc appName = event.getApplicationName();
712             boolean ok = applicationUndeployed(true, appName);
713             if (ok) {
714                 ok = applicationDeployed(true, appName, event.getConfigContext());
715             }
716
717             if (!ok) {
718                 String JavaDoc msg = localStrings.getString(
719                     "applicationmgr.application_redeployed_failed", appName);
720                 registerException(event, msg);
721             }
722         } catch(ConfigException ce) {
723             throw new AdminEventListenerException(ce.getMessage());
724         }
725     }
726
727     public synchronized void applicationEnabled(ApplicationDeployEvent event)
728             throws AdminEventListenerException {
729
730         ResourcesUtil resutil = ResourcesUtil.getInstance();
731         try {
732             if (_logger.isLoggable(Level.FINEST)) {
733                _logger.log(Level.FINEST,
734                     "[ApplicationManager] Handling event " + event.toString());
735             }
736
737             //return if the app is not supposed to be enabled
738
if (!isEnabled(event.getConfigContext(), event.getApplicationName())) {
739                 return;
740             }
741
742             // refreshes the config context with the context from this event
743
this.configManager.refreshConfigContext( event.getConfigContext() );
744
745             String JavaDoc appName = event.getApplicationName();
746             boolean cascade = true;
747             ServerContext sc = ApplicationServer.getServerContext();
748             ConnectorResourcesLoader connecorResourcesLoader =
749                       new ConnectorResourcesLoader(sc);
750             resutil.setConfigContext(event.getConfigContext());
751             resutil.setReinitConfigContext(false);
752  
753             connecorResourcesLoader.loadEmbeddedRarRAConfigs(appName);
754             boolean enabled = applicationDeployed(false, appName, event.getConfigContext());
755
756             if (!enabled) {
757                 String JavaDoc msg = localStrings.getString(
758                         "applicationmgr.application_enabled_failed", appName);
759                 registerException(event, msg);
760             }
761            
762             AbstractLoader appLoader =
763                 (AbstractLoader)id2loader.get(appName);
764             Application appDescriptor = appLoader.getApplication();
765             if (appDescriptor != null) {
766                 connecorResourcesLoader.loadEmbeddedRarResources(
767                             appName,appDescriptor);
768             } else {
769                 _logger.log(Level.FINE,
770                 "[ApplicationManager] Application descriptor is NULL. Skip loading embedded rar resources...");
771             }
772         } catch(ConfigException ce) {
773             throw new AdminEventListenerException(ce.getMessage());
774         } catch(Throwable JavaDoc th) {
775             AdminEventListenerException aele =
776                            new AdminEventListenerException(th.getMessage());
777             aele.initCause(th);
778             throw aele;
779         }finally {
780             resutil.setReinitConfigContext(true);
781         }
782     }
783
784     public synchronized void applicationDisabled(ApplicationDeployEvent event)
785             throws AdminEventListenerException {
786
787         try {
788             if (_logger.isLoggable(Level.FINEST)) {
789                _logger.log(Level.FINEST,
790                     "[ApplicationManager] Handling event " + event.toString());
791             }
792
793             // refreshes the config context with the context from this event
794
this.configManager.refreshConfigContext( event.getConfigContext() );
795
796             String JavaDoc appName = event.getApplicationName();
797             AbstractLoader appLoader = (AbstractLoader) id2loader.get(appName);
798         if(appLoader == null) {
799                 if (_logger.isLoggable(Level.FINEST)) {
800                    _logger.log(Level.FINEST,
801                         "[ApplicationManager] appLoader Null. Returning applicationDisabled");
802                 }
803         return;
804
805         }
806             event.setCascade(true);
807             boolean disabled = applicationUndeployed(false, appName,true,true);
808
809             if (!disabled) {
810                 String JavaDoc msg = localStrings.getString(
811                         "applicationmgr.application_disabled_failed", appName);
812                 registerException(event, msg);
813             }
814         } catch(ConfigException ce) {
815             throw new AdminEventListenerException(ce.getMessage());
816         }
817     }
818
819     
820     /**
821      * Invoked when an application reference is created from a
822      * server instance (or cluster) to a particular application.
823      *
824      * @throws AdminEventListenerException when the listener is unable to
825      * process the event.
826      */

827     public void applicationReferenceAdded(ApplicationDeployEvent event)
828             throws AdminEventListenerException {
829     }
830
831     /**
832      * Invoked when a reference is removed from a
833      * server instance (or cluster) to a particular application.
834      *
835      * @throws AdminEventListenerException when the listener is unable to
836      * process the event.
837      */

838     public void applicationReferenceRemoved(ApplicationDeployEvent event)
839             throws AdminEventListenerException {
840                 
841     }
842     
843     // ---- END OF ApplicationDeployEventListener METHODS --------------------
844
}
845
Popular Tags