geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r278600 - in /geronimo/trunk/applications/console-standard/src: java/org/apache/geronimo/console/jsr77/ webapp/WEB-INF/ webapp/WEB-INF/view/infomanager/
Date Sun, 04 Sep 2005 15:35:13 GMT
Author: ammulder
Date: Sun Sep  4 08:35:09 2005
New Revision: 278600

URL: http://svn.apache.org/viewcvs?rev=278600&view=rev
Log:
More AJAX Goodness
 - kernel up time updates too
 - squash error popups
 - only show refresh button if auto-update has stopped

Added:
    geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/jsr77/DynamicServerInfo.java
  (with props)
Modified:
    geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/jsr77/Jsr77Lookup.java
    geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/dwr.xml
    geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/infomanager/svrInfoNormal.jsp

Added: geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/jsr77/DynamicServerInfo.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/jsr77/DynamicServerInfo.java?rev=278600&view=auto
==============================================================================
--- geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/jsr77/DynamicServerInfo.java
(added)
+++ geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/jsr77/DynamicServerInfo.java
Sun Sep  4 08:35:09 2005
@@ -0,0 +1,119 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.console.jsr77;
+
+import java.io.Serializable;
+import java.text.NumberFormat;
+
+/**
+ * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
+ */
+public class DynamicServerInfo implements Serializable {
+    private final static long BYTES_MAX = 2048;
+    private final static long KB_MAX = BYTES_MAX * 1024l;
+    private final static long MB_MAX = KB_MAX * 1024l;
+    private final static long GB_MAX = MB_MAX * 1024l;
+    private final static long TB_MAX = GB_MAX * 1024l;
+    private final static double KB_DIV = 1024;
+    private final static double MB_DIV = KB_DIV*1024d;
+    private final static double GB_DIV = MB_DIV*1024d;
+    private final static double TB_DIV = GB_DIV*1024d;
+    private NumberFormat dec2Format;
+    private String memoryCurrent;
+    private String memoryMost;
+    private String memoryAllocated;
+    private String upTime;
+
+    public DynamicServerInfo(long upTime) {
+        this.upTime = calculateTime(upTime);
+        memoryAllocated = memoryCurrent = memoryMost = "Unknown";
+    }
+
+    public DynamicServerInfo(long memoryCurrent, long memoryMost, long memoryAllocated, long
upTime) {
+        dec2Format = NumberFormat.getNumberInstance();
+        dec2Format.setMaximumFractionDigits(2);
+        this.memoryCurrent = calculateMemory(memoryCurrent);
+        this.memoryMost = calculateMemory(memoryMost);
+        this.memoryAllocated = calculateMemory(memoryAllocated);
+        this.upTime = calculateTime(upTime);
+    }
+
+    private String calculateMemory(long bytes) {
+        if(bytes < BYTES_MAX) {
+            return bytes+" B";
+        } else if(bytes < KB_MAX) {
+            return dec2Format.format((double)bytes/KB_DIV)+" kB";
+        } else if(bytes < MB_MAX) {
+            return dec2Format.format((double)bytes/MB_DIV)+" MB";
+        } else if(bytes < GB_MAX) {
+            return dec2Format.format((double)bytes/GB_DIV)+" GB";
+        } else if(bytes < TB_MAX) {
+            return dec2Format.format((double)bytes/TB_DIV)+" TB";
+        } else {
+            return "Out of range";
+        }
+    }
+
+    private String calculateTime(long millis) {
+        int secs = (int)(millis/1000L);
+        int days = secs/86400;
+        secs = secs % 86400;
+        int hours = secs/3600;
+        secs = secs % 3600;
+        int minutes = secs / 60;
+        secs = secs % 60;
+        StringBuffer buf = new StringBuffer();
+        if(days > 1) {
+            buf.append(' ').append(days).append(" days");
+        } else if(days > 0) {
+            buf.append(' ').append(days).append(" day");
+        }
+        if(hours > 1) {
+            buf.append(' ').append(hours).append(" hours");
+        } else if(hours > 0) {
+            buf.append(' ').append(hours).append(" hour");
+        }
+        if(minutes > 1) {
+            buf.append(' ').append(minutes).append(" minutes");
+        } else if(minutes > 0) {
+            buf.append(' ').append(minutes).append(" minute");
+        }
+        if(secs > 1) {
+            buf.append(' ').append(secs).append(" seconds");
+        } else if(secs > 0) {
+            buf.append(' ').append(secs).append(" second");
+        }
+        buf.delete(0,1);
+        return buf.toString();
+    }
+
+    public String getMemoryCurrent() {
+        return memoryCurrent;
+    }
+
+    public String getMemoryMost() {
+        return memoryMost;
+    }
+
+    public String getMemoryAllocated() {
+        return memoryAllocated;
+    }
+
+    public String getUpTime() {
+        return upTime;
+    }
+}

