User: mnf999  
  Date: 01/08/29 15:57:44

  Added:       src/main/org/jboss/system Info.java InfoMBean.java
  Log:
  The little brother of the old Info stuff with everything exposed and System stuff 
most notably we add the file system anchor
  
  Revision  Changes    Path
  1.1                  jboss/src/main/org/jboss/system/Info.java
  
  Index: Info.java
  ===================================================================
  /*
  * JBoss, the OpenSource J2EE webOS
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.system;
  
  import java.util.Enumeration;
  
  import javax.management.ObjectName;
  import javax.management.MBeanServer;
  import javax.management.MBeanRegistration;
  
  // Part of the boot, don't use org4j
  import org.jboss.logging.Log;
  
  /**
  * A simple mbean that dumps out info like the system properties, etc.
  *      
  * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>.
  * @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>.
  * @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.1 $
  * 
  */
  public class Info
  implements InfoMBean, MBeanRegistration
  {
        // Constants -----------------------------------------------------
        
        // Attributes ----------------------------------------------------
        
        /*System information */
        protected String javaVersion, javaVendor , javaVMName , javaVMVersion, 
libraryDirectory,
        javaVMVendor, osName, osVersion, osArch, jbossLocalHomeDirectory,
        installationURL, configurationDirectory, patchDirectory, jbossVersion;
        
        
        /** Instance logger. */
        private Log log = Log.createLog("GPA");
        
        // Static --------------------------------------------------------
        
        // Constructors --------------------------------------------------
        
        // Public --------------------------------------------------------
        
        public ObjectName preRegister(MBeanServer server, ObjectName name)
        throws Exception
        {
                
                //VM stuff
                javaVersion = System.getProperty("java.version");
                javaVendor = System.getProperty("java.vendor");
                javaVMName = System.getProperty("java.vm.name");
                javaVMVersion = System.getProperty("java.vm.version");
                javaVMVendor =  System.getProperty("java.vm.vendor");
                
                // OS stuff
                osName = System.getProperty("os.name");
                osVersion = System.getProperty("os.version");
                osArch = System.getProperty("os.arch");
                
                // JBoss stuff
                jbossVersion = System.getProperty("jboss.system.version");
                jbossLocalHomeDirectory = System.getProperty("jboss.system.home");
                installationURL = System.getProperty("jboss.system.installationURL");
                configurationDirectory = 
System.getProperty("jboss.system.configurationDirectory");
                libraryDirectory = System.getProperty("jboss.system.libraryDirectory");
                patchDirectory = System.getProperty("jboss.system.patchDirectory");
                
                log.log("General Purpose Architecture [GPA]");
                
                // Dump out basic info as INFO priority msgs
                log.log("Java version: " +
                        javaVersion + "," +
                        javaVendor);
                log.log("Java VM: " +
                        javaVMName + " " +
                        javaVMVersion + "," +
                        javaVMVendor);
                log.log("OS-System: " +
                        osName + " " +
                        osVersion + "," +
                        osArch);
                log.log("JBoss Version : " + jbossVersion);
                log.log("localDir : " + jbossLocalHomeDirectory);
                log.log("installationURL : "+ installationURL);
                log.log("configuration : " + configurationDirectory);
                log.log("libraries : "+libraryDirectory);
                //         log.info("local patch directory " + patchDirectory);
                log.log("Oh, and remember we love you");
                
                // dump out the entire system properties if debug is enabled
                log.debug("+++ Full System Properties Dump");
                Enumeration names= System.getProperties().propertyNames();
                while (names.hasMoreElements()) {
                        String pname= (String) names.nextElement();
                        log.debug(pname + ": " + System.getProperty(pname));
                }
                
                
                return new ObjectName(OBJECT_NAME);
        }
        
        public void postRegister(Boolean registrationDone) {
                // empty
        }
        
        public void preDeregister() throws Exception {
                // empty
        }
        
        public void postDeregister() {
                // empty
        }
        
        public String getJavaVersion() {return javaVersion;} 
        public String getJavaVendor() {return javaVendor;}
        public String getJavaVMName() {return javaVMName;}
        public String getJavaVMVersion() {return javaVMVersion;}
        public String getJavaVMVendor() { return javaVMVendor;}
        public String getOSName() {return osName;}
        public String getOSVersion() { return osVersion;}
        public String getOSArch() { return osArch;}
        
        public String getLocalJBossSystemHomeDirectory() {return 
jbossLocalHomeDirectory;}
        public String getLocalInstallationURL(){return installationURL;}
        public String getConfigurationDirectoryURL(){return configurationDirectory;}
        public String getLocalPatchDirectory(){ return patchDirectory;}
        public String getJBossVersion() { return jbossVersion;}
        public String getLibraryDirectoryURL() { return libraryDirectory;}
        public String getInstallationURL() { return installationURL;}
        
        public 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();
        }
        
        public String runGarbageCollector() {
                StringBuffer buff = new StringBuffer();
                buff.append("<h3>Before</h3>");
                buff.append(listMemoryUsage());
                buff.append("<h3>After</h3>");
                
                log.debug("hinting the VM to run the garbage collector");
                System.gc();
                
                buff.append(listMemoryUsage());
                return buff.toString();
        }
        
        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 listSystemInfo() {
                // Dump out basic info as INFO priority msgs
                StringBuffer rc= new StringBuffer();
                rc.append("<pre>");
                rc.append("Java version: " +
                        System.getProperty("java.version") + "," +
                        System.getProperty("java.vendor"));
                rc.append("\n");
                rc.append("Java VM: " +
                        System.getProperty("java.vm.name") + " " +
                        System.getProperty("java.vm.version") + "," +
                        System.getProperty("java.vm.vendor"));
                rc.append("\n");
                rc.append("System: " +
                        System.getProperty("os.name") + " " +
                        System.getProperty("os.version") + "," +
                        System.getProperty("os.arch"));
                rc.append("\n");
                rc.append("</pre>");
                
                // HRC: Should we also do a full system properties dump??
                
                return rc.toString();
        }
        
        public String listThreadDump() {
                // Get the root thread group
                ThreadGroup root= Thread.currentThread().getThreadGroup();
                while (root.getParent() != null) {
                        root = root.getParent();
                }
                
                // 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) ;
                return rc;
        }
        
        /**
        * Enable or disable tracing method calls at the Runtime level.
        */
        public void traceMethodCalls(final boolean flag) {
                Runtime.getRuntime().traceMethodCalls(flag);
        }
        
        /**
        * Enable or disable tracing instructions the Runtime level.
        */
        public void traceInstructions(final boolean flag) {
                Runtime.getRuntime().traceInstructions(flag);
        }
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/system/InfoMBean.java
  
  Index: InfoMBean.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.system;
  
  import java.lang.Object;
  
  /**
   * The management interface for the Info bean.
   *      
   * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>.
   * @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.1 $
   */
  public interface InfoMBean
  {
        
        public static final String OBJECT_NAME= "JBOSS-SYSTEM:service=Info";
  
     String listMemoryUsage();
     String listSystemInfo();
     String listThreadDump();
     String runGarbageCollector();
     void traceMethodCalls(boolean flag);
     void traceInstructions(boolean flag);
        
        /* getJBossSystemHome
        * return the filesystem directory where JBoss is running on this node
     */
        String getLocalJBossSystemHomeDirectory();
        /*
        * installation URL
        * can be local in a file: or remote with http:
        * tells where the JBOSS-SYSTEM was loaded from
        * By default it is the systemHome.  In case of an http install the system will 
be the 
        * local file system where the run is and the install will be an http based 
install with 
        * centralized configuration for the farms
        */
        String getInstallationURL();
        
        /*
        * configurationDirectory()
        * relative to the installation you can reference different install directories 
so you 
        * can configure farms from an http base with different profiles.  The 
webserver will 
        * need the subdirectory at the installationURL
        * ex: a install refering to -n http://www.jboss.org/world -c acme-inc will 
download 
        * a profile from www.jboss.org that is acme-inc only on the www.jboss.org 
        * we need to have conf/acme-inc under the base directory of JBoss installs
        */
        String getConfigurationDirectoryURL();
        
        /*
        * Lib directory
        * Where to find basic libraries in this system. 
        * This is an absoluteURL
        *
        */
        public String getLibraryDirectoryURL();
        
        /** 
         * Various System getters
         * 
         */
        public String getJavaVersion();
        public String getJavaVendor();
        public String getJavaVMName();
        public String getJavaVMVersion();
        public String getJavaVMVendor();
        public String getOSName();
        public String getOSVersion();
        public String getOSArch() ;
        public String getJBossVersion();
        
  }
  
  
  

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

Reply via email to