KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > handlers > CallFlowHandler


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 package com.sun.enterprise.tools.admingui.handlers;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Date JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Properties JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.text.DateFormat JavaDoc;
34 import java.text.NumberFormat JavaDoc;
35
36 import javax.faces.component.UIComponent;
37 import javax.management.Attribute JavaDoc;
38 import javax.management.AttributeList JavaDoc;
39
40 import com.iplanet.jato.view.View;
41 import com.iplanet.jato.view.ViewBase;
42 import com.iplanet.jato.view.ViewBean;
43 import com.iplanet.jato.view.html.SelectableGroup;
44 import com.iplanet.jato.view.html.OptionList;
45 import com.iplanet.jato.RequestContext;
46 import com.iplanet.jato.model.DefaultModel;
47 import com.iplanet.jato.model.Model;
48
49 import com.sun.web.ui.model.CCActionTableModelInterface;
50 import com.sun.web.ui.view.html.CCOption;
51
52 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
53 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView;
54 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
55 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
56 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent;
57
58 import com.sun.enterprise.tools.admingui.util.MBeanUtil;
59 import com.sun.enterprise.tools.admingui.util.AMXUtil;
60 import com.sun.enterprise.tools.admingui.util.Util;
61 import com.sun.enterprise.tools.jsfext.component.ComponentUtil;
62
63 //need for constants
64
import com.sun.appserv.management.monitor.ServerRootMonitor;
65 import com.sun.appserv.management.monitor.CallFlowMonitor;
66
67 import com.sun.web.ui.component.Tree;
68 import com.sun.web.ui.component.TreeNode;
69
70
71 public class CallFlowHandler {
72     
73     private static boolean PROVIDE_DEMO_DATA = false;
74     private static String JavaDoc DEMO_INSTANCE_NAME = "demo";
75     
76     private static String JavaDoc SUCCESS="success";
77     private static String JavaDoc FAILED="failed";
78     private static String JavaDoc[] ADMIN_APP_PREFIX =
79         {"uri:/asadmin/",
80          "uri:/admingui/",
81          "uri:/images/",
82          "uri:/js/",
83          "uri:/redirect.html",
84          "uri:/com_sun_web_ui/",
85          "uri:/favicon.ico",
86          "uri:/web1/"
87          };
88             
89     private static final String JavaDoc LOCALHOST="127.0.0.1";
90     private static final String JavaDoc END_TIMESTAMP_KEY = "end_timestamp";
91    
92   
93     public void loadCallFlowDataTable(RequestContext ctx, HandlerContext handlerCtx) {
94     View view = handlerCtx.getView();
95         ViewDescriptor desc = null;
96         if (handlerCtx.getEvent() instanceof BeforeCreateEvent) {
97             desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor();
98     } else {
99             DescriptorContainerView descView = (DescriptorContainerView)
100                 (((ViewBase)view).getParentViewBean());
101             desc = descView.getViewDescriptor();
102         }
103         
104         CCActionTableModelInterface model =(CCActionTableModelInterface)handlerCtx.getInputValue("model");
105         if (model == null) {
106             throw new FrameworkException("loadCallFlowDataTable: No Model Specified.",
107                 desc, handlerCtx.getView());
108         }
109         
110         String JavaDoc instanceName = (String JavaDoc) handlerCtx.getInputValue("instanceName");
111         String JavaDoc filterValue = (String JavaDoc) handlerCtx.getInputValue("filterValue");
112         try {
113             ((DefaultModel)model).clear();
114             model.beforeFirst();
115             model.setRowSelectionType("multiple");
116             CallFlowMonitor cfm = getCallFlowMonitor(instanceName);
117             
118             if (cfm == null)
119                 return;
120             List JavaDoc listOfMap = cfm.queryRequestInformation ();
121             if (listOfMap == null || listOfMap.isEmpty()){
122                 if (PROVIDE_DEMO_DATA && DEMO_INSTANCE_NAME.equals(instanceName))
123                     listOfMap = queryDemoRequestInformation();
124                 else return;
125             }
126             DateFormat JavaDoc dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, ctx.getRequest().getLocale());
127             Iterator JavaDoc it = listOfMap.iterator();
128             while(it.hasNext()){
129                 Map JavaDoc oneRow = (Map JavaDoc) it.next();
130                 if( filterValue == null || includeRequest(oneRow, filterValue))
131                     populateOneRow(model, oneRow, dateFormat);
132             }
133         } catch (Exception JavaDoc ex) {
134             //backend shouldn't throw exception.
135
if (Util.isLoggableFINE()) {
136                 Util.logFINE(ex);
137             }
138         }
139     }
140     
141     private void populateOneRow(CCActionTableModelInterface model, Map JavaDoc oneRow, DateFormat JavaDoc dateFormat){
142         
143         /* refer to bug# 6351555
144          * Filtering out request thats from admin gui.
145          */

146         String JavaDoc app = (String JavaDoc) oneRow.get(CallFlowMonitor.APPLICATION_NAME_KEY);
147         if (!Util.isEmpty(app)){
148             for(int i = 0; i < ADMIN_APP_PREFIX.length; i++){
149                 if (app.toLowerCase().startsWith(ADMIN_APP_PREFIX[i]))
150                     return;
151             }
152         }
153         model.appendRow();
154         String JavaDoc ms =(String JavaDoc) oneRow.get(CallFlowMonitor.TIME_STAMP_MILLIS_KEY);
155         if (!Util.isEmpty(ms)){
156             Date JavaDoc date = new Date JavaDoc (Long.parseLong (ms));
157             String JavaDoc formattedTime = dateFormat.format(date);
158             model.setValue("timeStampFormatted", formattedTime);
159         }
160         model.setValue("requestId", oneRow.get(CallFlowMonitor.REQUEST_ID_KEY));
161         String JavaDoc clientHost = (String JavaDoc) oneRow.get(CallFlowMonitor.CLIENT_HOST_KEY);
162         if (LOCALHOST.equals(clientHost))
163             clientHost = Util.getMessage("CallFlow.localhost");
164         model.setValue("clientHost", clientHost);
165         model.setValue("user", oneRow.get(CallFlowMonitor.USER_KEY));
166         model.setValue("application", oneRow.get(CallFlowMonitor.APPLICATION_NAME_KEY));
167         model.setValue("startContainer", Util.getMessage((String JavaDoc)oneRow.get(CallFlowMonitor.REQUEST_TYPE_KEY)));
168         String JavaDoc responseTime = (String JavaDoc)oneRow.get(CallFlowMonitor.RESPONSE_TIME_KEY);
169         String JavaDoc resp = convertNanoToMs(responseTime);
170         model.setValue("responseTime", resp);
171         model.setValue("hiddenResponseTime", resp);
172         String JavaDoc status = getStatus(oneRow);
173         if (SUCCESS.equals(status))
174             model.setValue("response", Util.getMessage("common.Success") );
175         else
176             model.setValue("response", Util.getMessage("common.Failed"));
177     }
178     
179     
180     public void populateFilterMenu(RequestContext ctx, HandlerContext handlerCtx) {
181         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
182
SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView();
183         OptionList optionList = new OptionList();
184         
185         optionList.add(new CCOption(Util.getMessage("common.Success"), SUCCESS));
186         optionList.add(new CCOption(Util.getMessage("common.Failed"), FAILED));
187         optionList.add(new CCOption(Util.getMessage("REMOTE_WEB"), CallFlowMonitor.REMOTE_WEB));
188         optionList.add(new CCOption(Util.getMessage("REMOTE_WEB_SERVICE"), CallFlowMonitor.REMOTE_WEB_SERVICE));
189         optionList.add(new CCOption(Util.getMessage("REMOTE_EJB"), CallFlowMonitor.REMOTE_EJB));
190         optionList.add(new CCOption(Util.getMessage("TIMER_EJB"), CallFlowMonitor.TIMER_EJB));
191         optionList.add(new CCOption(Util.getMessage("REMOTE_ASYNC_MESSAGE"), CallFlowMonitor.REMOTE_ASYNC_MESSAGE));
192         
193         dropDownChild.setOptions(optionList);
194     }
195
196
197     /**
198      * <p> This handler is written for our JSF-based framework -- note the
199      * HandlerContext package. This method retreives the CallFlow stack
200      * Maps.</p>
201      *
202      * <p> This handler uses the following input:</p>
203      *
204      * <ul><li><b>requestId</b> - The requestId of the CallFlow stack.</li>
205      * <li><b>instanceName</b> - The server instance name.</li></ul>
206      *
207      * <p> This handler returns the following output:</p>
208      *
209      * <ul><li><b>callStackMap</b> - The Map of Maps representing the request
210      * information.</li></ul>
211      *
212      * @param handlerCtx The JSF-based HandlerContext
213      */

