geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r224445 - in /geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console: infomanager/JavaSystemInfoPortlet.java infomanager/ServerInfoPortlet.java util/PortletManager.java
Date Sat, 23 Jul 2005 05:07:50 GMT
Author: ammulder
Date: Fri Jul 22 22:07:47 2005
New Revision: 224445

URL: http://svn.apache.org/viewcvs?rev=224445&view=rev
Log:
Add a helper class to interface with the management API and store the
  current objects we're working with in the session.
Revise the system info and server info portlets to use the management
  API (and clean them up a bit).

Added:
    geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/util/PortletManager.java
  (with props)
Modified:
    geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/infomanager/JavaSystemInfoPortlet.java
    geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/infomanager/ServerInfoPortlet.java

Modified: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/infomanager/JavaSystemInfoPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/infomanager/JavaSystemInfoPortlet.java?rev=224445&r1=224444&r2=224445&view=diff
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/infomanager/JavaSystemInfoPortlet.java
(original)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/infomanager/JavaSystemInfoPortlet.java
Fri Jul 22 22:07:47 2005
@@ -20,8 +20,8 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 import java.util.StringTokenizer;
+import java.util.Properties;
 
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
@@ -32,6 +32,7 @@
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.WindowState;
+import org.apache.geronimo.console.util.PortletManager;
 
 public class JavaSystemInfoPortlet extends GenericPortlet {
 
@@ -41,8 +42,6 @@
 
     private static final String HELPVIEW_JSP = "/WEB-INF/view/infomanager/javaSysHelp.jsp";
 
-    private static Map javaSysProps;
-
     private PortletRequestDispatcher normalView;
 
     private PortletRequestDispatcher maximizedView;
@@ -59,7 +58,8 @@
             return;
         }
 
-        javaSysProps = System.getProperties();
+        Properties javaSysProps = PortletManager.getCurrentJVM(renderRequest).getSystemProperties();
+
         renderRequest.setAttribute("javaSysProps", javaSysProps);
 
         String sep = (String) javaSysProps.get("path.separator");

Modified: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/infomanager/ServerInfoPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/infomanager/ServerInfoPortlet.java?rev=224445&r1=224444&r2=224445&view=diff
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/infomanager/ServerInfoPortlet.java
(original)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/infomanager/ServerInfoPortlet.java
Fri Jul 22 22:07:47 2005
@@ -22,7 +22,6 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.management.ObjectName;
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.GenericPortlet;
@@ -33,56 +32,22 @@
 import javax.portlet.RenderResponse;
 import javax.portlet.WindowState;
 
-import org.apache.geronimo.console.util.ObjectNameConstants;
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.console.util.PortletManager;
+import org.apache.geronimo.j2ee.management.geronimo.JVM;
 
+/**
+ * Calculates various information about the server to display in the server
+ * info portlet view (on of several JSPs depending on the portlet state).
+ *
+ * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
+ */
 public class ServerInfoPortlet extends GenericPortlet {
-
-    public static final String SVRINFO_BASEDIR = "baseDirectory";
-
-    public static final String SVRINFO_VERSION = "version";
-
-    public static final String SVRINFO_BUILDDATE = "buildDate";
-
-    public static final String SVRINFO_BUILDTIME = "buildTime";
-
-    public static final String SVRINFO_COPYRIGHT = "copyright";
-
-    public static final String SVRINFO_PLATFORMARCH = "platformArch";
-
-    public static final String SVRINFO_GERONIMO_BUILD_VERSION = "geronimoBuildVersion";
-
-    public static final String SVRINFO_GERONIMO_SPEC_VERSION = "geronimoSpecVersion";
-
-    public static final String SVRINFO_PORTAL_CORE_VERSION = "portalCoreVersion";
-
-    public static final String JVMIMPL_JAVAVER = "javaVersion";
-
-    public static final String JVMIMPL_JAVAVENDOR = "javaVendor";
-
-    public static final String JVMIMPL_NODE = "node";
-
-    public static final String JVMIMPL_FREEMEM = "freeMemory";
-
-    public static final String JVMIMPL_MAXMEM = "maxMemory";
-
-    public static final String JVMIMPL_TOTALMEM = "totalMemory";
-
-    public static final String JVMIMPL_AVAILABLEPROCS = "availableProcessors";
-
     private static final String NORMALVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoNormal.jsp";
 
     private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoMaximized.jsp";
 
     private static final String HELPVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoHelp.jsp";
 
-    private static Map svrProps = new HashMap();
-
-    private static Map jvmProps = new HashMap();
-
-    private Kernel kernel;
-
     private PortletRequestDispatcher normalView;
 
     private PortletRequestDispatcher maximizedView;
@@ -99,64 +64,27 @@
             return;
         }
 
