KickJava   Java API By Example, From Geeks To Geeks.

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


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

32
33 package com.sun.enterprise.deployment.phasing;
34
35 import com.sun.enterprise.deployment.backend.DeploymentEventManager;
36 import com.sun.enterprise.deployment.backend.DeploymentEvent;
37 import com.sun.enterprise.deployment.backend.DeploymentStatus;
38 import com.sun.enterprise.deployment.backend.DeploymentEventInfo;
39 import com.sun.enterprise.deployment.backend.DeploymentRequest;
40 import com.sun.enterprise.deployment.backend.DeployableObjectType;
41 import com.sun.enterprise.deployment.backend.IASDeploymentException;
42 import com.sun.enterprise.admin.common.constant.DeploymentConstants;
43 import com.sun.enterprise.config.ConfigException;
44 import com.sun.enterprise.util.i18n.StringManager;
45
46 /**
47  * This class is a framework for a deployment phase.
48  * A deployment phase is a logical part of deployment or undeployment operation
49  * Deployment operation has three phases namely J2EEC, Associate, Start
50  * Undeployment has UndeployFromDomain,Disassociate,Stop phases.
51  * These phases are invoked from DeploymentService. There is no state associated with these
52  * phases, that makes it possible for running phases concurrently.
53  * This class also provides methods for notifications, and pre post conditions.
54  * @author Sandhya E
55  */

56 public abstract class DeploymentPhase implements DeploymentConstants{
57     
58     /** names used for phases **/
59     public static final String JavaDoc J2EEC = "J2EEC";
60     public static final String JavaDoc ASSOCIATE = "Associate";
61     public static final String JavaDoc DISASSOCIATE = "Disassociate";
62     public static final String JavaDoc APP_START = "appStart";
63     public static final String JavaDoc RA_START = "raStart";
64     public static final String JavaDoc APP_STOP = "appStop";
65     public static final String JavaDoc RA_STOP = "raStop";
66     public static final String JavaDoc UNDEPLOY = "Undeploy";
67     public static final String JavaDoc PRE_RES_CREATION = "preResCreation";
68     public static final String JavaDoc POST_RES_CREATION = "postResCreation";
69     public static final String JavaDoc PRE_RES_DELETION = "preResDeletion";
70     public static final String JavaDoc POST_RES_DELETION = "postResDeletion";
71     
72     /** context object for executing this phase **/
73     protected DeploymentContext deploymentCtx;
74     
75     /** string manager */
76     private static StringManager localStrings =
77         StringManager.getManager( DeploymentPhase.class );
78     
79     /** name of the phase **/
80     String JavaDoc name = null;
81     
82     /**
83      * This method executes the whole phase.
84      * @param req DeploymentRequest object
85      * @param status the DeploymentStatus object to return feedback
86      * @throws DeploymentPhaseException
87      */

88     public final DeploymentPhaseContext executePhase(DeploymentRequest req, DeploymentStatus status)
89         throws DeploymentPhaseException {
90     DeploymentPhaseContext phaseCtx = getPhaseContext();
91         phaseCtx.setDeploymentRequest(req);
92         phaseCtx.setDeploymentStatus(status);
93         prePhase(phaseCtx);
94         if (status.getStatus()>DeploymentStatus.FAILURE)
95             runPhase(phaseCtx);
96         if (status.getStatus()>DeploymentStatus.FAILURE)
97             postPhase(phaseCtx);
98     return phaseCtx;
99     }
100     
101     /**
102      * This method is called when a successfully executed phase needs
103      * to be rollbacked due to a subsequent failure in the deployment
104      * process. All information needed for rollbacking should be
105      * available in the DeploymentPhaseContext instance returned by
106      * the executePhase and passed to this method
107      *
108      * @param phaseCtx the DeploymentPhaseContext instance
109      * @throws DeploymentPhaseException
110      */

111     public void rollback(DeploymentPhaseContext phaseCtx) throws DeploymentPhaseException {
112     }
113     
114     /**
115      * Phase specific execution logic will go in this method. Any phase implementing
116      * this class will provide its implementation for this method.
117      * @param phaseCtx the DeploymentPhaseContext object
118      * @throws DeploymentPhaseException
119      */

120     public abstract void runPhase(DeploymentPhaseContext phaseCtx) throws DeploymentPhaseException;
121     
122     /**
123      * Any prePhase checks can be done here, and also any preparation for actual
124      * phase execution can happen here
125      * @param phaseCtx the DeploymentPhaseContext object
126      * @throws DeploymentPhaseException
127      */

128     public void prePhase(DeploymentPhaseContext phaseCtx) throws DeploymentPhaseException{
129         //phase specific pre conditions must be checked here
130
}
131     
132     /**
133      * Any postPhase checks and postPhase cleanup can happen here
134      * @param phaseCtx the DeploymentPhaseContext object
135      * @throws DeploymentPhaseException
136      */

137     public void postPhase(DeploymentPhaseContext phaseCtx) throws DeploymentPhaseException{
138         //phase specific post conditions must be checked here
139
}
140     
141     /**
142      * All the listeners registered for this phase will be notified
143      * at the start of the phase.
144      */

145     public void prePhaseNotify(DeploymentEvent event){
146         DeploymentEventManager.notifyDeploymentEvent(event);
147     }
148     
149     /**
150      * All listeners registered with DeploymentEventManager will be notified
151      * at the end of the phase
152      */

153     public void postPhaseNotify(DeploymentEvent event) {
154         DeploymentEventManager.notifyDeploymentEvent(event);
155     }
156     
157     /**
158      * Gets the name of this phase
159      * @return name of the phase
160      */

161     public String JavaDoc getName() {
162         return name;
163     }
164     
165     /**
166      * Sets the name of this phase
167      * @param name name of the phase
168      */

169     /*package*/ void setName(String JavaDoc name) {
170         this.name = name;
171     }
172     
173     /**
174      * Returns the deployment target of the specified name
175      * @param targetName target that has to be returned, if targetName is null default target
176      * is returned
177      * @return deploymentTarget DeploymentTarget
178      */

179     protected DeploymentTarget getTarget(String JavaDoc targetName) throws DeploymentPhaseException{
180         try{
181             DeploymentTarget target = getTargetFactory().getTarget(
182                                          deploymentCtx.getConfigContext(), targetName);
183             return target;
184         }catch(IASDeploymentException de){
185             String JavaDoc msg = localStrings.getString("enterprise.deployment.phasing.phase.targetnotfound");
186             throw new DeploymentPhaseException(getName(), msg, de);
187         }
188         
189     }
190      
191      /**
192       * @return a new @see DeploymentPhaseContext instance to hold information
193       * about this phase. Can be used at rollback time to undo a succesful
194       * deployment phase.
195       */

196       protected DeploymentPhaseContext getPhaseContext() {
197       return new StandardDeploymentPhaseContext();
198       }
199
200       private DeploymentTargetFactory getTargetFactory() {
201         return DeploymentTargetFactory.getDeploymentTargetFactory();
202       }
203 }
204
Popular Tags