KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > phasing > ApplicationStopPhase


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  * ApplicationStopPhase.java
26  *
27  * Created on May 20, 2003, 3:19 PM
28  * @author sandhyae
29  * <BR> <I>$Source: /cvs/glassfish/appserv-core/src/java/com/sun/enterprise/deployment/phasing/ApplicationStopPhase.java,v $
30  *
31  */

32
33 package com.sun.enterprise.deployment.phasing;
34
35 import javax.management.MBeanServer JavaDoc;
36 import javax.management.ObjectName JavaDoc;
37 import javax.management.MBeanException JavaDoc;
38
39 import com.sun.enterprise.deployment.backend.IASDeploymentException;
40 import com.sun.enterprise.deployment.backend.DeploymentRequest;
41 import com.sun.enterprise.deployment.backend.DeploymentEvent;
42 import com.sun.enterprise.deployment.backend.DeploymentEventType;
43 import com.sun.enterprise.deployment.backend.DeploymentEventInfo;
44 import com.sun.enterprise.deployment.backend.DeploymentLogger;
45 import com.sun.enterprise.deployment.backend.DeploymentStatus;
46 import com.sun.enterprise.deployment.backend.DeployableObjectType;
47 import com.sun.enterprise.deployment.Application;
48 import com.sun.enterprise.util.i18n.StringManager;
49 import com.sun.enterprise.admin.event.BaseDeployEvent;
50 import com.sun.enterprise.admin.common.MBeanServerFactory;
51 import com.sun.enterprise.admin.common.ObjectNames;
52 import com.sun.enterprise.admin.server.core.AdminNotificationHelper;
53 import com.sun.enterprise.admin.server.core.AdminService;
54 import com.sun.enterprise.admin.AdminContext;
55 import com.sun.enterprise.server.Constants;
56
57 import java.util.logging.Level JavaDoc;
58 import java.util.logging.Logger JavaDoc;
59
60 /**
61  * Phase that is responsible to send stop events when an application is undeployed or
62  * disassociated
63  * @author Sandhya E
64  */

65 public class ApplicationStopPhase extends DeploymentPhase {
66     
67     /** Deployment Logger object for this class */
68     public static final Logger sLogger = DeploymentLogger.get();
69     
70     /** string manager */
71     private static StringManager localStrings =
72         StringManager.getManager( ApplicationStopPhase.class );
73     
74     /**
75      * Creates a new instance of Class
76      * @param deploymentCtx DeploymentContext object
77      */

78     public ApplicationStopPhase(DeploymentContext deploymentCtx)
79     {
80         this.deploymentCtx = deploymentCtx;
81         this.name = APP_STOP;
82     }
83     
84     /**
85      * Sends stop events to the required target
86      * @param req DeploymentRequest object
87      * @param phaseCtx the DeploymentPhaseContext object
88      */

89     public void runPhase(DeploymentPhaseContext phaseCtx)
90     {
91         String JavaDoc type = null;
92         
93         DeploymentRequest req = phaseCtx.getDeploymentRequest();
94
95         DeploymentTarget target = (DeploymentTarget)req.getTarget();
96         DeploymentStatus status = phaseCtx.getDeploymentStatus();
97
98         int loadUnloadAction = Constants.UNLOAD_ALL;
99
100         if(!req.isApplication())
101         {
102             type = DeploymentServiceUtils.getModuleTypeString(req.getType());
103         } else {
104             Application app = DeploymentServiceUtils.getInstanceManager(
105                DeployableObjectType.APP).getRegisteredDescriptor(req.getName());
106
107             if ( (app != null) && (app.getRarComponentCount() != 0) ) {
108                 loadUnloadAction = Constants.UNLOAD_REST;
109             }
110         }
111         
112         prePhaseNotify(getPrePhaseEvent(req));
113         
114         boolean success;
115         try {
116             // send this event to unload non-rar standalone module
117
// or to unload the non-rar submodules of embedded rar
118
if (! req.isConnectorModule()) {
119                 success = target.sendStopEvent(req.getActionCode(), req.getName(), type, req.getCascade(), req.isForced(), loadUnloadAction);
120             } else {
121                 status.setStageStatus(DeploymentStatus.SUCCESS);
122                 return;
123             }
124         } catch(DeploymentTargetException dte) {
125             status.setStageStatus(DeploymentStatus.FAILURE);
126             if (dte.getCause()!=null) {
127                 status.setStageException(dte.getCause());
128                 status.setStageStatusMessage(dte.getMessage());
129             }
130             return;
131         }
132         if (success) {
133             status.setStageStatus(DeploymentStatus.SUCCESS);
134         } else {
135             status.setStageStatus(DeploymentStatus.FAILURE);
136             status.setStageStatusMessage("Application failed to stop");
137         }
138         
139         postPhaseNotify(getPostPhaseEvent(req));
140         
141         // if any exception is thrown. we let the stack unroll, it
142
// will be processed in the DeploymentService.
143
}
144     
145     /**
146      * Event that will be broadcasted at the start of the phase
147      * @param req Deployment request object
148      * @return DeploymentEvent
149      */

150     protected DeploymentEvent getPrePhaseEvent(DeploymentRequest req)
151     {
152         return new DeploymentEvent(DeploymentEventType.PRE_APP_STOP, new DeploymentEventInfo(req));
153     }
154     
155     /**
156      * Event that will be broadcasted at the end of the phase
157      * @param req Deployment request object
158      * @return DeploymentEvent
159      */

160     protected DeploymentEvent getPostPhaseEvent(DeploymentRequest req)
161     {
162         return new DeploymentEvent(DeploymentEventType.POST_APP_STOP,new DeploymentEventInfo(req) );
163     }
164
165 }
166
Popular Tags