214     public void getCallFlowStackMaps(com.sun.enterprise.tools.jsfext.event.handlers.HandlerContext handlerCtx) {
215
216     String JavaDoc requestId = (String JavaDoc) handlerCtx.getInputValue("requestId");
217     String JavaDoc instanceName = (String JavaDoc) handlerCtx.getInputValue("instanceName");
218
219     CallFlowMonitor cfm = getCallFlowMonitor(instanceName);
220     if (cfm == null) {
221         return;
222     }
223     try {
224         List JavaDoc listOfMap = cfm.queryCallStackForRequest(requestId);
225         if (listOfMap==null || listOfMap.size()==0) {
226         if (PROVIDE_DEMO_DATA && DEMO_INSTANCE_NAME.equals(instanceName)){
227             listOfMap = getDemoCallFlowStack(requestId);
228         }
229         }
230         handlerCtx.setOutputValue("callStackMap", listOfMap);
231     } catch (Exception JavaDoc ex) {
232         if (Util.isLoggableFINE()) {
233         Util.logFINE(ex);
234         }
235     }
236     }
237
238     /**
239      * <p> This handler is written for our JSF-based framework -- note the
240      * HandlerContext package. This method converts the CallFlow stack
241      * List of Maps to tree and adds it as a child to the given parent
242      * UIComponent.</p>
243      *
244      * <p> This handler uses the following input:</p>
245      *
246      * <ul><li><b>parent</b> -
247      * The <code>com.sun.web.ui.component.Tree</code>.</li>
248      * <li><b>content</b> - The List of Maps.</li></ul>
249      *
250      * <p> This handler returns the following output:</p>
251      *
252      * <ul><li><b>tree</b> - The populated Tree.</li></ul>
253      *
254      * @param handlerCtx The JSF-based HandlerContext
255      */