-        try {
-            Object o = null;
+        Map svrProps = new HashMap();
+        Map jvmProps = new HashMap();
 
-            // Kernel boot time
-            Date bootDate = kernel.getBootTime();
-            long bootTime = bootDate.getTime() / 1000;
-            long currentTime = System.currentTimeMillis() / 1000;
-            long elapsedTime = currentTime - bootTime;
-            svrProps.put("Kernel Boot Time", bootDate);
-            svrProps.put("Kernel Up Time", calcElapsedTime(elapsedTime));
-
-            // Server info
-            /*
-             * ObjectName svrInfo = new
-             * ObjectName(ObjectNameConstants.SERVER_INFO_OBJECT_NAME); o =
-             * kernel.getAttribute(svrInfo, SVRINFO_BASEDIR); svrProps.put("Base
-             * Directory", o); ObjectName joeSvrInfo = new
-             * ObjectName(ObjectNameConstants.SE_SERVER_INFO_NAME); o =
-             * kernel.getAttribute(joeSvrInfo, SVRINFO_PLATFORMARCH);
-             * svrProps.put("Platform Architecture", o); o =
-             * kernel.getAttribute(joeSvrInfo, SVRINFO_VERSION);
-             * svrProps.put("Version", o); o = kernel.getAttribute(joeSvrInfo,
-             * SVRINFO_GERONIMO_BUILD_VERSION); svrProps.put("Apache Geronimo
-             * Build Version", o); o = kernel.getAttribute(joeSvrInfo,
-             * SVRINFO_GERONIMO_SPEC_VERSION); svrProps.put("J2EE Specifications
-             * Version", o); o = kernel.getAttribute(joeSvrInfo,
-             * SVRINFO_PORTAL_CORE_VERSION); svrProps.put("JSR 168 Portal
-             * Version", o); o = kernel.getAttribute(joeSvrInfo,
-             * SVRINFO_BUILDDATE); svrProps.put("Build Date", o); o =
-             * kernel.getAttribute(joeSvrInfo, SVRINFO_BUILDTIME);
-             * svrProps.put("Build Time", o); o =
-             * kernel.getAttribute(joeSvrInfo, SVRINFO_COPYRIGHT);
-             * svrProps.put("Copyright", o);
-             */
-            renderRequest.setAttribute("svrProps", svrProps);
-
-            // JVM info
-            ObjectName jvmImpl = new ObjectName(
-                    ObjectNameConstants.JVM_IMPL_NAME);
-            o = kernel.getAttribute(jvmImpl, JVMIMPL_JAVAVER);
-            jvmProps.put("Java Version", o);
-            o = kernel.getAttribute(jvmImpl, JVMIMPL_JAVAVENDOR);
-            jvmProps.put("Java Vendor", o);
-            o = kernel.getAttribute(jvmImpl, JVMIMPL_NODE);
-            jvmProps.put("Node", o);
-            o = kernel.getAttribute(jvmImpl, JVMIMPL_MAXMEM);
-            jvmProps.put("Max Memory", calcMemory((Long) o));
-            o = kernel.getAttribute(jvmImpl, JVMIMPL_TOTALMEM);
-            jvmProps.put("Total Memory", calcMemory((Long) o));
-            o = kernel.getAttribute(jvmImpl, JVMIMPL_FREEMEM);
-            jvmProps.put("Free Memory", calcMemory((Long) o));
-            o = kernel.getAttribute(jvmImpl, JVMIMPL_AVAILABLEPROCS);
-            jvmProps.put("Available Processors", o);
-            renderRequest.setAttribute("jvmProps", jvmProps);
-        } catch (Exception e) {
-            e.printStackTrace();
-            //throw new PortletException(e);
-        }
+        JVM jvm = PortletManager.getCurrentJVM(renderRequest);
+
+        Date bootDate = jvm.getKernelBootTime();
+        long bootTime = bootDate.getTime() / 1000;
+        long currentTime = System.currentTimeMillis() / 1000;
+        long elapsedTime = currentTime - bootTime;
+        svrProps.put("Kernel Boot Time", bootDate);
+        svrProps.put("Kernel Up Time", calcElapsedTime(elapsedTime));
+        renderRequest.setAttribute("svrProps", svrProps);
+
+        jvmProps.put("Java Version", jvm.getJavaVersion());
+        jvmProps.put("Java Vendor", jvm.getJavaVendor());
+        jvmProps.put("Node", jvm.getNode());
+        jvmProps.put("Max Memory", calcMemory(jvm.getMaxMemory()));
+        jvmProps.put("Total Memory", calcMemory(jvm.getTotalMemory()));
+        jvmProps.put("Free Memory", calcMemory(jvm.getFreeMemory()));
+        jvmProps.put("Available Processors", new Integer(jvm.getAvailableProcessors()));
+        renderRequest.setAttribute("jvmProps", jvmProps);
 
         if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
             normalView.include(renderRequest, renderResponse);
