KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > debugger > business > Globals


1 package com.lutris.appserver.debugger.business;
2
3 import java.util.Vector JavaDoc;
4 import java.util.Enumeration JavaDoc;
5 import java.util.Hashtable JavaDoc;
6
7 import javax.servlet.Servlet JavaDoc;
8 import javax.servlet.ServletContext JavaDoc;
9 import javax.servlet.http.HttpServletRequest JavaDoc;
10 import javax.servlet.http.HttpServletResponse JavaDoc;
11
12
13 import com.lutris.appserver.server.httpPresentation.HttpPresentationManager;
14 import com.lutris.appserver.server.*;
15 import com.lutris.appserver.debugger.applet.io.*;
16 import javax.servlet.http.HttpServlet JavaDoc;
17 import com.lutris.appserver.server.httpPresentation.servlet.*;
18 import javax.servlet.*;
19 import javax.servlet.http.*;
20 import org.apache.catalina.core.*;
21 import org.apache.catalina.*;
22 import com.lutris.appserver.debugger.spec.*;
23
24 public class Globals {
25
26
27 private static boolean saveResponseData;
28 private static Server server;
29 private static Container cont;
30 private static Host host;
31
32
33 private static Object JavaDoc contentLock = new Object JavaDoc();
34
35     private static int queueSize;
36  
37     private static Vector JavaDoc transactions=new Vector JavaDoc();
38     private static Object JavaDoc lock = new Object JavaDoc();
39
40     private static Hashtable JavaDoc valveMap = new Hashtable JavaDoc();
41     private static Hashtable JavaDoc servletMap = new Hashtable JavaDoc();
42
43
44 public static boolean initialize(String JavaDoc hostName,int size, boolean srd) {
45         queueSize=size;
46         server = ServerFactory.getServer();
47         Service[] service = server.findServices();
48         cont= service[0].getContainer();
49         Container children[] = ((StandardEngine)cont).findChildren();
50         boolean found=false;
51        for (int i = 0; i < children.length; i++) {
52           if (children[i] instanceof Host){
53             if((children[i].getName()).equals(hostName))
54              {
55               found=true;
56                host= (Host)children[i];
57              }
58             }
59           }
60         
61         
62       saveResponseData = srd;
63     return found;
64   }
65
66
67 public static void addTransaction(Hashtable JavaDoc transaction){
68    synchronized (lock) {
69     if(!(transactions.size()<queueSize))
70        transactions.removeElementAt(0);
71       
72     transactions.add(transaction);
73     }
74  }
75
76
77
78 public static Vector JavaDoc getTransactions(){
79
80  synchronized (lock) {
81    return new Vector JavaDoc(transactions);
82    }
83  }
84  
85  
86 public static String JavaDoc [] getServletNames()
87  {
88   
89   Vector JavaDoc names=new Vector JavaDoc();
90   
91     Container[] ch=((StandardHost)host).findChildren();
92          
93       String JavaDoc[] temp=new String JavaDoc[ch.length];
94   
95   for(int i=0;i<ch.length;i++)
96    {
97    String JavaDoc tmp=((Context JavaDoc)ch[i]).getPath();
98       if(tmp!=null)
99        temp[i]=tmp;
100    
101    
102    
103    }
104  
105
106   int j=0;
107   for(int i=0;i<temp.length;i++)
108     {
109      if(!(temp[i].equals("/debugger")||temp[i].equals("/debugger_pres")||temp[i].equals("/")||temp[i].equals("")))
110       {
111         
112         names.add(temp[i]);
113         j++;
114       }
115     }
116   
117    String JavaDoc[] servlets=new String JavaDoc[names.size()];
118    for(int i=0;i<names.size();i++)
119      servlets[i]=(String JavaDoc)names.elementAt(i);
120   return servlets;
121  }
122  
123  public static StandardContext getServlet(String JavaDoc name)
124  {
125   String JavaDoc[] servlets =getServletNames();
126   StandardContext servlet=null;
127   int k=0;
128   boolean found=false;
129   while(!found && k<servlets.length)
130    {
131     if(servlets[k].equals(name)){
132       servlet = (StandardContext) host.findChild(name);
133       found=true;
134       }
135    k++;
136    }
137   
138   return servlet;
139  }
140  
141 public static boolean isContains(String JavaDoc name){
142 boolean contains=servletMap.containsKey(name);
143
144 if(contains)
145 {
146  boolean process=((DebuggerValve)valveMap.get(name)).toProcess;
147     if(process)
148      return true;
149    else
150    return false;
151    }
152 else{
153
154 return false;
155 }
156 }
157
158 public static void addServlet(String JavaDoc name,StandardContext s){
159     synchronized (contentLock)
160             {
161            
162             servletMap.put(name, s);
163             DebuggerValve valve=setNewValve(name);
164             valveMap.put(name,valve);
165               
166             }
167 }
168   
169 public static void removeServlet(String JavaDoc name){
170      synchronized (contentLock) {
171         
172            DebuggerValve valve=(DebuggerValve)valveMap.get(name);
173           valve.toProcess=false;
174        
175            }
176 }
177     
178     
179 public static Snapshot takeSnapshot(long id, int wait) {
180        
181        
182        Snapshot result = new Snapshot();
183      
184         synchronized (contentLock) {
185           
186             Vector JavaDoc v = new Vector JavaDoc();
187             try {
188               String JavaDoc[] e = getServletNames();
189               int k=0;
190                while (k<e.length) {
191                 StandardContext s=getServlet(e[k]);
192                  if ((s == null))
193                      continue;
194            
195                  
196                boolean temp=valveMap.containsKey(e[k]);
197                boolean res=false;
198                if(temp)
199                  res= ((DebuggerValve)valveMap.get(e[k])).toProcess;
200                 v.addElement(new ServletDescription(e[k],res));
201                  k=k+1;
202                 }//while
203

204               result.servlets = new ServletDescription[e.length];
205       
206                 for (int i=0; i<v.size(); i++){
207                     result.servlets[i] = (ServletDescription) v.elementAt(i);
208                 }
209                       
210             } catch (Throwable JavaDoc t) {
211                 System.out.println(t);
212            }
213        
214     
215      
216        
217         }
218         return result;
219     }
220     
221  
222  public static DebuggerValve setNewValve(String JavaDoc apName)
223  {
224     DebuggerValve valve=(DebuggerValve)valveMap.get(apName);
225    if(valve==null)
226       valve=new DebuggerValve(apName,getServlet(apName));
227  valve.toProcess=true;
228   StandardContext servlet=(StandardContext)servletMap.get(apName);
229   servlet.addValve(valve);
230      
231  return valve;
232 }
233     
234 }
Popular Tags