KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > monitor > jvm > component > UIProcessInfo


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.monitor.jvm.component;
6
7 import java.lang.management.* ;
8 import org.exoplatform.container.RootContainer ;
9 import org.exoplatform.faces.core.component.UIExoCommand;
10 import org.exoplatform.faces.core.event.ExoActionEvent;
11 import org.exoplatform.faces.core.event.ExoActionListener;
12 import org.exoplatform.text.template.ListBeanDataHandler;
13 import org.exoplatform.text.template.DataHandler;
14 import org.exoplatform.text.template.xhtml.* ;
15 /**
16  * May 31, 2004
17  * @author: Tuan Nguyen
18  * @email: tuan08@users.sourceforge.net
19  * @version: $ID$
20  **/

21 public class UIProcessInfo extends UIExoCommand {
22   static private String JavaDoc SHOW_PROCESS_INFO_ACTION = "showProcessInfo" ;
23   static private String JavaDoc LIST_PROCESS_INFO_ACTION = "listProcessInfo" ;
24   
25   static private Element PROCESS_INFO_TEMPLATE =
26     new Div().
27       add(new Properties().
28           add("#{UIProcesseInfo.label.thread-name}", "${threadName}").
29           add("#{UIProcesseInfo.header.thread-id}", "${threadId}").
30           
31           add("#{UIProcesseInfo.header.thread-state}", "${threadState}").
32           add("#{UIProcesseInfo.header.is-native}", "${isInNative()}").
33           add("#{UIProcesseInfo.header.is-suspended}", "${isSuspended()}").
34           
35           add("#{UIProcesseInfo.header.blocked-count}", "${blockedCount}").
36           add("#{UIProcesseInfo.header.blocked-time}", "${blockedTime}").
37           add("#{UIProcesseInfo.header.waited-count}", "${waitedCount}").
38           add("#{UIProcesseInfo.header.waited-time}", "${waitedTime}").
39           
40           add("#{UIProcesseInfo.header.lock-name}", "${lockName}").
41           add("#{UIProcesseInfo.header.lock-owner-id}", "${lockOwnerId}").
42           add("#{UIProcesseInfo.header.lock-owner-name}", "${lockOwnerName}")).
43       add(new Button("#{UIProcesseInfo.button.cancel}").
44           addParameter(ACTION, LIST_PROCESS_INFO_ACTION)).
45       optimize();
46   
47   static private Element PROCESSES_SUMMARY_TEMPLATE =
48     new Table().setCssClass("UIGrid").
49       add(new Rows().setShowHeader(true).
50           add(new LinkColumn("#{UIProcesseInfo.label.thread-name}", "${threadName}", "${threadId}").
51               addParameter(ACTION, SHOW_PROCESS_INFO_ACTION)).
52           add(new Column("#{UIProcesseInfo.header.thread-id}", "${threadId}")).
53           add(new Column("#{UIProcesseInfo.header.thread-state}", "${threadState}")).
54           add(new Column("#{UIProcesseInfo.header.is-native}", "${isInNative()}")).
55           add(new Column("#{UIProcesseInfo.header.is-suspended}", "${isSuspended()}"))).
56       optimize() ;
57   
58   private ListBeanDataHandler threadInfo_ ;
59   private Element template_ = PROCESSES_SUMMARY_TEMPLATE ;
60   
61     public UIProcessInfo() {
62         setRendererType("TemplateRenderer") ;
63     threadInfo_ = new ListBeanDataHandler(ThreadInfo.class);
64     ThreadMXBean threadMXBean =
65       (ThreadMXBean)RootContainer.getComponent(ThreadMXBean.class) ;
66     threadInfo_.setBeans(threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds())) ;
67     addActionListener(ShowThreadInfoActionListener.class, SHOW_PROCESS_INFO_ACTION) ;
68     addActionListener(ListThreadInfoActionListener.class, LIST_PROCESS_INFO_ACTION) ;
69     }
70   
71     public DataHandler getDataHandler(Class JavaDoc type) {
72       return threadInfo_ ;
73     }
74     
75   public Element getTemplate() { return template_ ; }
76   
77   static public class ShowThreadInfoActionListener extends ExoActionListener {
78     public void execute(ExoActionEvent event) throws Exception JavaDoc {
79       UIProcessInfo uicomp = (UIProcessInfo) event.getComponent() ;
80       String JavaDoc id = event.getParameter(OBJECTID) ;
81       long threadId = Long.parseLong(id) ;
82       ThreadMXBean threadMXBean =
83         (ThreadMXBean)RootContainer.getComponent(ThreadMXBean.class) ;
84       ThreadInfo tinfo = threadMXBean.getThreadInfo(threadId) ;
85       uicomp.threadInfo_.setBean(tinfo) ;
86       uicomp.template_ = PROCESS_INFO_TEMPLATE ;
87     }
88   }
89   
90   static public class ListThreadInfoActionListener extends ExoActionListener {
91     public void execute(ExoActionEvent event) throws Exception JavaDoc {
92       UIProcessInfo uicomp = (UIProcessInfo) event.getComponent() ;
93       ThreadMXBean threadMXBean =
94         (ThreadMXBean)RootContainer.getComponent(ThreadMXBean.class) ;
95       uicomp.threadInfo_.setBean(threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds())) ;
96       uicomp.template_ = PROCESSES_SUMMARY_TEMPLATE;
97     }
98   }
99 }
Popular Tags