KickJava   Java API By Example, From Geeks To Geeks.

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


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

32
33 package com.sun.enterprise.deployment.phasing;
34
35 import com.sun.enterprise.deployment.backend.IASDeploymentException;
36 import com.sun.enterprise.deployment.backend.DeploymentRequest;
37 import com.sun.enterprise.deployment.backend.DeploymentEvent;
38 import com.sun.enterprise.deployment.backend.DeploymentEventType;
39 import com.sun.enterprise.deployment.backend.DeploymentEventInfo;
40 import com.sun.enterprise.deployment.backend.DeploymentLogger;
41 import com.sun.enterprise.deployment.backend.DeploymentStatus;
42 import com.sun.enterprise.deployment.backend.DeployableObjectType;
43 import com.sun.enterprise.deployment.Application;
44 import com.sun.enterprise.util.i18n.StringManager;
45 import com.sun.enterprise.admin.event.BaseDeployEvent;
46 import com.sun.enterprise.server.Constants;
47
48 import java.util.logging.Level JavaDoc;
49 import java.util.logging.Logger JavaDoc;
50
51 /**
52  * This phase is responsible to send the start events to the actual server
53  * instance. This phase is executed as part of Deploy, Associate operations
54  * @author Sandhya E
55  */

56 public class ApplicationStartPhase extends DeploymentPhase {
57
58     /** Deployment Logger object for this class */
59     public static final Logger sLogger = DeploymentLogger.get();
60     
61     /** string manager */
62     private static StringManager localStrings =
63         StringManager.getManager( ApplicationStartPhase.class );
64     
65     /**
66      * Creates a new instance of ApplicationStartPhase
67      * @param deploymentCtx DeploymentContext object
68      */

69     public ApplicationStartPhase(DeploymentContext deploymentCtx)
70     {
71          this.deploymentCtx = deploymentCtx;
72          this.name = APP_START;
73     }
74     
75     /**
76      * Phase specific execution logic will go in this method. Any phase implementing
77      * this class will provide its implementation for this method.
78      * @param req DeploymentRequest object
79      * @param phaseCtx the DeploymentPhaseContext object
80      */

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

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

158     private DeploymentEvent getPostPhaseEvent(DeploymentRequest req) {
159         return new DeploymentEvent(DeploymentEventType.POST_APP_START, new DeploymentEventInfo(req));
160     }
161     
162 }
163
Popular Tags