@@ -172,7 +100,6 @@
 
     public void init(PortletConfig portletConfig) throws PortletException {
         super.init(portletConfig);
-        kernel = KernelRegistry.getSingleKernel();
         normalView = portletConfig.getPortletContext().getRequestDispatcher(
                 NORMALVIEW_JSP);
         maximizedView = portletConfig.getPortletContext().getRequestDispatcher(
@@ -182,22 +109,13 @@
     }
 
     public void destroy() {
-        kernel = null;
         normalView = null;
         maximizedView = null;
         helpView = null;
         super.destroy();
     }
 
-    public static Map getServerInfo() {
-        return svrProps;
-    }
-
-    public static Map getJVMInfo() {
-        return jvmProps;
-    }
-
-    private String calcElapsedTime(long timeInSeconds) {
+    private static String calcElapsedTime(long timeInSeconds) {
         long days, hrs, mins, secs;
         days = timeInSeconds / 86400;
         timeInSeconds = timeInSeconds - (days * 86400);
@@ -220,9 +138,8 @@
         return sb.toString();
     }
 
-    private String calcMemory(Long memory) {
+    private static String calcMemory(long mem) {
         long mb, kb;
-        long mem = memory.longValue();
         mb = mem / 1048576;
         // If less than 10MB return as KB
         if (mb < 10) {

Added: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/util/PortletManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/util/PortletManager.java?rev=224445&view=auto
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/util/PortletManager.java
(added)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/util/PortletManager.java
Fri Jul 22 22:07:47 2005
@@ -0,0 +1,78 @@
+/**
+ *
+ * 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.util;
+
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletSession;
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.j2ee.management.J2EEDomain;
+import org.apache.geronimo.j2ee.management.J2EEServer;
+import org.apache.geronimo.j2ee.management.geronimo.JVM;
+
+/**
+ * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
+ */
+public class PortletManager {
+    private final static String HELPER_KEY = "org.apache.geronimo.console.ManagementHelper";
+    private final static String DOMAIN_KEY = "org.apache.geronimo.console.J2EEDomain";
+    private final static String SERVER_KEY = "org.apache.geronimo.console.J2EEServer";
+    private final static String JVM_KEY = "org.apache.geronimo.console.JVM";
+
+    private static ManagementHelper createHelper() {
+        //todo: consider making this configurable; we could easily connect to a remote kernel
if we wanted to
+        return new KernelManagementHelper(KernelRegistry.getSingleKernel());
+    }
+
+    public static ManagementHelper getManagementHelper(PortletRequest request) {
+        ManagementHelper helper = (ManagementHelper) request.getPortletSession(true).getAttribute(HELPER_KEY,
PortletSession.APPLICATION_SCOPE);
+        if(helper == null) {
+            helper = createHelper();
+            request.getPortletSession().setAttribute(HELPER_KEY, helper, PortletSession.APPLICATION_SCOPE);
+        }
+        return helper;
+    }
+
+    public static J2EEDomain getCurrentDomain(PortletRequest request) {
+        J2EEDomain domain = (J2EEDomain) request.getPortletSession(true).getAttribute(DOMAIN_KEY,
PortletSession.APPLICATION_SCOPE);
+        if(domain == null) {
+            domain = getManagementHelper(request).getDomains()[0]; //todo: some day, select
a domain
+            request.getPortletSession().setAttribute(DOMAIN_KEY, domain, PortletSession.APPLICATION_SCOPE);
+        }
+        return domain;
+
+    }
+
+    public static J2EEServer getCurrentServer(PortletRequest request) {
+        J2EEServer server = (J2EEServer) request.getPortletSession(true).getAttribute(SERVER_KEY,
PortletSession.APPLICATION_SCOPE);
+        if(server == null) {
+            ManagementHelper helper = getManagementHelper(request);
+            server = helper.getServers(getCurrentDomain(request))[0]; //todo: some day, select
a server from the domain
+            request.getPortletSession().setAttribute(SERVER_KEY, server, PortletSession.APPLICATION_SCOPE);
+        }
+        return server;
+    }
+
+    public static JVM getCurrentJVM(PortletRequest request) {
+        JVM jvm = (JVM) request.getPortletSession(true).getAttribute(JVM_KEY, PortletSession.APPLICATION_SCOPE);
+        if(jvm == null) {
+            ManagementHelper helper = getManagementHelper(request);
+            jvm = helper.getJavaVMs(getCurrentServer(request))[0]; //todo: some day, select
a JVM from the server
+            request.getPortletSession().setAttribute(JVM_KEY, jvm, PortletSession.APPLICATION_SCOPE);
+        }
+        return jvm;
+    }
+}

Propchange: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/util/PortletManager.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message