KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > EEWebContainerAdminEventProcessor


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  * EEWebContainerAdminEventProcessor.java
26  *
27  * Created on September 26, 2003, 4:51 PM
28  */

29
30 package com.sun.enterprise.web;
31
32 import java.util.Hashtable JavaDoc;
33
34 import java.util.logging.Logger JavaDoc;
35 import java.util.logging.Level JavaDoc;
36 import java.util.ResourceBundle JavaDoc;
37
38 import com.sun.logging.LogDomains;
39
40 import com.sun.enterprise.admin.event.ApplicationDeployEvent;
41 import com.sun.enterprise.admin.event.ModuleDeployEvent;
42
43 /**
44  *
45  * @author lwhite
46  */

47 public class EEWebContainerAdminEventProcessor implements WebContainerAdminEventProcessor {
48     
49     /**
50      * The logger to use for logging ALL web container related messages.
51      */

52     protected static Logger JavaDoc _logger = null;
53     
54     /**
55      * The resource bundle containing the message strings for _logger.
56      */

57     protected static ResourceBundle JavaDoc _rb = null;
58     
59     /**
60      * The embedded Catalina object.
61      */

62     protected EmbeddedWebContainer _embedded = null;
63     
64     /**
65      * Hashtable to keep track of deploy / undeploy events timing
66      * HERCULES:add
67      */

68     private static Hashtable JavaDoc _deployHistory = new Hashtable JavaDoc();
69     
70     /** Creates a new instance of EEWebContainerAdminEventProcessor */
71     public EEWebContainerAdminEventProcessor() {
72         if (_logger == null) {
73             _logger = LogDomains.getLogger(LogDomains.WEB_LOGGER);
74             _rb = _logger.getResourceBundle();
75         }
76     }
77     
78     /** Creates a new instance of EEWebContainerAdminEventProcessor */
79     public EEWebContainerAdminEventProcessor(EmbeddedWebContainer embedded) {
80         _embedded = embedded;
81         if (_logger == null) {
82             _logger = LogDomains.getLogger(LogDomains.WEB_LOGGER);
83             _rb = _logger.getResourceBundle();
84         }
85     }
86     
87     public void init(EmbeddedWebContainer embedded) {
88         _embedded = embedded;
89     }
90     
91     public void applicationDeployed(ApplicationDeployEvent deployEvent) {
92         String JavaDoc deployedAppName = deployEvent.getApplicationName();
93         _logger.finest("applicationDeployed:" + deployedAppName);
94         String JavaDoc key = "App_" + deployedAppName;
95         
96         boolean deployedRecently = checkDeployHistoryEntry(key, "deployed");
97         setDeployHistoryEntry(key, "deployed", System.currentTimeMillis());
98         if (deployedRecently) {
99             _logger.finest("Returning from MIDDLE of applicationDeployed");
100             return;
101         }
102         
103         SessionPurgeUtil purgeUtil = new SessionPurgeUtil(_embedded);
104         _logger.finest("about to call SessionPurgeUtil for" + deployedAppName);
105         deployedAppName = "/" + deployedAppName;
106         /*
107         ConnectionShutdownUtil shutdownUtil = new ConnectionShutdownUtil(_instances);
108         System.out.println("IN WebContainer>>applicationDeployed: "
109             + deployedAppName + "about to close all connections");
110         //shutdownUtil.runCloseAllConnections();
111          */

112         System.gc();
113         //use next line later after container deploy bug is fixed
114
//purgeUtil.closeCachedConnectionForApp(deployedAppName);
115
_logger.finest("Returning from END of applicationDeployed");
116     }
117     
118     public void applicationDisabled(ApplicationDeployEvent deployEvent) {
119     }
120     
121     public void applicationEnabled(ApplicationDeployEvent deployEvent) {
122     }
123     
124     public void applicationRedeployed(ApplicationDeployEvent deployEvent) {
125         String JavaDoc deployedAppName = deployEvent.getApplicationName();
126         _logger.finest("applicationRedeployed:" + deployedAppName);
127         
128         String JavaDoc key = "App_" + deployedAppName;
129         boolean redeployedRecently = checkDeployHistoryEntry(key, "redeployed");
130         setDeployHistoryEntry(key, "redeployed", System.currentTimeMillis());
131         if (redeployedRecently) {
132             _logger.finest("Returning from MIDDLE of applicationRedeployed");
133             return;
134         }
135                 
136         SessionPurgeUtil purgeUtil = new SessionPurgeUtil(_embedded);
137         _logger.finest("about to call SessionPurgeUtil for" + deployedAppName);
138         deployedAppName = "/" + deployedAppName;
139         purgeUtil.purgeSessionsForApp(deployedAppName);
140         /*
141         ConnectionShutdownUtil shutdownUtil = new ConnectionShutdownUtil(_instances);
142         System.out.println("IN WebContainer>>applicationRedeployed: "
143             + deployedAppName + "about to close all connections");
144         //shutdownUtil.runCloseAllConnections();
145          */

146         System.gc();
147         //use next line later after container deploy bug is fixed
148
//purgeUtil.closeCachedConnectionForApp(deployedAppName);
149
_logger.finest("Returning from END of applicationRedeployed");
150     }
151     
152     public void applicationUndeployed(ApplicationDeployEvent deployEvent) {
153         String JavaDoc deployedAppName = deployEvent.getApplicationName();
154         _logger.finest("applicationUndeployed:" + deployedAppName);
155         
156         String JavaDoc key = "App_" + deployedAppName;
157         boolean undeployedRecently = checkDeployHistoryEntry(key, "undeployed");
158         setDeployHistoryEntry(key, "undeployed", System.currentTimeMillis());
159         if (undeployedRecently) {
160             _logger.finest("Returning from MIDDLE of applicationUndeployed");
161             return;
162         }
163         
164         SessionPurgeUtil purgeUtil = new SessionPurgeUtil(_embedded);
165         _logger.finest("about to call SessionPurgeUtil for" + deployedAppName);
166         deployedAppName = "/" + deployedAppName;
167         purgeUtil.purgeSessionsForApp(deployedAppName);
168         /*
169         ConnectionShutdownUtil shutdownUtil = new ConnectionShutdownUtil(_instances);
170         System.out.println("IN WebContainer>>applicationUnDeployed: "
171             + deployedAppName + "about to close all connections");
172         //shutdownUtil.runCloseAllConnections();
173          */

174         System.gc();
175         //use next line later after container deploy bug is fixed
176
//purgeUtil.closeCachedConnectionForApp(deployedAppName);
177
}
178     
179     public void moduleDeployed(ModuleDeployEvent deployEvent) {
180         String JavaDoc deployedModuleName = deployEvent.getModuleName();
181         _logger.finest("moduleDeployed:" + deployedModuleName);
182
183         String JavaDoc key = "Mod_" + deployedModuleName;
184         boolean deployedRecently = checkDeployHistoryEntry(key, "deployed");
185         setDeployHistoryEntry(key, "deployed", System.currentTimeMillis());
186         if (deployedRecently) {
187             _logger.finest("Returning from MIDDLE of moduleDeployed");
188             return;
189         }
190                 
191         ConnectionShutdownUtil shutdownUtil = new ConnectionShutdownUtil(_embedded);
192         shutdownUtil.runCloseAllConnections();
193         System.gc();
194         //use next line later after container deploy bug is fixed
195
//purgeUtil.closeCachedConnectionForApp(deployedAppName);
196
_logger.finest("Returning from END of moduleDeployed");
197     }
198     
199     public void moduleDisabled(ModuleDeployEvent deployEvent) {
200     }
201     
202     public void moduleEnabled(ModuleDeployEvent deployEvent) {
203     }
204     
205     public void moduleRedeployed(ModuleDeployEvent deployEvent) {
206         String JavaDoc deployedModuleName = deployEvent.getModuleName();
207         _logger.finest("moduleRedeployed:" + deployedModuleName);
208
209         String JavaDoc key = "Mod_" + deployedModuleName;
210         boolean redeployedRecently = checkDeployHistoryEntry(key, "redeployed");
211         setDeployHistoryEntry(key, "redeployed", System.currentTimeMillis());
212         if (redeployedRecently) {
213             _logger.finest("Returning from MIDDLE of moduleRedeployed");
214             return;
215         }
216                 
217         ConnectionShutdownUtil shutdownUtil = new ConnectionShutdownUtil(_embedded);
218         shutdownUtil.runCloseAllConnections();
219         System.gc();
220         //use next line later after container deploy bug is fixed
221
//purgeUtil.closeCachedConnectionForApp(deployedAppName);
222
_logger.finest("Returning from END of moduleRedeployed");
223     }
224     
225     public void moduleUndeployed(ModuleDeployEvent deployEvent) {
226         String JavaDoc deployedModuleName = deployEvent.getModuleName();
227         _logger.finest("moduleUndeployed:" + deployedModuleName);
228
229         String JavaDoc key = "Mod_" + deployedModuleName;
230         boolean undeployedRecently = checkDeployHistoryEntry(key, "undeployed");
231         setDeployHistoryEntry(key, "undeployed", System.currentTimeMillis());
232         if (undeployedRecently) {
233             _logger.finest("Returning from MIDDLE of moduleUndeployed");
234             return;
235         }
236
237         ConnectionShutdownUtil shutdownUtil = new ConnectionShutdownUtil(_embedded);
238         System.out.println("IN WebContainer>>moduleUndeployed: "
239             + deployedModuleName + "about to close all connections");
240         shutdownUtil.runCloseAllConnections();
241         System.gc();
242         //use next line later after container deploy bug is fixed
243
//purgeUtil.closeCachedConnectionForApp(deployedAppName);
244
_logger.finest("Returning from END of moduleUndeployed");
245     }
246     
247     /**
248      * set a deploy history entry
249      * @param key identifies an application or module
250      * @param value may have one of
251      * the following values : 'deployed', 'undeployed', 'redeployed'.
252      * @param lat the latency
253      * HERCULES:add
254      */

255     private void setDeployHistoryEntry(String JavaDoc key, String JavaDoc value, long lat) {
256         DeployHistoryEntry entry = (DeployHistoryEntry) _deployHistory.get(key); if (entry == null)
257             _deployHistory.put(key, new DeployHistoryEntry(value, lat));
258         else {
259             entry.value = value;
260             entry.lat = lat;
261         }
262     }
263     
264     /**
265      * This method returns true if the application/module is attempted to be
266      * undeployed even though it was already undeployed, or is attempted to be
267      * (re)deployed when it was (re)deployed within the last 1 minute (60000 ms)
268      * @param key identifies an application or module
269      * @param deployStatus may have one of
270      * the following values : 'deployed', 'undeployed', 'redeployed'.
271      * HERCULES:add
272      */

273     private boolean checkDeployHistoryEntry(String JavaDoc key, String JavaDoc deployStatus) {
274         DeployHistoryEntry entry = (DeployHistoryEntry) _deployHistory.get(key);
275         if (entry == null) {
276             return false;
277         }
278         String JavaDoc val = entry.value;
279         if (val.equals(deployStatus)) {
280             /*if (deployStatus.equals("undeployed")) {
281                     return true; // no need to check timestamp
282             }*/

283             if (( System.currentTimeMillis() - entry.lat ) < 60000) {
284                     return true;
285             }
286         }
287         return false;
288     }
289     
290 }
291
292 /**
293  * class used by WebContainer to properly handle timing of admin events
294  * HERCULES:add
295  */

296 class DeployHistoryEntry {
297     String JavaDoc value;
298     long lat;
299
300     DeployHistoryEntry(String JavaDoc value, long lat) {
301         this.value = value;
302         this.lat = lat;
303     }
304 }
305
Popular Tags