KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > connector > grizzly > CatalinaListener


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 package com.sun.enterprise.web.connector.grizzly;
24
25 import java.util.Iterator JavaDoc;
26 import java.util.concurrent.ConcurrentHashMap JavaDoc;
27 import java.util.concurrent.ConcurrentLinkedQueue JavaDoc;
28
29 import com.sun.enterprise.web.connector.grizzly.FileCache.FileCacheEntry;
30 import org.apache.catalina.Container;
31 import org.apache.catalina.ContainerEvent;
32 import org.apache.catalina.ContainerListener;
33 import org.apache.catalina.Context;
34 import org.apache.catalina.Host;
35
36 /**
37  * Listener used to receive events from Catalina when a <code>Context</code>
38  * is removed or when a <code>Host</code> is removed.
39  *
40  * @author Jean-Francois Arcand
41  */

42 public class CatalinaListener implements ContainerListener{
43   
44     public void containerEvent(ContainerEvent event) {
45         if (Container.REMOVE_CHILD_EVENT.equals(event.getType()) ) {
46             Context context;
47             String JavaDoc contextPath;
48             Host host;
49
50             Object JavaDoc container = event.getData();
51             if ( container instanceof Context) {
52                 context = (Context)container;
53                 
54                 if ( context != null
55                         && context.findConstraints().length == 0
56                         && context.findFilterDefs().length == 0 ){
57                                 
58                     contextPath = context.getPath();
59                     host = (Host)context.getParent();
60                     int[] ports = host.getPorts();
61                     for (int i=0; i < ports.length; i++){
62                         removeContextPath(ports[i],contextPath);
63                     }
64                 }
65             }
66         }
67     }
68     
69     
70     /**
71      * Remove from the <code>FileCache</code> all entries related to
72      * the <code>Context</code> path.
73      * @param port the <code>FileCacheFactory</code> port
74      * @param contextPath the <code>Context</code> path
75      */

76     private void removeContextPath(int port, String JavaDoc contextPath) {
77         FileCacheFactory fileCacheFactory = FileCacheFactory.getFactory(port);
78         ConcurrentHashMap JavaDoc<String JavaDoc,FileCacheEntry>
79                 cachedEntries = fileCacheFactory.getCache();
80         
81         if ( cachedEntries == null){
82             return;
83         }
84         
85         Iterator JavaDoc<String JavaDoc> iterator = cachedEntries.keySet().iterator();
86         String JavaDoc cachedPath;
87         while (iterator.hasNext()){
88             cachedPath = iterator.next();
89             if ( cachedPath.startsWith(contextPath) ){
90                 cachedEntries.remove(cachedPath).run();
91             }
92         }
93     }
94 }
95
96
Popular Tags