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: 476321 $ $Date: 2006-11-17 16:18:49 -0500 (Fri, 17 Nov 2006) $
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 renderRequest.setAttribute("svrProps", svrProps);
077
078 jvmProps.put("Java Version", jvm.getJavaVersion());
079 jvmProps.put("Java Vendor", jvm.getJavaVendor());
080 jvmProps.put("Node", jvm.getNode());
081 jvmProps.put("Available Processors", new Integer(jvm.getAvailableProcessors()));
082 renderRequest.setAttribute("jvmProps", jvmProps);
083
084 if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
085 normalView.include(renderRequest, renderResponse);
086 } else {
087 maximizedView.include(renderRequest, renderResponse);
088 }
089 }
090
091 protected void doHelp(RenderRequest renderRequest,
092 RenderResponse renderResponse) throws PortletException, IOException {
093 helpView.include(renderRequest, renderResponse);
094 }
095
096 public void init(PortletConfig portletConfig) throws PortletException {
097 super.init(portletConfig);
098 normalView = portletConfig.getPortletContext().getRequestDispatcher(
099 NORMALVIEW_JSP);
100 maximizedView = portletConfig.getPortletContext().getRequestDispatcher(
101 MAXIMIZEDVIEW_JSP);
102 helpView = portletConfig.getPortletContext().getRequestDispatcher(
103 HELPVIEW_JSP);
104 }
105
106 public void destroy() {
107 normalView = null;
108 maximizedView = null;
109 helpView = null;
110 super.destroy();
111 }
112 }