256     public void createCallFlowStackTree(com.sun.enterprise.tools.jsfext.event.handlers.HandlerContext handlerCtx) {
257     // Get the inputs
258
UIComponent parent = (UIComponent) handlerCtx.getInputValue("parent");
259     List JavaDoc content = (List JavaDoc) handlerCtx.getInputValue("content");
260
261     // Create a Tree dataSource...
262
TreeDataSource dataSource = new CallFlowStackTreeDS(content);
263
264     // Fill the Tree
265
Tree tree = dataSource.createJSFTree(parent);
266
267     // Set the output
268
handlerCtx.setOutputValue("tree", tree);
269     }
270
271     private interface TreeDataSource {
272     /**
273      * <p> This method is reponsible for creating, filling and adding a Tree
274      * to the given parent UIComponent. It will use the information
275      * contained in this TreeDataSource.</p>
276      */

277     public Tree createJSFTree(UIComponent parent);
278     }
279
280     private class CallFlowStackTreeDS implements TreeDataSource {
281     public CallFlowStackTreeDS(List JavaDoc<Map JavaDoc> maps) {
282         if (maps != null) {
283         _maps = maps;
284         }
285     }
286
287     /**
288      * <p> This method is reponsible for creating, filling and adding a Tree
289      * to the given parent UIComponent. It will use the information
290      * contained in this TreeDataSource.</p>
291      */

292     public Tree createJSFTree(UIComponent parent) {
293         Map JavaDoc nodeMap = null;
294         UIComponent child = null;
295         String JavaDoc type = null;
296         String JavaDoc methodName = null;
297         Tree tree = null;
298
299         // Get the interator...
300
Iterator JavaDoc<Map JavaDoc> it = _maps.iterator();
301         if (!it.hasNext()) {
302         return null;
303         }
304             
305             //Get the application name from the methodStart row.
306
String JavaDoc application = "";
307             for(int i=0; i<_maps.size(); i++){
308                 Map JavaDoc ms = _maps.get(i);
309                 String JavaDoc rowType = (String JavaDoc) ms.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY);
310                 if(rowType.equals(CallFlowMonitor.CALL_STACK_METHOD_START )){
311                     application = (String JavaDoc) ms.get(CallFlowMonitor.APPLICATION_NAME_KEY );
312                     if(! Util.isEmpty(application))
313                         break;
314                 }
315             }
316                     
317         // Process first Map (should be RequestStart)
318
nodeMap = (Map JavaDoc) it.next();
319         if (!((String JavaDoc) nodeMap.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY)).
320             equals(CallFlowMonitor.CALL_STACK_REQUEST_START)) {
321         throw new RuntimeException JavaDoc("CallFlow stack should begin with "
322             + "RequestStart, instead got: '"
323             + nodeMap.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY) + "'.");
324         }
325         Properties JavaDoc props = new Properties JavaDoc();
326         props.put("expanded", Boolean.TRUE);
327         // ensure application is not null
328
if (application == null) application = "";
329         props.put("text", application);
330         //props.put("imageURL", ...);
331
child = ComponentUtil.getChild(parent, "callFlowTree",
332             "com.sun.enterprise.tools.jsfext.component.factory.basic.TreeFactory",
333             props);
334         parent.getChildren().add(child);
335         tree = (Tree) child;
336         tree.setClientSide(false);
337
338         int idx = 0;
339         while (it.hasNext()) {
340         nodeMap = (Map JavaDoc) it.next();
341         type = (String JavaDoc) nodeMap.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY);
342         if (type.equals(CallFlowMonitor.CALL_STACK_METHOD_START)) {
343             parent = child;
344             methodName = (String JavaDoc) nodeMap.get(CallFlowMonitor.METHOD_NAME_KEY);
345             // Don't share properties...
346
props = (Properties JavaDoc) props.clone();
347             props.setProperty("text", methodName);
348             child = ComponentUtil.getChild(
349             parent, "node" + (++idx),
350             "com.sun.enterprise.tools.jsfext.component.factory.basic.TreeNodeFactory",
351             props);
352             parent.getChildren().add(child);
353         } else if (type.equals(CallFlowMonitor.CALL_STACK_METHOD_END)) {
354             // Set the child -- parent points to child on next pass
355
child = child.getParent();
356         } else if (type.equals(CallFlowMonitor.CALL_STACK_REQUEST_END)) {
357             break;
358         }
359         }
360
361         return tree;
362     }
363
364     /**
365      * The List of Maps
366      */

