001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.console.infomanager; 019 020 import java.io.IOException; 021 import java.util.Date; 022 import java.util.HashMap; 023 import java.util.Map; 024 025 import javax.portlet.ActionRequest; 026 import javax.portlet.ActionResponse; 027 import javax.portlet.PortletConfig; 028 import javax.portlet.PortletException; 029 import javax.portlet.PortletRequestDispatcher; 030 import javax.portlet.RenderRequest; 031 import javax.portlet.RenderResponse; 032 import javax.portlet.WindowState; 033 034 import org.apache.geronimo.console.BasePortlet; 035 import org.apache.geronimo.console.util.PortletManager; 036 import org.apache.geronimo.management.geronimo.JVM; 037 import org.apache.geronimo.system.serverinfo.ServerConstants; 038 039 /** 040 * Calculates various information about the server to display in the server 041 * info portlet view (on of several JSPs depending on the portlet state). 042 * 043 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 044 */ 045 public class ServerInfoPortlet extends BasePortlet { 046 private static final String NORMALVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoNormal.jsp"; 047 048 private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoMaximized.jsp"; 049 050 private static final String HELPVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoHelp.jsp"; 051 052 private PortletRequestDispatcher normalView; 053 054 private PortletRequestDispatcher maximizedView; 055 056 private PortletRequestDispatcher helpView; 057 058 public void processAction(ActionRequest actionRequest, 059 ActionResponse actionResponse) throws PortletException, IOException { 060 } 061 062 protected void doView(RenderRequest renderRequest, 063 RenderResponse renderResponse) throws IOException, PortletException { 064 if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) { 065 return; 066 } 067 068 Map svrProps = new HashMap(); 069 Map jvmProps = new HashMap(); 070 071 JVM jvm = PortletManager.getCurrentJVM(renderRequest); 072 073 Date bootDate = jvm.getKernelBootTime(); 074 svrProps.put("Kernel Boot Time", bootDate); 075 svrProps.put("Geronimo Version", ServerConstants.getVersion()); 076 svrProps.put("Build", ServerConstants.getBuildDate() + "-" + ServerConstants.getBuildTime()); 077 svrProps.put("os.name", System.getProperty("os.name")); 078 svrProps.put("os.version", System.getProperty("os.version")); 079 svrProps.put("sun.os.patch.level", System.getProperty("sun.os.patch.level")); 080 svrProps.put("os.arch", System.getProperty("os.arch")); 081 svrProps.put("os.locale", System.getProperty("user.language") + "_" + System.getProperty("user.country")); 082 renderRequest.setAttribute("svrProps", svrProps); 083 084 jvmProps.put("Java Version", jvm.getJavaVersion()); 085 jvmProps.put("Java Vendor", jvm.getJavaVendor()); 086 jvmProps.put("Node", jvm.getNode()); 087 jvmProps.put("Available Processors", new Integer(jvm.getAvailableProcessors())); 088 renderRequest.setAttribute("jvmProps", jvmProps); 089 090 if (WindowState.NORMAL.equals(renderRequest.getWindowState())) { 091 normalView.include(renderRequest, renderResponse); 092 } else { 093 maximizedView.include(renderRequest, renderResponse); 094 } 095 } 096 097 protected void doHelp(RenderRequest renderRequest, 098 RenderResponse renderResponse) throws PortletException, IOException { 099 helpView.include(renderRequest, renderResponse); 100 } 101 102 public void init(PortletConfig portletConfig) throws PortletException { 103 super.init(portletConfig); 104 normalView = portletConfig.getPortletContext().getRequestDispatcher( 105 NORMALVIEW_JSP); 106 maximizedView = portletConfig.getPortletContext().getRequestDispatcher( 107 MAXIMIZEDVIEW_JSP); 108 helpView = portletConfig.getPortletContext().getRequestDispatcher( 109 HELPVIEW_JSP); 110 } 111 112 public void destroy() { 113 normalView = null; 114 maximizedView = null; 115 helpView = null; 116 super.destroy(); 117 } 118 }