Propchange: geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/jsr77/DynamicServerInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/jsr77/Jsr77Lookup.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/jsr77/Jsr77Lookup.java?rev=278600&r1=278599&r2=278600&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/jsr77/Jsr77Lookup.java
(original)
+++ geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/jsr77/Jsr77Lookup.java
Sun Sep  4 08:35:09 2005
@@ -33,18 +33,19 @@
  * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
  */
 public class Jsr77Lookup {
-    public BoundedRangeStatistic getJavaVMStatistics() {
+    public DynamicServerInfo getJavaVMStatistics() {
         HttpSession session = ExecutionContext.get().getSession();
         ManagementHelper helper = PortletManager.getManagementHelper(session);
         J2EEDomain[] domains = helper.getDomains();
         J2EEServer[] servers = helper.getServers(domains[0]);
         JVM[] jvms = helper.getJavaVMs(servers[0]);
+        long elapsed = System.currentTimeMillis() - jvms[0].getKernelBootTime().getTime();
         if(jvms[0].isStatisticsProvider()) {
             JVMStats stats = (JVMStats) ((StatisticsProvider)jvms[0]).getStats();
             BoundedRangeStatistic heap = stats.getHeapSize();
-            return heap;
+            return new DynamicServerInfo(heap.getCurrent(), heap.getHighWaterMark(), heap.getUpperBound(),
elapsed);
         } else {
-            return null;
+            return new DynamicServerInfo(elapsed);
         }
     }
 }

Modified: geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/dwr.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/dwr.xml?rev=278600&r1=278599&r2=278600&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/dwr.xml (original)
+++ geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/dwr.xml Sun Sep  4 08:35:09
2005
@@ -4,7 +4,7 @@
 
 <dwr>
   <allow>
-    <convert converter="bean" match="javax.management.j2ee.statistics.BoundedRangeStatistic"/>
+    <convert converter="bean" match="org.apache.geronimo.console.jsr77.DynamicServerInfo"/>
     <create creator="new" javascript="Jsr77Stats">
       <param name="class" value="org.apache.geronimo.console.jsr77.Jsr77Lookup"/>
     </create>

Modified: geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/infomanager/svrInfoNormal.jsp
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/infomanager/svrInfoNormal.jsp?rev=278600&r1=278599&r2=278600&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/infomanager/svrInfoNormal.jsp
(original)
+++ geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/infomanager/svrInfoNormal.jsp
Sun Sep  4 08:35:09 2005
@@ -17,7 +17,7 @@
   </tr> 
   <tr> 
     <td class="MediumBackground">Kernel Up Time</td> 
-    <td class="MediumBackground">${svrProps['Kernel Up Time']}</td> 
+    <td class="MediumBackground"><div id="<portlet:namespace/>UpTime">Not
Yet Available</div></td>
   </tr> 
 </table>
 <br>
@@ -96,26 +96,37 @@
     <td class="MediumBackground">Total Memory Allocated</td>
     <td class="MediumBackground"><div id="<portlet:namespace/>AvailableMemory">Not
Yet Available</div></td>
   </tr> 
-  <tr> 
+  <tr>
     <td class="LightBackground">Available Processors</td> 
     <td class="LightBackground">${jvmProps['Available Processors']}</td> 
   </tr> 
   <tr> 
-    <td colspan="2" align="center">
-      <form name="<portlet:namespace/>" action="<portlet:actionURL/>">
-        <input type="submit" value="Refresh"/>
-      </form>
-    </td>
+    <td colspan="2" align="center"><div id="<portlet:namespace/>ErrorArea"></div></td>
   </tr>
 </table>
 
 <script>
-function <portlet:namespace/>showNext(jvmStats) {
-    DWRUtil.setValue("<portlet:namespace/>CurrentMemory", jvmStats.current);
-    DWRUtil.setValue("<portlet:namespace/>MostMemory", jvmStats.highWaterMark);
-    DWRUtil.setValue("<portlet:namespace/>AvailableMemory", jvmStats.upperBound);
-    setTimeout("Jsr77Stats.getJavaVMStatistics(<portlet:namespace/>showNext)", 1000);
+DWREngine.setErrorHandler(null);
+<portlet:namespace/>stopped=false;
+function <portlet:namespace/>callServer() {
+    metadata = {};
+    metadata.callback=<portlet:namespace/>updateValues;
+    metadata.errorHandler=<portlet:namespace/>onError;
+    Jsr77Stats.getJavaVMStatistics(metadata);
+}
+function <portlet:namespace/>updateValues(serverStats) {
+    DWRUtil.setValue("<portlet:namespace/>CurrentMemory", serverStats.memoryCurrent);
+    DWRUtil.setValue("<portlet:namespace/>MostMemory", serverStats.memoryMost);
+    DWRUtil.setValue("<portlet:namespace/>AvailableMemory", serverStats.memoryAllocated);
+    DWRUtil.setValue("<portlet:namespace/>UpTime", serverStats.upTime);
+    if(!<portlet:namespace/>stopped) {
+        setTimeout("<portlet:namespace/>callServer()", 1000);
+    }
+}
+function <portlet:namespace/>onError() {
+    <portlet:namespace/>stopped=true;
+    DWRUtil.setValue("<portlet:namespace/>ErrorArea", '<form name="<portlet:namespace/>Refresh"
action="<portlet:actionURL/>"><input type="submit" value="Refresh"/></form>');
 }
-Jsr77Stats.getJavaVMStatistics(<portlet:namespace/>showNext);
+<portlet:namespace/>callServer();
 </script>
 



Mime
View raw message