[jboss-cvs] JBossAS SVN: r60535 - trunk/system/src/main/org/jboss/system/server.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 14 09:44:36 EST 2007


Author: dimitris at jboss.org
Date: 2007-02-14 09:44:36 -0500 (Wed, 14 Feb 2007)
New Revision: 60535

Modified:
   trunk/system/src/main/org/jboss/system/server/ServerInfo.java
Log:
JBAS-3675, tidy up and add support for ThreadInfo getLockOwnerId/getLockOwnerName. The problem is all those operations are a no-op on all the jdks I tried, returning -1/null, so when jdk support comes, just uncomment the implementation.

Modified: trunk/system/src/main/org/jboss/system/server/ServerInfo.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/ServerInfo.java	2007-02-14 14:40:03 UTC (rev 60534)
+++ trunk/system/src/main/org/jboss/system/server/ServerInfo.java	2007-02-14 14:44:36 UTC (rev 60535)
@@ -1,8 +1,8 @@
 /*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
@@ -56,9 +56,12 @@
 
    /** Zero */
    private static final Integer ZERO = new Integer(0);
+   
+   /** Empty parameter signature for reflective calls */
+   private static final Class[] NO_PARAMS_SIG = new Class[0];
 
-   /** The MBeanServer we are registered to */
-   private MBeanServer server;
+   /** Empty paramater list for reflective calls */
+   private static final Object[] NO_PARAMS = new Object[0];
    
    /** The cached host name for the server. */
    private String hostName;
@@ -93,6 +96,8 @@
    private Method getThreadName;
    private Method getThreadState;
    private Method getLockName;
+   //private Method getLockOwnerId;
+   //private Method getLockOwnerName;   
    private Method getStackTrace;
    
    /** The cached jdk5+ Thread.getId() method */
