User: starksm 
  Date: 02/02/09 18:50:00

  Modified:    src/main/org/jboss/system InfoMBean.java Info.java
  Log:
  Add the listMemoryUsage, listThreadDump and displayPackageInfo methods
  from the 2.4 version
  
  Revision  Changes    Path
  1.5       +17 -6     jboss/src/main/org/jboss/system/InfoMBean.java
  
  Index: InfoMBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/InfoMBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- InfoMBean.java    7 Feb 2002 00:05:56 -0000       1.4
  +++ InfoMBean.java    10 Feb 2002 02:50:00 -0000      1.5
  @@ -16,17 +16,28 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Hiram Chirino</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public interface InfoMBean
   {
      String OBJECT_NAME = ":service=Info";
   
  +   /** InetAddress.getLocalHost().getHostName();
  +    */
      String getHostName();
  -
  +   /** Returns InetAddress.getLocalHost().getHostAddress();
  +    */
      String getHostAddress();
  -   
  -   Map showProperties();
  -   
  -   String showThreads();
  +   /** Return the total memory and free memory from Runtime
  +    */
  +   String listMemoryUsage();
  +   /** Return a listing of the active threads and thread groups.
  +    */
  +   String listThreadDump();
  +   /** Display the java.lang.Package info for the pkgName */
  +   String displayPackageInfo(String pkgName);
  +   /** Return a Map of System.getProperties() with a toString implementation
  +    *that provides an html table of the key/value pairs
  +    */
  +   Map showProperties();   
   }
  
  
  
  1.9       +151 -95   jboss/src/main/org/jboss/system/Info.java
  
  Index: Info.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/Info.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Info.java 7 Feb 2002 00:05:56 -0000       1.8
  +++ Info.java 10 Feb 2002 02:50:00 -0000      1.9
  @@ -19,7 +19,7 @@
   import org.jboss.logging.Logger;
   
   /**
  - * An MBean that provides a rich view of system information for the JBoss 
  + * An MBean that provides a rich view of system information for the JBoss
    * server in which it is deployed.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard Öberg</a>
  @@ -27,45 +27,46 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Hiram Chirino</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    */
   public class Info
      implements InfoMBean, MBeanRegistration
   {
      /** Class logger. */
      private static final Logger log = Logger.getLogger(Info.class);
  -
  +   
      /** The cached host name for the server. */
      private String hostName;
  -
  +   
      /** The cached host address for the server. */
      private String hostAddress;
  -
  -
  +   
  +   
      ///////////////////////////////////////////////////////////////////////////
      //                               JMX Hooks                               //
      ///////////////////////////////////////////////////////////////////////////
  -
  +   
      public ObjectName preRegister(MBeanServer server, ObjectName name)
         throws Exception
      {
         // Dump out basic JVM & OS info as INFO priority msgs
         log.info("Java version: " +
  -              System.getProperty("java.version") + "," +
  -              System.getProperty("java.vendor"));
  +      System.getProperty("java.version") + "," +
  +      System.getProperty("java.vendor"));
         
         log.info("Java VM: " +
  -              System.getProperty("java.vm.name") + " " +
  -              System.getProperty("java.vm.version") + "," +
  -              System.getProperty("java.vm.vendor"));
  +      System.getProperty("java.vm.name") + " " +
  +      System.getProperty("java.vm.version") + "," +
  +      System.getProperty("java.vm.vendor"));
         
         log.info("OS-System: " +
  -              System.getProperty("os.name") + " " +
  -              System.getProperty("os.version") + "," +
  -              System.getProperty("os.arch"));
  -
  +      System.getProperty("os.name") + " " +
  +      System.getProperty("os.version") + "," +
  +      System.getProperty("os.arch"));
  +      
         // Dump out the entire system properties if debug is enabled
  -      if (log.isDebugEnabled()) {
  +      if (log.isDebugEnabled())
  +      {
            log.debug("Full System Properties Dump");
            Enumeration names = System.getProperties().propertyNames();
            while (names.hasMoreElements())
  @@ -77,123 +78,178 @@
         
         return (name != null ? name : new ObjectName(OBJECT_NAME));
      }
  -     
  -   public void postRegister(Boolean registrationDone) {
  +   
  +   public void postRegister(Boolean registrationDone)
  +   {
         // empty
      }
  -     
  -   public void preDeregister() throws Exception {
  +   
  +   public void preDeregister() throws Exception
  +   {
         // empty
      }
  -     
  -   public void postDeregister() {
  +   
  +   public void postDeregister()
  +   {
         // empty
      }
  -     
  -
  +   
  +   
      ///////////////////////////////////////////////////////////////////////////
      //                            Server Information                         //
      ///////////////////////////////////////////////////////////////////////////
  -
  -   public String getHostName() {
  -      if (hostName == null) {
  -      try {
  -         hostName = java.net.InetAddress.getLocalHost().getHostName();
  -      }
  -      catch (java.net.UnknownHostException e) {
  -         log.error("Error looking up local hostname", e);
  -         hostName = "<unknown>";
  -      }
  +   
  +   public String getHostName()
  +   {
  +      if (hostName == null)
  +      {
  +         try
  +         {
  +            hostName = java.net.InetAddress.getLocalHost().getHostName();
  +         }
  +         catch (java.net.UnknownHostException e)
  +         {
  +            log.error("Error looking up local hostname", e);
  +            hostName = "<unknown>";
  +         }
         }
  -
  +      
         return hostName;
      }
  -
  -   public String getHostAddress() {
  -      if (hostAddress == null) {
  -      try {
  -         hostAddress = java.net.InetAddress.getLocalHost().getHostAddress();
  -      }
  -      catch (java.net.UnknownHostException e) {
  -         log.error("Error looking up local address", e);
  -         hostAddress = "<unknown>";
  -      }
  +   
  +   public String getHostAddress()
  +   {
  +      if (hostAddress == null)
  +      {
  +         try
  +         {
  +            hostAddress = java.net.InetAddress.getLocalHost().getHostAddress();
  +         }
  +         catch (java.net.UnknownHostException e)
  +         {
  +            log.error("Error looking up local address", e);
  +            hostAddress = "<unknown>";
  +         }
         }
  -
  +      
         return hostAddress;
      }
   
  -   private String getThreadGroupInfo(ThreadGroup group) {
  -      StringBuffer rc = new StringBuffer();
  -             
  -      rc.append("<BR><B>");
  -      rc.append("Thread Group: " + group.getName());
  -      rc.append("</B> : ");
  -      rc.append("max priority:" + group.getMaxPriority() +
  -                ", demon:" + group.isDaemon());
  -             
  -      rc.append("<blockquote>");
  -      Thread threads[]= new Thread[group.activeCount()];
  -      group.enumerate(threads, false);
  -      for (int i= 0; i < threads.length && threads[i] != null; i++) {
  -         rc.append("<B>");
  -         rc.append("Thread: " + threads[i].getName());
  -         rc.append("</B> : ");
  -         rc.append("priority:" + threads[i].getPriority() +
  -                   ", demon:" + threads[i].isDaemon());
  -         rc.append("<BR>");
  -      }
  -             
  -      ThreadGroup groups[]= new ThreadGroup[group.activeGroupCount()];
  -      group.enumerate(groups, false);
  -      for (int i= 0; i < groups.length && groups[i] != null; i++) {
  -         rc.append(getThreadGroupInfo(groups[i]));
  -      }
  -      rc.append("</blockquote>");
  -      
  -      return rc.toString();
  +   /** Return the total memory and free memory from Runtime
  +    */
  +   public String listMemoryUsage()
  +   {
  +      String rc= "<P><B>Total Memory: </B>" +
  +      (Runtime.getRuntime().totalMemory()) +
  +      " </P>" + "<P><B>Free Memory: </B>" +
  +      (Runtime.getRuntime().freeMemory()) + " </P>";
  +      return rc;
      }
  -     
  -   public String showThreads() {
  +
  +   /** Return a listing of the active threads and thread groups.
  +    */
  +   public String listThreadDump()
  +   {
         // Get the root thread group
         ThreadGroup root= Thread.currentThread().getThreadGroup();
  -      while (root.getParent() != null) {
  +      while (root.getParent() != null)
  +      {
            root = root.getParent();
         }
  -             
  -      // I'm not sure why what gets reported is off by +1, 
  +      
  +      // I'm not sure why what gets reported is off by +1,
         // but I'm adjusting so that it is consistent with the display
         int activeThreads = root.activeCount()-1;
  -
         // I'm not sure why what gets reported is off by -1
         // but I'm adjusting so that it is consistent with the display
         int activeGroups = root.activeGroupCount()+1;
  -             
  +      
         String rc=
  -         "<b>Total Threads:</b> "+activeThreads+"<br>"+
  -         "<b>Total Thread Groups:</b> "+activeGroups+"<br>"+
  -         getThreadGroupInfo(root) ;
  +      "<b>Total Threads:</b> "+activeThreads+"<br>"+
  +      "<b>Total Thread Groups:</b> "+activeGroups+"<br>"+
  +      getThreadGroupInfo(root) ;
         return rc;
      }
  -   
  -   public Map showProperties() {
  -      return new HashMap(System.getProperties()) {
  -         public String toString() {
  +
  +   /** Display the java.lang.Package info for the pkgName  */
  +   public String displayPackageInfo(String pkgName)
  +   {
  +      Package pkg = Package.getPackage(pkgName);
  +      if( pkg == null )
  +         return "<h2>Package:"+pkgName+" Not Found!</h2>";
  +
  +      StringBuffer info = new StringBuffer("<h2>Package: "+pkgName+"</h2>");
  +      info.append("<pre>\n");
  +      info.append("SpecificationTitle: "+pkg.getSpecificationTitle());
  +      info.append("\nSpecificationVersion: "+pkg.getSpecificationVersion());
  +      info.append("\nSpecificationVendor: "+pkg.getSpecificationVendor());
  +      info.append("\nImplementationTitle: "+pkg.getImplementationTitle());
  +      info.append("\nImplementationVersion: "+pkg.getImplementationVersion());
  +      info.append("\nImplementationVendor: "+pkg.getImplementationVendor());
  +      info.append("\nisSealed: "+pkg.isSealed());
  +      info.append("</pre>\n");
  +      return info.toString();
  +   }
  +
  +   /** Return a Map of System.getProperties() with a toString implementation
  +    *that provides an html table of the key/value pairs
  +    */
  +   public Map showProperties()
  +   {
  +      return new HashMap(System.getProperties())
  +      {
  +         public String toString()
  +         {
               StringBuffer buff = new StringBuffer();
               buff.append("<table>");
               Iterator iter = keySet().iterator();
  -            while (iter.hasNext()) {
  +            while (iter.hasNext())
  +            {
                  String key = (String)iter.next();
                  buff.append("<tr><td align=\"left\">")
  -                  .append(key)
  -                  .append("</td><td align=\"left\">")
  -                  .append(get(key))
  -                  .append("</td></tr>\n\r");
  +               .append(key)
  +               .append("</td><td align=\"left\">")
  +               .append(get(key))
  +               .append("</td></tr>\n\r");
               }
               buff.append("</table>");
               
               return buff.toString();
            }
         };
  +   }
  +
  +   private String getThreadGroupInfo(ThreadGroup group)
  +   {
  +      StringBuffer rc = new StringBuffer();
  +      
  +      rc.append("<BR><B>");
  +      rc.append("Thread Group: " + group.getName());
  +      rc.append("</B> : ");
  +      rc.append("max priority:" + group.getMaxPriority() +
  +      ", demon:" + group.isDaemon());
  +      
  +      rc.append("<blockquote>");
  +      Thread threads[]= new Thread[group.activeCount()];
  +      group.enumerate(threads, false);
  +      for (int i= 0; i < threads.length && threads[i] != null; i++)
  +      {
  +         rc.append("<B>");
  +         rc.append("Thread: " + threads[i].getName());
  +         rc.append("</B> : ");
  +         rc.append("priority:" + threads[i].getPriority() +
  +         ", demon:" + threads[i].isDaemon());
  +         rc.append("<BR>");
  +      }
  +      
  +      ThreadGroup groups[]= new ThreadGroup[group.activeGroupCount()];
  +      group.enumerate(groups, false);
  +      for (int i= 0; i < groups.length && groups[i] != null; i++)
  +      {
  +         rc.append(getThreadGroupInfo(groups[i]));
  +      }
  +      rc.append("</blockquote>");
  +      
  +      return rc.toString();
      }
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to