KickJava   Java API By Example, From Geeks To Geeks.

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


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  * DisassociationPhase.java
26  *
27  * Created on May 20, 2003, 3:17 PM
28  * @author sandhyae
29  * <BR> <I>$Source: /cvs/glassfish/appserv-core/src/java/com/sun/enterprise/deployment/phasing/DisassociationPhase.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.util.i18n.StringManager;
43
44 import java.util.logging.Level JavaDoc;
45 import java.util.logging.Logger JavaDoc;
46
47 /**
48  * This phase is responsible to disassociate an application from a target
49  * It uses ServerDeploymentTarget, GroupDeploymentTarget to remove references
50  * @author Sandhya E
51  */

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

65     public DisassociationPhase(DeploymentContext deploymentCtx) {
66         this.deploymentCtx = deploymentCtx;
67         this.name = DISASSOCIATE;
68     }
69     
70     /**
71      * This method disassociates the application from the target as specified
72      * in request object
73      * @param req DeploymentRequest object
74      * @param phaseCtx the DeploymentPhaseContext object
75      */

76     public void runPhase(DeploymentPhaseContext phaseCtx)
77     {
78         DeploymentStatus status = phaseCtx.getDeploymentStatus();
79
80         try {
81             //get the app directory on target's cache deleted
82
DeploymentRequest req = phaseCtx.getDeploymentRequest();
83             DeploymentTarget target = (DeploymentTarget)req.getTarget();
84
85             target.removeAppReference(req.getName());
86             sendDisassociateEvent(req);
87             status.setStageStatus(DeploymentStatus.SUCCESS);
88         }catch(Throwable JavaDoc t){
89             status.setStageStatus(DeploymentStatus.FAILURE);
90             status.setStageException(t);
91             status.setStageStatusMessage(t.getMessage());
92         }
93     }
94  
95     
96     /**
97      * Event that will be broadcasted at the start of the phase
98      * @param req DeploymentRequest object
99      * @return DeploymentEvent
100      **/

101     private DeploymentEvent getPrePhaseEvent(DeploymentRequest req) {
102         return new DeploymentEvent(DeploymentEventType.PRE_DISASSOCIATE, new DeploymentEventInfo(req));
103     }
104     
105     /**
106      * Event that will be broadcasted at the end of the phase
107      * @param req DeploymentRequest object
108      * @return DeploymentEvent
109      **/

110     private DeploymentEvent getPostPhaseEvent(DeploymentRequest req) {
111         return new DeploymentEvent(DeploymentEventType.POST_DISASSOCIATE,new DeploymentEventInfo(req));
112     }
113
114     private void sendDisassociateEvent(DeploymentRequest req) throws
115         Exception JavaDoc {
116         DeploymentTarget target = (DeploymentTarget)req.getTarget();
117
118         String JavaDoc moduleType;
119
120         if(req.isApplication()) {
121             moduleType = null;
122         }
123         else {
124             moduleType = DeploymentServiceUtils.getModuleTypeString(req.getType());
125         }
126
127         int eventType = com.sun.enterprise.admin.event.BaseDeployEvent.APPLICATION_UNREFERENCED;
128         String JavaDoc appName = req.getName();
129         String JavaDoc targetName = target.getTarget().getName();
130
131         boolean success = DeploymentServiceUtils.multicastEvent(
132                           eventType,
133                           appName,
134                           moduleType,
135                           false,
136                           true,
137                           targetName);
138  
139         sLogger.log(Level.FINE, "sendDisassociateEvent: success=" + success);
140     }
141 }
142
Popular Tags