1 5 package org.exoplatform.portlets.monitor.jvm.component; 6 7 import java.lang.management.ClassLoadingMXBean ; 8 import java.lang.management.CompilationMXBean ; 9 import org.exoplatform.faces.core.component.UIExoComponentBase; 10 import org.exoplatform.text.template.DataBindingValue; 11 import org.exoplatform.text.template.DataHandler; 12 import org.exoplatform.text.template.xhtml.Div; 13 import org.exoplatform.text.template.xhtml.Element; 14 import org.exoplatform.text.template.xhtml.Properties; 15 21 public class UIClassInfo extends UIExoComponentBase { 22 static private Element TEMPLATE = 23 new Div(). 24 add(new Properties(). 25 addHeader("Compiler Info"). 26 add("#{UIClassInfo.label.compiler-name}", "${name}"). 27 add("#{UIClassInfo.label.total-compilation-time}", "${totalCompilationTime}"). 28 add("#{UIClassInfo.label.is-monitor-supported}","${isCompilationTimeMonitoringSupported()}"). 29 addHeader("Class Loading Info"). 30 add("#{UIClassInfo.label.loaded-class-count}", "${loadedClassCount}"). 31 add("#{UIClassInfo.label.total-loaded-class-count}", "${totalLoadedClassCount}"). 32 add("#{UIClassInfo.label.unloaded-class-count}","${unloadedClassCount}")). 33 optimize(); 34 35 private DataHandler datahandler_ ; 36 37 public UIClassInfo(ClassLoadingMXBean classBean, CompilationMXBean compiler) { 38 setRendererType("TemplateRenderer") ; 39 datahandler_ = new ClassInfoDataHandler(classBean, compiler); 40 } 41 42 public DataHandler getDataHandler(Class type) { 43 return datahandler_ ; 44 } 45 46 public Element getTemplate() { return TEMPLATE ; } 47 48 static class ClassInfoDataHandler implements DataHandler { 49 private ClassLoadingMXBean classBean_; 50 private CompilationMXBean compiler_; 51 52 public ClassInfoDataHandler(ClassLoadingMXBean classBean, CompilationMXBean compiler) { 53 classBean_ = classBean ; 54 compiler_ = compiler ; 55 } 56 57 public Class getDataTypeHandler() { return ClassInfoDataHandler.class; } 58 59 public String getValueAsString(DataBindingValue value) { 60 if("getName".equals(value.getMethodName())) return compiler_.getName() ; 61 if("getTotalCompilationTime".equals(value.getMethodName())) 62 return Long.toString(compiler_.getTotalCompilationTime()) ; 63 if("isCompilationTimeMonitoringSupported".equals(value.getMethodName())) 64 return Boolean.toString(compiler_.isCompilationTimeMonitoringSupported()) ; 65 66 if("getLoadedClassCount".equals(value.getMethodName())) 67 return Long.toString(classBean_.getLoadedClassCount()) ; 68 if("getTotalLoadedClassCount".equals(value.getMethodName())) 69 return Long.toString(classBean_.getTotalLoadedClassCount()) ; 70 if("getUnloadedClassCount".equals(value.getMethodName())) 71 return Long.toString(classBean_.getUnloadedClassCount()) ; 72 return value.getExpression(); 73 } 74 75 public Object getValue(DataBindingValue value) { 76 throw new RuntimeException ("This method is not supported") ; 77 } 78 } 79 } | Popular Tags |