1 16 17 package org.apache.jetspeed.portal.portlets.admin; 18 19 import org.apache.ecs.html.Table; 21 import org.apache.ecs.html.TD; 22 import org.apache.ecs.html.TR; 23 import org.apache.ecs.ConcreteElement; 24 25 import org.apache.jetspeed.portal.portlets.AbstractPortlet; 27 import org.apache.jetspeed.portal.PortletException; 28 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 29 import org.apache.jetspeed.services.logging.JetspeedLogger; 30 31 import org.apache.turbine.util.RunData; 33 34 import java.util.Enumeration; 36 import java.util.Properties; 37 38 44 public class JavaRuntimePortlet extends AbstractPortlet 45 { 46 47 50 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JavaRuntimePortlet.class.getName()); 51 52 public ConcreteElement getContent( RunData rundata ) { 53 54 Table table = new Table().setWidth("100%"); 55 56 try { 57 Runtime jvm = Runtime.getRuntime(); 59 60 table.addElement( new TR() 61 .addElement( new TD("Free Memory (in bytes)") ) 62 .addElement( new TD( Long.toString( jvm.freeMemory() ) ) ) ); 63 64 table.addElement( new TR() 65 .addElement( new TD("Total Memory (in bytes)") ) 66 .addElement( new TD( Long.toString( jvm.totalMemory() ) ) ) ); 67 68 Properties props = System.getProperties(); 70 71 Enumeration enum = props.propertyNames(); 72 while( enum.hasMoreElements() ) { 73 Object key = enum.nextElement(); 74 if ( ! ( key instanceof String ) ) { 75 continue; 76 } 77 78 Object value = props.getProperty( key.toString() ); 79 table.addElement( new TR() 80 .addElement( new TD( key.toString() ) ) 81 .addElement( new TD( value.toString() ) ) ); 82 83 } 84 } catch (Throwable t) { 85 logger.error("Throwable", t); 86 table.addElement( new TR() 87 .addElement( new TD( "Error" ) ) 88 .addElement( new TD( "Could not read system properties" ) ) ); 89 } 90 91 return table; 92 } 93 94 98 public void init() throws PortletException { 99 100 this.setTitle("Java Runtime"); 101 this.setDescription("Information about your Java Runtime"); 102 103 } 104 105 public boolean getAllowEdit(RunData rundata) { 106 return false; 107 } 108 109 public boolean getAllowMaximize(RunData rundata) { 110 return false; 111 } 112 113 114 } 115 | Popular Tags |