@@ -105,9 +110,8 @@
    public ObjectName preRegister(MBeanServer server, ObjectName name)
       throws Exception
    {
-      this.server = server;
       // Dump out basic JVM & OS info as INFO priority msgs
-      log.debug("Java version: " +
+      log.info("Java version: " +
       System.getProperty("java.version") + "," +
       System.getProperty("java.vendor"));
       
@@ -140,42 +144,44 @@
             Class clazz = cl.loadClass("java.lang.management.ManagementFactory");
 
             // cache ThreadMXBean instance
-            Method method = clazz.getMethod("getThreadMXBean", null);
-            this.threadMXBean = method.invoke(null, null);
+            Method method = clazz.getMethod("getThreadMXBean", NO_PARAMS_SIG);
+            this.threadMXBean = method.invoke(null, NO_PARAMS);
             
             // cache ManagementFactory.getMemoryPoolMXBeans() method
-            this.getMemoryPoolMXBeans = clazz.getMethod("getMemoryPoolMXBeans", null);
+            this.getMemoryPoolMXBeans = clazz.getMethod("getMemoryPoolMXBeans", NO_PARAMS_SIG);
             
             // cache MemoryPoolMXBean methods
             clazz = cl.loadClass("java.lang.management.MemoryPoolMXBean");
-            this.getName = clazz.getMethod("getName", null);
-            this.getType = clazz.getMethod("getType", null);
-            this.getUsage = clazz.getMethod("getUsage", null);
-            this.getPeakUsage = clazz.getMethod("getPeakUsage", null);
+            this.getName = clazz.getMethod("getName", NO_PARAMS_SIG);
+            this.getType = clazz.getMethod("getType", NO_PARAMS_SIG);
+            this.getUsage = clazz.getMethod("getUsage", NO_PARAMS_SIG);
+            this.getPeakUsage = clazz.getMethod("getPeakUsage", NO_PARAMS_SIG);
             
             // cache MemoryUsage methods
             clazz = cl.loadClass("java.lang.management.MemoryUsage");
-            this.getInit = clazz.getMethod("getInit", null);
-            this.getUsed = clazz.getMethod("getUsed", null);
-            this.getCommitted = clazz.getMethod("getCommitted", null);
-            this.getMax = clazz.getMethod("getMax", null);
+            this.getInit = clazz.getMethod("getInit", NO_PARAMS_SIG);
+            this.getUsed = clazz.getMethod("getUsed", NO_PARAMS_SIG);
+            this.getCommitted = clazz.getMethod("getCommitted", NO_PARAMS_SIG);
+            this.getMax = clazz.getMethod("getMax", NO_PARAMS_SIG);
             
             // cache ThreadMXBean.getThreadInfo() method
             clazz = cl.loadClass("java.lang.management.ThreadMXBean");
             this.getThreadInfo = clazz.getMethod("getThreadInfo", new Class[] { Long.TYPE, Integer.TYPE } );
-            this.getAllThreadIds = clazz.getMethod("getAllThreadIds", null );
+            this.getAllThreadIds = clazz.getMethod("getAllThreadIds", NO_PARAMS_SIG );
             this.getThreadCpuTime = clazz.getMethod("getThreadCpuTime", new Class[] { Long.TYPE } );
 
             // cache ThreadInfo methods
             clazz = cl.loadClass("java.lang.management.ThreadInfo");
-            this.getThreadName = clazz.getMethod("getThreadName", null);
-            this.getThreadState = clazz.getMethod("getThreadState", null);
-            this.getLockName = clazz.getMethod("getLockName", null);
-            this.getStackTrace = clazz.getMethod("getStackTrace", null);
+            this.getThreadName = clazz.getMethod("getThreadName", NO_PARAMS_SIG);
+            this.getThreadState = clazz.getMethod("getThreadState", NO_PARAMS_SIG);
+            this.getLockName = clazz.getMethod("getLockName", NO_PARAMS_SIG);
+            //this.getLockOwnerId = clazz.getMethod("getLockOwnerId", NO_PARAMS_SIG);
+            //this.getLockOwnerName = clazz.getMethod("getLockOwnerName", NO_PARAMS_SIG);            
+            this.getStackTrace = clazz.getMethod("getStackTrace", NO_PARAMS_SIG);
             
             // cache Thread.getId() method
             clazz = Thread.class;
-            this.getThreadId = clazz.getMethod("getId", null);
+            this.getThreadId = clazz.getMethod("getId", NO_PARAMS_SIG);
          }
          catch (Exception e)
          {
@@ -301,8 +307,8 @@
          // until then use reflection to do the job
          try {
             Runtime rt = Runtime.getRuntime();
-            Method m = rt.getClass().getMethod("maxMemory", new Class[0]);
-            return (Long)m.invoke(rt, new Object[0]);
+            Method m = rt.getClass().getMethod("maxMemory", NO_PARAMS_SIG);
+            return (Long)m.invoke(rt, NO_PARAMS);
          }
          catch (Exception e) {
             log.error("Operation failed", e);
@@ -327,8 +333,8 @@
          // until then use reflection to do the job
          try {
             Runtime rt = Runtime.getRuntime();
-            Method m = rt.getClass().getMethod("availableProcessors", new Class[0]);
-            return (Integer)m.invoke(rt, new Object[0]);
+            Method m = rt.getClass().getMethod("availableProcessors", NO_PARAMS_SIG);
+            return (Integer)m.invoke(rt, NO_PARAMS);
          }
          catch (Exception e) {
             log.error("Operation failed", e);
@@ -400,30 +406,30 @@
          try
          {
             // get the pools
-            List poolList = (List)getMemoryPoolMXBeans.invoke(null, null);
+            List poolList = (List)getMemoryPoolMXBeans.invoke(null, NO_PARAMS);
             sbuf.append("<b>Total Memory Pools:</b> ").append(poolList.size());
             sbuf.append("<blockquote>");
             for (Iterator i = poolList.iterator(); i.hasNext(); )
             {
                // MemoryPoolMXBean instance
                Object pool = i.next();
-               String name = (String)getName.invoke(pool, null);
+               String name = (String)getName.invoke(pool, NO_PARAMS);
                // enum MemoryType
-               Object type = getType.invoke(pool, null);
+               Object type = getType.invoke(pool, NO_PARAMS);
                sbuf.append("<b>Pool: ").append(name);
                sbuf.append("</b> (").append(type).append(")");
                
                // PeakUsage/CurrentUsage
-               Object peakUsage = getPeakUsage.invoke(pool, null);
-               Object usage = getUsage.invoke(pool, null);
+               Object peakUsage = getPeakUsage.invoke(pool, NO_PARAMS);
+               Object usage = getUsage.invoke(pool, NO_PARAMS);
                
                sbuf.append("<blockquote>");
                if (usage != null && peakUsage != null)
                {
-                  Long init = (Long)getInit.invoke(peakUsage, null);
-                  Long used = (Long)getUsed.invoke(peakUsage, null);
-                  Long committed = (Long)getCommitted.invoke(peakUsage, null);
-                  Long max = (Long)getMax.invoke(peakUsage, null);
+                  Long init = (Long)getInit.invoke(peakUsage, NO_PARAMS);
+                  Long used = (Long)getUsed.invoke(peakUsage, NO_PARAMS);
+                  Long committed = (Long)getCommitted.invoke(peakUsage, NO_PARAMS);
+                  Long max = (Long)getMax.invoke(peakUsage, NO_PARAMS);
 
                   sbuf.append("Peak Usage    : ");
                   sbuf.append("init:").append(init);
@@ -432,10 +438,10 @@
                   sbuf.append(", max:").append(max);
                   sbuf.append("<br>");
                   
-                  init = (Long)getInit.invoke(usage, null);
-                  used = (Long)getUsed.invoke(usage, null);
-                  committed = (Long)getCommitted.invoke(usage, null);
-                  max = (Long)getMax.invoke(usage, null);
+                  init = (Long)getInit.invoke(usage, NO_PARAMS);
+                  used = (Long)getUsed.invoke(usage, NO_PARAMS);
+                  committed = (Long)getCommitted.invoke(usage, NO_PARAMS);
+                  max = (Long)getMax.invoke(usage, NO_PARAMS);
 
                   sbuf.append("Current Usage : ");
                   sbuf.append("init:").append(init);
@@ -557,13 +563,13 @@
       try
       {
          TreeSet result = new TreeSet();
-         long[] threads = (long[]) getAllThreadIds.invoke(threadMXBean, null);
+         long[] threads = (long[]) getAllThreadIds.invoke(threadMXBean, NO_PARAMS);
          for (int i = 0; i < threads.length; ++i)
          {
             Long id = new Long(threads[i]);
             Long cpuTime = (Long) getThreadCpuTime.invoke(threadMXBean, new Object[] { id });
             Object threadInfo = getThreadInfo.invoke(threadMXBean, new Object[] { id, ZERO });
-            String name = (String) getThreadName.invoke(threadInfo, null);
+            String name = (String) getThreadName.invoke(threadInfo, NO_PARAMS);
             result.add(new ThreadCPU(name, cpuTime.longValue()));
          }
          return result;
@@ -646,18 +652,22 @@
          try
          {
             // get the threadId
-            Long threadId = (Long)getThreadId.invoke(thread, null);
+            Long threadId = (Long)getThreadId.invoke(thread, NO_PARAMS);
             // get the ThreadInfo object for that threadId, max StackTraceElement depth
             Object threadInfo = getThreadInfo.invoke(threadMXBean,
                   new Object[] { threadId, new Integer(Integer.MAX_VALUE) });
             // get misc info from ThreadInfo
-            Object threadState = getThreadState.invoke(threadInfo, null); // enum
-            String threadLockName = (String)getLockName.invoke(threadInfo, null);
-            Object[] stackTrace = (Object[])getStackTrace.invoke(threadInfo, null);
+            Object threadState = getThreadState.invoke(threadInfo, NO_PARAMS); // enum
+            String lockName = (String)getLockName.invoke(threadInfo, NO_PARAMS);
+            //Long lockOwnerId = (Long)getLockOwnerId.invoke(threadInfo, NO_PARAMS);
+            //String lockOwnerName = (String)getLockOwnerName.invoke(threadInfo, NO_PARAMS);
+            Object[] stackTrace = (Object[])getStackTrace.invoke(threadInfo, NO_PARAMS);
             
             sbuf.append(", threadId:").append(threadId);
             sbuf.append(", threadState:").append(threadState);
-            sbuf.append(", threadLockName:").append(threadLockName);
+            sbuf.append(", lockName:").append(lockName);
+            //sbuf.append(", lockOwnerId:").append(lockOwnerId);
+            //sbuf.append(", lockOwnerName:").append(lockOwnerName);
             sbuf.append("<br>");
             if (stackTrace.length > 0)
             {
@@ -869,4 +879,4 @@
       public int threads;
       public int groups;
    }
-}
\ No newline at end of file
+}




More information about the jboss-cvs-commits mailing list