KickJava   Java API By Example, From Geeks To Geeks.

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


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.MemoryPoolMXBean JavaDoc;
8 import java.util.List JavaDoc;
9 import org.exoplatform.container.RootContainer;
10 import org.exoplatform.container.monitor.jvm.JVMRuntimeInfo;
11 import org.exoplatform.faces.core.component.UIExoCommand;
12 import org.exoplatform.faces.core.event.ExoActionEvent;
13 import org.exoplatform.faces.core.event.ExoActionListener;
14 import org.exoplatform.text.template.DataHandler;
15 import org.exoplatform.text.template.ListBeanDataHandler;
16 import org.exoplatform.text.template.ArrayFormater;
17 import org.exoplatform.text.template.xhtml.*;
18 /**
19  * May 31, 2004
20  * @author: Tuan Nguyen
21  * @email: tuan08@users.sourceforge.net
22  * @version: $ID$
23  **/

24 public class UIMemoryPoolInfo extends UIExoCommand {
25   private static String JavaDoc SHOW_DETAIL_ACTION = "detail" ;
26   private static String JavaDoc SHOW_LIST_ACTION = "list" ;
27   
28   static private Element LIST_TEMPLATE =
29     new Table().setCssClass("UIGrid").
30       add(new Rows().setShowHeader(true).
31           add(new LinkColumn("#{UIMemoryPoolInfo.header.name}", "${name}", "${name}").
32               addParameter(ACTION, SHOW_DETAIL_ACTION )).
33           add(new Column("#{UIMemoryPoolInfo.header.memory-type}","${type}")).
34           add(new Column("#{UIMemoryPoolInfo.header.usage}", "${usage}"))).
35       optimize() ;
36
37   static private Element DETAIL_TEMPLATE =
38     new Div().
39       add(new Properties().
40           add("#{UIMemoryPoolInfo.label.name}", "${name}").
41           add("#{UIMemoryPoolInfo.label.memory-manager-names}", "${memoryManagerNames}",
42               new ArrayFormater(null, "<br/>")).
43           add("#{UIMemoryPoolInfo.label.valid}", "${isValid()}").
44           
45           add("#{UIMemoryPoolInfo.label.memory-type}", "${type}").
46           add("#{UIMemoryPoolInfo.label.memory-usage}", "${usage}").
47           add("#{UIMemoryPoolInfo.label.memory-peak-usage}", "${peakUsage}").
48           
49           add("#{UIMemoryPoolInfo.label.usage-threshold}", "${usageThreshold}").
50           add("#{UIMemoryPoolInfo.label.usage-threshold-count}", "${usageThresholdCount}").
51           add("#{UIMemoryPoolInfo.label.is-usage-threshold-supported}", "${isUsageThresholdSupported()}").
52           add("#{UIMemoryPoolInfo.label.is-usage-threshold-exceeded}", "${isUsageThresholdExceeded()}").
53           
54           add("#{UIMemoryPoolInfo.label.collection-usage-threshold}", "${collectionUsageThreshold}").
55           add("#{UIMemoryPoolInfo.label.is-collection-usage-threshold-exceeded}", "${isCollectionUsageThresholdExceeded()}").
56           add("#{UIMemoryPoolInfo.label.collection-usage-threshold-count}", "${collectionUsageThresholdCount}").
57           add("#{UIMemoryPoolInfo.label.collection-usage}", "${collectionUsage}").
58           add("#{UIMemoryPoolInfo.label.is-collection-usage-threshold-supported}", "${isCollectionUsageThresholdSupported()}")).
59       add(new Button("#{UIProcesseInfo.button.cancel}").
60           addParameter(ACTION, SHOW_LIST_ACTION)).
61       optimize();
62   
63   private Element template_ = LIST_TEMPLATE ;
64   private ListBeanDataHandler dataHandler_ ;
65   
66     public UIMemoryPoolInfo() {
67         setRendererType("TemplateRenderer") ;
68     List JavaDoc list =
69       (List JavaDoc)RootContainer.getInstance().getComponentInstance(JVMRuntimeInfo.MEMORY_POOL_MXBEANS) ;
70     dataHandler_ = new ListBeanDataHandler(MemoryPoolMXBean JavaDoc.class) ;
71     dataHandler_.setBeans(list) ;
72     addActionListener(ShowDetailActionListener.class, SHOW_DETAIL_ACTION) ;
73     addActionListener(ShowListActionListener.class, SHOW_LIST_ACTION) ;
74     }
75   
76   public DataHandler getDataHandler(Class JavaDoc type) {
77     return dataHandler_ ;
78   }
79   
80   public Element getTemplate() { return template_ ; }
81   
82   
83   static public class ShowDetailActionListener extends ExoActionListener {
84     public void execute(ExoActionEvent event) throws Exception JavaDoc {
85       UIMemoryPoolInfo uicomp = (UIMemoryPoolInfo) event.getComponent() ;
86       String JavaDoc poolname = event.getParameter(OBJECTID) ;
87       List JavaDoc list = uicomp.dataHandler_.getBeans() ;
88       for(int i = 0; i < list.size(); i++) {
89         MemoryPoolMXBean JavaDoc bean = (MemoryPoolMXBean JavaDoc) list.get(i) ;
90         if(poolname.equals(bean.getName())) {
91           uicomp.dataHandler_.setBean(bean) ;
92           uicomp.template_ = DETAIL_TEMPLATE ;
93           return ;
94         }
95       }
96     }
97   }
98   
99   static public class ShowListActionListener extends ExoActionListener {
100     public void execute(ExoActionEvent event) throws Exception JavaDoc {
101       UIMemoryPoolInfo uicomp = (UIMemoryPoolInfo) event.getComponent() ;
102       uicomp.template_ = LIST_TEMPLATE ;
103     }
104   }
105 }
Popular Tags