367     private List JavaDoc<Map JavaDoc> _maps = new ArrayList JavaDoc<Map JavaDoc>();
368     }
369
370
371 public void getCallFlowDetail(RequestContext ctx, HandlerContext handlerCtx) {
372     
373     String JavaDoc requestId = (String JavaDoc) handlerCtx.getInputValue("requestId");
374     String JavaDoc instanceName = (String JavaDoc) handlerCtx.getInputValue("instanceName");
375     
376     CallFlowMonitor cfm = getCallFlowMonitor(instanceName);
377     if (cfm == null)
378         return;
379     try {
380         List JavaDoc listOfMap = cfm.queryCallStackForRequest (requestId);
381         /*
382         System.out.println("List returned by queryCallStackForRequest()");
383         System.out.println(listOfMap);
384         for(int i=0; i<listOfMap.size(); i++){
385             System.out.println(" Map # " + i);
386             System.out.println(listOfMap.get(i));
387         }
388          */

389         if (listOfMap==null || listOfMap.size()==0){
390             if (PROVIDE_DEMO_DATA && DEMO_INSTANCE_NAME.equals(instanceName)){
391                 listOfMap = getDemoCallFlowStack(requestId);
392             }
393         }
394         Map JavaDoc oneRow = getRow( CallFlowMonitor.CALL_STACK_REQUEST_START, listOfMap);
395         if(oneRow == null) return; //shouldn't happen
396
String JavaDoc ms =(String JavaDoc) oneRow.get(CallFlowMonitor.TIME_STAMP_MILLIS_KEY);
397         DateFormat JavaDoc dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, ctx.getRequest().getLocale());
398         Date JavaDoc date = new Date JavaDoc (Long.parseLong(ms));
399         String JavaDoc formattedTime = dateFormat.format(date);
400         handlerCtx.setOutputValue("timeStamp", formattedTime);
401
402         handlerCtx.setOutputValue("startContainer", oneRow.get(CallFlowMonitor.REQUEST_TYPE_KEY));
403
404         //extract info from METHOD_START
405
oneRow = getRow( CallFlowMonitor.CALL_STACK_METHOD_START, listOfMap);
406         if (oneRow == null) return; //shouldn't happen
407
handlerCtx.setOutputValue("application", oneRow.get(CallFlowMonitor.APPLICATION_NAME_KEY));
408         //handlerCtx.setOutputValue("user", oneRow.get(CallFlowMonitor.USER_KEY));
409

410         oneRow = getLastRow( CallFlowMonitor.CALL_STACK_METHOD_END, listOfMap);
411         if(oneRow == null) return;
412         String JavaDoc except = (String JavaDoc) oneRow.get(CallFlowMonitor.EXCEPTION_KEY);
413         handlerCtx.setOutputValue("exception", except);
414         handlerCtx.setOutputValue("callStackMap", listOfMap);
415     } catch (Exception JavaDoc ex) {
416         if (Util.isLoggableFINE()) {
417                 Util.logFINE(ex);
418             }
419         }
420     
421 }
422     
423     public void loadCallStackTable(RequestContext ctx, HandlerContext handlerCtx) {
424     View view = handlerCtx.getView();
425         ViewDescriptor desc = null;
426         if (handlerCtx.getEvent() instanceof BeforeCreateEvent) {
427             desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor();
428     } else {
429             DescriptorContainerView descView = (DescriptorContainerView)
430                 (((ViewBase)view).getParentViewBean());
431             desc = descView.getViewDescriptor();
432         }
433         CCActionTableModelInterface model =(CCActionTableModelInterface)handlerCtx.getInputValue("model");
434         if (model == null) {
435             throw new FrameworkException("loadCallFlowDataTable: No Model Specified.",
436                 desc, handlerCtx.getView());
437         }
438         DateFormat JavaDoc dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, ctx.getRequest().getLocale());
439         try {
440             ((DefaultModel)model).clear();
441             model.beforeFirst();
442             //model.setRowSelectionType("single");
443

444             List JavaDoc listOfMap = (List JavaDoc) handlerCtx.getInputValue("callStackMap");
445             if (listOfMap == null || listOfMap.isEmpty())
446                 return;
447             ArrayList JavaDoc <Map JavaDoc> tmpList = new ArrayList JavaDoc<Map JavaDoc> ();
448             for(int i=0; i < listOfMap.size(); i++){
449                 Map JavaDoc oneRow = (Map JavaDoc) listOfMap.get(i);
450                 String JavaDoc type = (String JavaDoc) oneRow.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY);
451                 if (CallFlowMonitor.CALL_STACK_METHOD_START.equals(type)){
452                     tmpList.add(oneRow);
453                 }
454                 if (CallFlowMonitor.CALL_STACK_METHOD_END.equals(type)){
455                     int lastIndex = tmpList.size()-1;
456                     Map JavaDoc methodStart = tmpList.get(lastIndex);
457                     methodStart.put(END_TIMESTAMP_KEY, oneRow.get(CallFlowMonitor.TIME_STAMP_KEY) );
458                     tmpList.remove(lastIndex);
459                 }
460             }
461             
462             int sequence = 1;
463             for(int i=0; i< listOfMap.size(); i++){
464                 Map JavaDoc oneRow = (Map JavaDoc) listOfMap.get(i);
465                 String JavaDoc type = (String JavaDoc) oneRow.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY);
466                 if (CallFlowMonitor.CALL_STACK_METHOD_START.equals(type))
467                     populateOneDetailRow(model, oneRow, dateFormat, sequence++);
468             }
469         } catch (Exception JavaDoc ex) {
470             if (Util.isLoggableFINE()) {
471                 Util.logFINE(ex);
472             }
473         }
474     }
475     
476      private void populateOneDetailRow(CCActionTableModelInterface model, Map JavaDoc oneRow, DateFormat JavaDoc dateFormat, int sequence){
477         model.appendRow();
478
479         /*** Commented out for now, refer to bug# 6365274
480 // String startTime =(String) oneRow.get(CallFlowMonitor.TIME_STAMP_KEY);
481 // String endTime = (String) oneRow.get(END_TIMESTAMP_KEY);
482 // if (!Util.isEmpty(startTime) && !Util.isEmpty(endTime)){
483 // String duration = String.valueOf(Long.parseLong(endTime) - Long.parseLong(startTime));
484 // model.setValue("duration", convertNanoToMs(duration));
485 // }
486          */

487         model.setValue("container", oneRow.get(CallFlowMonitor.CONTAINER_TYPE_KEY));
488         model.setValue("module", oneRow.get(CallFlowMonitor.MODULE_NAME_KEY));
489         model.setValue("method", oneRow.get(CallFlowMonitor.METHOD_NAME_KEY));
490         model.setValue("component", oneRow.get(CallFlowMonitor.COMPONENT_NAME_KEY));
491         model.setValue("sequence", sequence);
492         //model.setValue("transaction", oneRow.get(CallFlowMonitor.TRANSACTION_ID_KEY));
493
//model.setValue("thread", oneRow.get(CallFlowMonitor.THREAD_ID_KEY));
494
}
495     
496      
497   public void clearCallFlowData(RequestContext ctx, HandlerContext handlerCtx) {
498         String JavaDoc instanceName = (String JavaDoc) handlerCtx.getInputValue("instanceName");
499         if (Util.isEmpty(instanceName))
500             throw new FrameworkException("CallFlowHandler:clearCallFlowData(): No instanceName specified");
501         CallFlowMonitor cfm = getCallFlowMonitor(instanceName);
502         if (cfm == null)
503             return;
504         cfm.clearData() ;
505   }
506   
507    public void setCallFlowConfig(RequestContext ctx, HandlerContext handlerCtx) {
508        String JavaDoc instanceName = (String JavaDoc) handlerCtx.getInputValue("instanceName");
509        Boolean JavaDoc enabled = new Boolean JavaDoc((String JavaDoc) handlerCtx.getInputValue("enabled"));
510        String JavaDoc callerIpFilter = (String JavaDoc) handlerCtx.getInputValue("callerIpFilter");
511        String JavaDoc callerPrincipalFilter = (String JavaDoc) handlerCtx.getInputValue("callerPrincipalFilter");
512        CallFlowMonitor cfm = getCallFlowMonitor(instanceName);
513        if (cfm != null){
514            cfm.setEnabled(enabled);
515            cfm.setCallerIPFilter(callerIpFilter);
516            cfm.setCallerPrincipalFilter(callerPrincipalFilter);
517        }
518    }
519    
520    
521    public void getTimeSpendInfo(RequestContext ctx, HandlerContext handlerCtx) {
522        String JavaDoc instanceName = (String JavaDoc) handlerCtx.getInputValue("instanceName");
523        String JavaDoc requestId = (String JavaDoc) handlerCtx.getInputValue("requestId");
524        CallFlowMonitor cfm = getCallFlowMonitor(instanceName);
525        if (cfm == null) return;
526        try {
527            Map JavaDoc timeSpendMap = (Map JavaDoc) cfm.queryPieInformation(requestId);
528            if (timeSpendMap == null || timeSpendMap.size() <=0 ){
529                if (PROVIDE_DEMO_DATA && DEMO_INSTANCE_NAME.equals(instanceName))
530                     timeSpendMap = getDemoTimeSpendMap(requestId);
531            }
532            handlerCtx.setOutputValue("timeSpendMap", timeSpendMap);
533        }catch (Exception JavaDoc ex) {
534             if (Util.isLoggableFINE()) {
535                 Util.logFINE(ex);
536             }
537         }
538    }
539    
540
541    public void getTimeSpendValues(RequestContext ctx, HandlerContext handlerCtx) {
542        Map JavaDoc<String JavaDoc, String JavaDoc> timeSpendMap = (Map JavaDoc<String JavaDoc, String JavaDoc>) handlerCtx.getInputValue("timeSpendMap");
543        Boolean JavaDoc aa = Boolean.valueOf(timeSpendMap.containsKey("EJB_CONTAINER"));
544        handlerCtx.setOutputValue("hasEjbContainer", aa);
545        
546        aa = Boolean.valueOf(timeSpendMap.containsKey("EJB_APPLICATION"));
547        handlerCtx.setOutputValue("hasEjbApp", aa);
548        
549        aa = Boolean.valueOf(timeSpendMap.containsKey("WEB_CONTAINER"));
550        handlerCtx.setOutputValue("hasWebContainer", aa);
551        
552        aa = Boolean.valueOf(timeSpendMap.containsKey("WEB_APPLICATION"));
553        handlerCtx.setOutputValue("hasWebApp", aa);
554        
555        aa = Boolean.valueOf(timeSpendMap.containsKey("ORB_CONTAINER"));
556        handlerCtx.setOutputValue("hasOrbContainer", aa);
557        
558        float total = 0;
559        for(String JavaDoc key : timeSpendMap.keySet()){
560            total += Float.parseFloat(timeSpendMap.get(key));
561        }
562        
563        AttributeList JavaDoc attrsList = new AttributeList JavaDoc();
564        for(String JavaDoc key : timeSpendMap.keySet()){
565            String JavaDoc value = (String JavaDoc) timeSpendMap.get(key);
566            float xx = Float.parseFloat(value);
567            float yy = xx / total;
568            float percent = yy * 100;
569            NumberFormat JavaDoc numberformat = NumberFormat.getInstance();
570            numberformat.setMinimumFractionDigits(2);
571            Object JavaDoc[] args = {numberformat.format(percent), convertNanoToMs(value) };
572            String JavaDoc result = Util.getMessage("callFlowDetail.percentMs", args);
573            attrsList.add(new Attribute JavaDoc(key, result));
574        }
575        
576        handlerCtx.setOutputValue("valueList", attrsList);
577    }
578    
579    
580     public void deleteCallFlowRequests(RequestContext ctx, HandlerContext handlerCtx) {
581         CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("tableModel");
582         String JavaDoc instanceName = (String JavaDoc)handlerCtx.getInputValue("instanceName");
583 // ((DefaultModel)model).dumpValues(System.out);
584
ArrayList JavaDoc list = new ArrayList JavaDoc();
585         model.setRowSelectionType("multiple");
586         try{
587             model.beforeFirst();
588             while(model.next()) {
589                 boolean selected = model.isRowSelected();
590                 if (selected) {
591                     String JavaDoc res = (String JavaDoc) model.getValue("requestId");
592                     list.add(model.getValue("requestId"));
593                     model.setRowSelected(false);
594                 }
595             }
596             if(!list.isEmpty()){
597                 String JavaDoc[] param = (String JavaDoc[]) list.toArray(new String JavaDoc[ list.size()]);
598                 CallFlowMonitor cfm = getCallFlowMonitor(instanceName);
599                 cfm.deleteRequestIDs(param);
600             }
601         }catch(Exception JavaDoc ex) {
602             ex.printStackTrace();
603         throw new FrameworkException("Unable to delete CallFlow Requests: ", ex);
604     }
605     }
606     
607  
608    private CallFlowMonitor getCallFlowMonitor(String JavaDoc instanceName){
609         Map JavaDoc serverRootMonitorMap = AMXUtil.getDomainRoot().getMonitoringRoot().getServerRootMonitorMap();
610         ServerRootMonitor serverRootMonitor = (ServerRootMonitor) serverRootMonitorMap.get(instanceName);
611         //IF the instance is not running or when no monitorin on, just return;
612
if (serverRootMonitor == null)
613             return null;
614         CallFlowMonitor cfm = serverRootMonitor.getCallFlowMonitor();
615         return cfm;
616    }
617       
618     private boolean includeRequest(Map JavaDoc oneRow, String JavaDoc filter){
619         if (filter == null || "".equals(filter))
620             return true;
621         String JavaDoc status = getStatus(oneRow);
622         String JavaDoc container = (String JavaDoc) oneRow.get(CallFlowMonitor.REQUEST_TYPE_KEY);
623         
624         if (filter.equalsIgnoreCase(status) || filter.equalsIgnoreCase(container))
625             return true;
626         else
627             return false;
628     }
629     
630     private String JavaDoc getStatus(Map JavaDoc oneRow){
631         String JavaDoc error = (String JavaDoc) oneRow.get(CallFlowMonitor.EXCEPTION_KEY);
632         return Util.isEmpty(error) ? SUCCESS : FAILED ;
633         
634     }
635     
636     private Map JavaDoc getRow(String JavaDoc callStackType, List JavaDoc listOfMap){
637     
638         Map JavaDoc oneRow = null;
639         for(int i=0; i< listOfMap.size(); i++){
640             oneRow = (Map JavaDoc) listOfMap.get(i);
641             String JavaDoc type = (String JavaDoc) oneRow.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY);
642             if (callStackType.equals(type))
643                 break;
644         }
645         return oneRow;
646     }
647     
648     
649     private Map JavaDoc getLastRow(String JavaDoc callStackType, List JavaDoc listOfMap){
650         Map JavaDoc oneRow = null;
651         for(int i= listOfMap.size()-1; i>=0; i--){
652             oneRow = (Map JavaDoc) listOfMap.get(i);
653             String JavaDoc type = (String JavaDoc) oneRow.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY);
654             if (callStackType.equals(type))
655                 break;
656         }
657         return oneRow;
658     }
659     
660     private String JavaDoc convertFromNano(String JavaDoc ms, DateFormat JavaDoc dateFormat){
661         long ns = Long.parseLong(ms);
662         long ns1 = ns/1000000;
663         Date JavaDoc dd = new Date JavaDoc(ns1);
664         String JavaDoc formattedTime = dateFormat.format(dd);
665         return formattedTime;
666     }
667     
668     private String JavaDoc convertNanoToMs(String JavaDoc nano){
669         
670         float ns = Float.parseFloat(nano);
671         float ns1 = ns / 1000000;
672         NumberFormat JavaDoc numberformat = NumberFormat.getInstance();
673         numberformat.setMinimumFractionDigits(2);
674         String JavaDoc str = numberformat.format(ns1);
675         return str;
676     }
677     
678     
679     private List JavaDoc queryDemoRequestInformation(){
680         List JavaDoc listOfMap = new ArrayList JavaDoc();
681         
682         HashMap JavaDoc hashMap = new HashMap JavaDoc();
683         hashMap.put(CallFlowMonitor.REQUEST_ID_KEY, "23458989" );
684         hashMap.put(CallFlowMonitor.TIME_STAMP_KEY, ""+java.lang.System.nanoTime());
685         hashMap.put(CallFlowMonitor.CLIENT_HOST_KEY, "138.243.150.122");
686         hashMap.put(CallFlowMonitor.USER_KEY, "Mary");
687         hashMap.put(CallFlowMonitor.REQUEST_TYPE_KEY, "web");
688         hashMap.put(CallFlowMonitor.STATUS_KEY, "true");
689         hashMap.put(CallFlowMonitor.RESPONSE_TIME_KEY, "34");
690         hashMap.put(CallFlowMonitor.APPLICATION_NAME_KEY, "testApp");
691         listOfMap.add(hashMap);
692         
693         HashMap JavaDoc hashMap2 = new HashMap JavaDoc();
694         hashMap2.put(CallFlowMonitor.REQUEST_ID_KEY, "28881999" );
695         hashMap2.put(CallFlowMonitor.TIME_STAMP_KEY, ""+java.lang.System.nanoTime());
696         hashMap2.put(CallFlowMonitor.CLIENT_HOST_KEY, "138.243.140.111");
697         hashMap2.put(CallFlowMonitor.USER_KEY, "Peter");
698         hashMap2.put(CallFlowMonitor.REQUEST_TYPE_KEY, "ejb");
699         hashMap2.put(CallFlowMonitor.STATUS_KEY, "true");
700         hashMap2.put(CallFlowMonitor.RESPONSE_TIME_KEY, "69");
701         hashMap2.put(CallFlowMonitor.APPLICATION_NAME_KEY, "testApp");
702         listOfMap.add(hashMap2);
703         
704         HashMap JavaDoc hashMap3 = new HashMap JavaDoc();
705         hashMap3.put(CallFlowMonitor.REQUEST_ID_KEY, "55551111" );
706         hashMap3.put(CallFlowMonitor.TIME_STAMP_KEY, ""+java.lang.System.nanoTime());
707         hashMap3.put(CallFlowMonitor.CLIENT_HOST_KEY, "299.288.277.266");
708         hashMap3.put(CallFlowMonitor.USER_KEY, "another-user");
709         hashMap3.put(CallFlowMonitor.REQUEST_TYPE_KEY, "iiop");
710         hashMap3.put(CallFlowMonitor.STATUS_KEY, "false");
711         hashMap3.put(CallFlowMonitor.RESPONSE_TIME_KEY, "44");
712         hashMap3.put(CallFlowMonitor.APPLICATION_NAME_KEY, "another-app");
713         listOfMap.add(hashMap3);
714         
715         HashMap JavaDoc hashMap4 = new HashMap JavaDoc();
716         hashMap4.put(CallFlowMonitor.REQUEST_ID_KEY, "38881999" );
717         hashMap4.put(CallFlowMonitor.TIME_STAMP_KEY, ""+java.lang.System.nanoTime());
718         hashMap4.put(CallFlowMonitor.CLIENT_HOST_KEY, "178.244.140.111");
719         hashMap4.put(CallFlowMonitor.USER_KEY, "admin");
720         hashMap4.put(CallFlowMonitor.REQUEST_TYPE_KEY, "ejb");
721         hashMap4.put(CallFlowMonitor.STATUS_KEY, "false");
722         hashMap4.put(CallFlowMonitor.RESPONSE_TIME_KEY, "20");
723         hashMap4.put(CallFlowMonitor.APPLICATION_NAME_KEY, "testApp");
724         listOfMap.add(hashMap4);
725         
726         return listOfMap;
727     }
728     
729     private List JavaDoc getDemoCallFlowStack(String JavaDoc requestId){
730         List JavaDoc listOfMap = new ArrayList JavaDoc();
731         
732         HashMap JavaDoc hMap = new HashMap JavaDoc();
733         hMap.put("RequestID", "RequestID_1");
734         hMap.put("RequestType", "REMOTE_EJB");
735         hMap.put("TimeStamp", "10");
736         hMap.put("CallStackRowType", "RequestStart");
737         listOfMap.add(hMap);
738
739         hMap = new HashMap JavaDoc();
740         hMap.put("Status", "false");
741         hMap.put("ModuleName", "Module_Name_1");
742         hMap.put("MethodName", "Method_Name_1");
743         hMap.put("Exception", "");
744         hMap.put("ComponentName", "Component_Name_1");
745         hMap.put("RequestID", "RequestID_1");
746         hMap.put("ApplicationName", "APP_NAME");
747         hMap.put("ContainerType", "SERVLET");
748         hMap.put("TimeStamp", "11");
749         hMap.put("CallStackRowType", "MethodStart");
750         listOfMap.add(hMap);
751
752
753         hMap = new HashMap JavaDoc();
754         hMap.put("Status", "false");
755         hMap.put("ModuleName", "Module_Name_2");
756         hMap.put("MethodName", "Method_Name_2");
757         hMap.put("Exception", "");
758         hMap.put("ComponentName", "Component_Name_2");
759         hMap.put("RequestID", "RequestID_1");
760         hMap.put("ApplicationName", "APP_NAME");
761         hMap.put("ContainerType", "SERVLET");
762         hMap.put("TimeStamp", "12");
763         hMap.put("CallStackRowType", "MethodStart");
764         listOfMap.add(hMap);
765
766         
767         hMap = new HashMap JavaDoc();
768         hMap.put("Status", "false");
769         hMap.put("Exception", "exe_1");
770         hMap.put("RequestID", "RequestID_1");
771         hMap.put("TimeStamp", "13");
772         hMap.put("CallStackRowType", "MethodEnd");
773         listOfMap.add(hMap);
774
775         hMap = new HashMap JavaDoc();
776         hMap.put("Status", "false");
777         hMap.put("Exception", "exe_1");
778         hMap.put("RequestID", "RequestID_1");
779         hMap.put("TimeStamp", "14");
780         hMap.put("CallStackRowType", "MethodEnd");
781         listOfMap.add(hMap);
782
783         hMap = new HashMap JavaDoc();
784         hMap.put("RequestID", "RequestID_1");
785         hMap.put("TimeStamp", "15");
786         hMap.put("CallStackRowType", "RequestEnd");
787         listOfMap.add(hMap);
788
789         return listOfMap;
790     }
791     
792     static int democount = 0;
793
794     private Map JavaDoc getDemoTimeSpendMap(String JavaDoc id){
795         
796         HashMap JavaDoc hashMap = new HashMap JavaDoc();
797         
798         if (democount == 0){
799         hashMap.put("WEB_CONTAINER", ""+10);
800         hashMap.put("WEB_APPLICATION", ""+30);
801         hashMap.put("EJB_CONTAINER", ""+15);
802         hashMap.put("EJB_APPLICATION", ""+40);
803         hashMap.put("ORB_CONTAINER", ""+5);
804         }else
805         if (democount == 1){
806             hashMap.put("WEB_CONTAINER", ""+20);
807             hashMap.put("WEB_APPLICATION", ""+10);
808             hashMap.put("EJB_CONTAINER", ""+15);
809             hashMap.put("EJB_APPLICATION", ""+30);
810         }else
811         if (democount == 2){
812             hashMap.put("WEB_CONTAINER", ""+20);
813             hashMap.put("WEB_APPLICATION", ""+10);
814             hashMap.put("EJB_CONTAINER", ""+15);
815         }
816         else
817         {
818             hashMap.put("WEB_CONTAINER", ""+20);
819             hashMap.put("WEB_APPLICATION", ""+35);
820         }
821         if (democount++ >=3)
822             democount=0;
823         
824         return hashMap;
825     }
826 }
827
Popular Tags