KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ResourceAdapterStartPhase.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/ResourceAdapterStartPhase.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 javax.enterprise.deploy.shared.ModuleType JavaDoc;
49
50 import java.util.logging.Level JavaDoc;
51 import java.util.logging.Logger JavaDoc;
52
53 /**
54  * This phase is responsible to send the start events to the actual server
55  * instance. This phase is executed as part of Deploy, Associate operations
56  * @author Sandhya E
57  */

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

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

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

154     private DeploymentEvent getPrePhaseEvent(DeploymentRequest req) {
155         return new DeploymentEvent(DeploymentEventType.PRE_RA_START, new DeploymentEventInfo(req));
156     }
157     
158     /**
159      * Event that will be broadcasted at the end of the phase
160      * @param req Deployment request object
161      * @return DeploymentEvent
162      */

163     private DeploymentEvent getPostPhaseEvent(DeploymentRequest req) {
164         return new DeploymentEvent(DeploymentEventType.POST_RA_START, new DeploymentEventInfo(req));
165     }
166     
167 }
168
Popular Tags