1 23 24 package com.sun.enterprise.tools.admingui.handlers; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.Date ; 29 import java.util.Map ; 30 import java.util.List ; 31 import java.util.Properties ; 32 import java.util.HashMap ; 33 import java.text.DateFormat ; 34 import java.text.NumberFormat ; 35 36 import javax.faces.component.UIComponent; 37 import javax.management.Attribute ; 38 import javax.management.AttributeList ; 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 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 DEMO_INSTANCE_NAME = "demo"; 75 76 private static String SUCCESS="success"; 77 private static String FAILED="failed"; 78 private static String [] 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 LOCALHOST="127.0.0.1"; 90 private static final String 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 instanceName = (String ) handlerCtx.getInputValue("instanceName"); 111 String filterValue = (String ) 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 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 dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, ctx.getRequest().getLocale()); 127 Iterator it = listOfMap.iterator(); 128 while(it.hasNext()){ 129 Map oneRow = (Map ) it.next(); 130 if( filterValue == null || includeRequest(oneRow, filterValue)) 131 populateOneRow(model, oneRow, dateFormat); 132 } 133 } catch (Exception ex) { 134 if (Util.isLoggableFINE()) { 136 Util.logFINE(ex); 137 } 138 } 139 } 140 141 private void populateOneRow(CCActionTableModelInterface model, Map oneRow, DateFormat dateFormat){ 142 143 146 String app = (String ) 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 ms =(String ) oneRow.get(CallFlowMonitor.TIME_STAMP_MILLIS_KEY); 155 if (!Util.isEmpty(ms)){ 156 Date date = new Date (Long.parseLong (ms)); 157 String formattedTime = dateFormat.format(date); 158 model.setValue("timeStampFormatted", formattedTime); 159 } 160 model.setValue("requestId", oneRow.get(CallFlowMonitor.REQUEST_ID_KEY)); 161 String clientHost = (String ) 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 )oneRow.get(CallFlowMonitor.REQUEST_TYPE_KEY))); 168 String responseTime = (String )oneRow.get(CallFlowMonitor.RESPONSE_TIME_KEY); 169 String resp = convertNanoToMs(responseTime); 170 model.setValue("responseTime", resp); 171 model.setValue("hiddenResponseTime", resp); 172 String 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 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 214 public void getCallFlowStackMaps(com.sun.enterprise.tools.jsfext.event.handlers.HandlerContext handlerCtx) { 215 216 String requestId = (String ) handlerCtx.getInputValue("requestId"); 217 String instanceName = (String ) handlerCtx.getInputValue("instanceName"); 218 219 CallFlowMonitor cfm = getCallFlowMonitor(instanceName); 220 if (cfm == null) { 221 return; 222 } 223 try { 224 List 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 ex) { 232 if (Util.isLoggableFINE()) { 233 Util.logFINE(ex); 234 } 235 } 236 } 237 238 256 public void createCallFlowStackTree(com.sun.enterprise.tools.jsfext.event.handlers.HandlerContext handlerCtx) { 257 UIComponent parent = (UIComponent) handlerCtx.getInputValue("parent"); 259 List content = (List ) handlerCtx.getInputValue("content"); 260 261 TreeDataSource dataSource = new CallFlowStackTreeDS(content); 263 264 Tree tree = dataSource.createJSFTree(parent); 266 267 handlerCtx.setOutputValue("tree", tree); 269 } 270 271 private interface TreeDataSource { 272 277 public Tree createJSFTree(UIComponent parent); 278 } 279 280 private class CallFlowStackTreeDS implements TreeDataSource { 281 public CallFlowStackTreeDS(List <Map > maps) { 282 if (maps != null) { 283 _maps = maps; 284 } 285 } 286 287 292 public Tree createJSFTree(UIComponent parent) { 293 Map nodeMap = null; 294 UIComponent child = null; 295 String type = null; 296 String methodName = null; 297 Tree tree = null; 298 299 Iterator <Map > it = _maps.iterator(); 301 if (!it.hasNext()) { 302 return null; 303 } 304 305 String application = ""; 307 for(int i=0; i<_maps.size(); i++){ 308 Map ms = _maps.get(i); 309 String rowType = (String ) ms.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY); 310 if(rowType.equals(CallFlowMonitor.CALL_STACK_METHOD_START )){ 311 application = (String ) ms.get(CallFlowMonitor.APPLICATION_NAME_KEY ); 312 if(! Util.isEmpty(application)) 313 break; 314 } 315 } 316 317 nodeMap = (Map ) it.next(); 319 if (!((String ) nodeMap.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY)). 320 equals(CallFlowMonitor.CALL_STACK_REQUEST_START)) { 321 throw new RuntimeException ("CallFlow stack should begin with " 322 + "RequestStart, instead got: '" 323 + nodeMap.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY) + "'."); 324 } 325 Properties props = new Properties (); 326 props.put("expanded", Boolean.TRUE); 327 if (application == null) application = ""; 329 props.put("text", application); 330 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 ) it.next(); 341 type = (String ) nodeMap.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY); 342 if (type.equals(CallFlowMonitor.CALL_STACK_METHOD_START)) { 343 parent = child; 344 methodName = (String ) nodeMap.get(CallFlowMonitor.METHOD_NAME_KEY); 345 props = (Properties ) 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 child = child.getParent(); 356 } else if (type.equals(CallFlowMonitor.CALL_STACK_REQUEST_END)) { 357 break; 358 } 359 } 360 361 return tree; 362 } 363 364 367 private List <Map > _maps = new ArrayList <Map >(); 368 } 369 370 371 public void getCallFlowDetail(RequestContext ctx, HandlerContext handlerCtx) { 372 373 String requestId = (String ) handlerCtx.getInputValue("requestId"); 374 String instanceName = (String ) handlerCtx.getInputValue("instanceName"); 375 376 CallFlowMonitor cfm = getCallFlowMonitor(instanceName); 377 if (cfm == null) 378 return; 379 try { 380 List listOfMap = cfm.queryCallStackForRequest (requestId); 381 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 oneRow = getRow( CallFlowMonitor.CALL_STACK_REQUEST_START, listOfMap); 395 if(oneRow == null) return; String ms =(String ) oneRow.get(CallFlowMonitor.TIME_STAMP_MILLIS_KEY); 397 DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, ctx.getRequest().getLocale()); 398 Date date = new Date (Long.parseLong(ms)); 399 String formattedTime = dateFormat.format(date); 400 handlerCtx.setOutputValue("timeStamp", formattedTime); 401 402 handlerCtx.setOutputValue("startContainer", oneRow.get(CallFlowMonitor.REQUEST_TYPE_KEY)); 403 404 oneRow = getRow( CallFlowMonitor.CALL_STACK_METHOD_START, listOfMap); 406 if (oneRow == null) return; handlerCtx.setOutputValue("application", oneRow.get(CallFlowMonitor.APPLICATION_NAME_KEY)); 408 410 oneRow = getLastRow( CallFlowMonitor.CALL_STACK_METHOD_END, listOfMap); 411 if(oneRow == null) return; 412 String except = (String ) oneRow.get(CallFlowMonitor.EXCEPTION_KEY); 413 handlerCtx.setOutputValue("exception", except); 414 handlerCtx.setOutputValue("callStackMap", listOfMap); 415 } catch (Exception 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 dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, ctx.getRequest().getLocale()); 439 try { 440 ((DefaultModel)model).clear(); 441 model.beforeFirst(); 442 444 List listOfMap = (List ) handlerCtx.getInputValue("callStackMap"); 445 if (listOfMap == null || listOfMap.isEmpty()) 446 return; 447 ArrayList <Map > tmpList = new ArrayList <Map > (); 448 for(int i=0; i < listOfMap.size(); i++){ 449 Map oneRow = (Map ) listOfMap.get(i); 450 String type = (String ) 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 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 oneRow = (Map ) listOfMap.get(i); 465 String type = (String ) 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 ex) { 470 if (Util.isLoggableFINE()) { 471 Util.logFINE(ex); 472 } 473 } 474 } 475 476 private void populateOneDetailRow(CCActionTableModelInterface model, Map oneRow, DateFormat dateFormat, int sequence){ 477 model.appendRow(); 478 479 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 } 495 496 497 public void clearCallFlowData(RequestContext ctx, HandlerContext handlerCtx) { 498 String instanceName = (String ) 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 instanceName = (String ) handlerCtx.getInputValue("instanceName"); 509 Boolean enabled = new Boolean ((String ) handlerCtx.getInputValue("enabled")); 510 String callerIpFilter = (String ) handlerCtx.getInputValue("callerIpFilter"); 511 String callerPrincipalFilter = (String ) 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 instanceName = (String ) handlerCtx.getInputValue("instanceName"); 523 String requestId = (String ) handlerCtx.getInputValue("requestId"); 524 CallFlowMonitor cfm = getCallFlowMonitor(instanceName); 525 if (cfm == null) return; 526 try { 527 Map timeSpendMap = (Map ) 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 ex) { 534 if (Util.isLoggableFINE()) { 535 Util.logFINE(ex); 536 } 537 } 538 } 539 540 541 public void getTimeSpendValues(RequestContext ctx, HandlerContext handlerCtx) { 542 Map <String , String > timeSpendMap = (Map <String , String >) handlerCtx.getInputValue("timeSpendMap"); 543 Boolean 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 key : timeSpendMap.keySet()){ 560 total += Float.parseFloat(timeSpendMap.get(key)); 561 } 562 563 AttributeList attrsList = new AttributeList (); 564 for(String key : timeSpendMap.keySet()){ 565 String value = (String ) timeSpendMap.get(key); 566 float xx = Float.parseFloat(value); 567 float yy = xx / total; 568 float percent = yy * 100; 569 NumberFormat numberformat = NumberFormat.getInstance(); 570 numberformat.setMinimumFractionDigits(2); 571 Object [] args = {numberformat.format(percent), convertNanoToMs(value) }; 572 String result = Util.getMessage("callFlowDetail.percentMs", args); 573 attrsList.add(new Attribute (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 instanceName = (String )handlerCtx.getInputValue("instanceName"); 583 ArrayList list = new ArrayList (); 585 model.setRowSelectionType("multiple"); 586 try{ 587 model.beforeFirst(); 588 while(model.next()) { 589 boolean selected = model.isRowSelected(); 590 if (selected) { 591 String res = (String ) model.getValue("requestId"); 592 list.add(model.getValue("requestId")); 593 model.setRowSelected(false); 594 } 595 } 596 if(!list.isEmpty()){ 597 String [] param = (String []) list.toArray(new String [ list.size()]); 598 CallFlowMonitor cfm = getCallFlowMonitor(instanceName); 599 cfm.deleteRequestIDs(param); 600 } 601 }catch(Exception ex) { 602 ex.printStackTrace(); 603 throw new FrameworkException("Unable to delete CallFlow Requests: ", ex); 604 } 605 } 606 607 608 private CallFlowMonitor getCallFlowMonitor(String instanceName){ 609 Map serverRootMonitorMap = AMXUtil.getDomainRoot().getMonitoringRoot().getServerRootMonitorMap(); 610 ServerRootMonitor serverRootMonitor = (ServerRootMonitor) serverRootMonitorMap.get(instanceName); 611 if (serverRootMonitor == null) 613 return null; 614 CallFlowMonitor cfm = serverRootMonitor.getCallFlowMonitor(); 615 return cfm; 616 } 617 618 private boolean includeRequest(Map oneRow, String filter){ 619 if (filter == null || "".equals(filter)) 620 return true; 621 String status = getStatus(oneRow); 622 String container = (String ) 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 getStatus(Map oneRow){ 631 String error = (String ) oneRow.get(CallFlowMonitor.EXCEPTION_KEY); 632 return Util.isEmpty(error) ? SUCCESS : FAILED ; 633 634 } 635 636 private Map getRow(String callStackType, List listOfMap){ 637 638 Map oneRow = null; 639 for(int i=0; i< listOfMap.size(); i++){ 640 oneRow = (Map ) listOfMap.get(i); 641 String type = (String ) 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 getLastRow(String callStackType, List listOfMap){ 650 Map oneRow = null; 651 for(int i= listOfMap.size()-1; i>=0; i--){ 652 oneRow = (Map ) listOfMap.get(i); 653 String type = (String ) oneRow.get(CallFlowMonitor.CALL_STACK_ROW_TYPE_KEY); 654 if (callStackType.equals(type)) 655 break; 656 } 657 return oneRow; 658 } 659 660 private String convertFromNano(String ms, DateFormat dateFormat){ 661 long ns = Long.parseLong(ms); 662 long ns1 = ns/1000000; 663 Date dd = new Date (ns1); 664 String formattedTime = dateFormat.format(dd); 665 return formattedTime; 666 } 667 668 private String convertNanoToMs(String nano){ 669 670 float ns = Float.parseFloat(nano); 671 float ns1 = ns / 1000000; 672 NumberFormat numberformat = NumberFormat.getInstance(); 673 numberformat.setMinimumFractionDigits(2); 674 String str = numberformat.format(ns1); 675 return str; 676 } 677 678 679 private List queryDemoRequestInformation(){ 680 List listOfMap = new ArrayList (); 681 682 HashMap hashMap = new HashMap (); 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 hashMap2 = new HashMap (); 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 hashMap3 = new HashMap (); 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 hashMap4 = new HashMap (); 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 getDemoCallFlowStack(String requestId){ 730 List listOfMap = new ArrayList (); 731 732 HashMap hMap = new HashMap (); 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 (); 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 (); 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 (); 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 (); 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 (); 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 getDemoTimeSpendMap(String id){ 795 796 HashMap hashMap = new HashMap (); 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 |