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: */package org.apache.geronimo.console.infomanager;
017:
018: import java.io.IOException;
019: import java.util.Date;
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import javax.portlet.ActionRequest;
024: import javax.portlet.ActionResponse;
025: import javax.portlet.PortletConfig;
026: import javax.portlet.PortletException;
027: import javax.portlet.PortletRequestDispatcher;
028: import javax.portlet.RenderRequest;
029: import javax.portlet.RenderResponse;
030: import javax.portlet.WindowState;
031:
032: import org.apache.geronimo.console.BasePortlet;
033: import org.apache.geronimo.console.util.PortletManager;
034: import org.apache.geronimo.management.geronimo.JVM;
035: import org.apache.geronimo.system.serverinfo.ServerConstants;
036:
037: /**
038: * Calculates various information about the server to display in the server
039: * info portlet view (on of several JSPs depending on the portlet state).
040: *
041: * @version $Rev: 476321 $ $Date: 2006-11-17 13:18:49 -0800 (Fri, 17 Nov 2006) $
042: */
043: public class ServerInfoPortlet extends BasePortlet {
044: private static final String NORMALVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoNormal.jsp";
045:
046: private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoMaximized.jsp";
047:
048: private static final String HELPVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoHelp.jsp";
049:
050: private PortletRequestDispatcher normalView;
051:
052: private PortletRequestDispatcher maximizedView;
053:
054: private PortletRequestDispatcher helpView;
055:
056: public void processAction(ActionRequest actionRequest,
057: ActionResponse actionResponse) throws PortletException,
058: IOException {
059: }
060:
061: protected void doView(RenderRequest renderRequest,
062: RenderResponse renderResponse) throws IOException,
063: PortletException {
064: if (WindowState.MINIMIZED
065: .equals(renderRequest.getWindowState())) {
066: return;
067: }
068:
069: Map svrProps = new HashMap();
070: Map jvmProps = new HashMap();
071:
072: JVM jvm = PortletManager.getCurrentJVM(renderRequest);
073:
074: Date bootDate = jvm.getKernelBootTime();
075: svrProps.put("Kernel Boot Time", bootDate);
076: svrProps.put("Geronimo Version", ServerConstants.getVersion());
077: renderRequest.setAttribute("svrProps", svrProps);
078:
079: jvmProps.put("Java Version", jvm.getJavaVersion());
080: jvmProps.put("Java Vendor", jvm.getJavaVendor());
081: jvmProps.put("Node", jvm.getNode());
082: jvmProps.put("Available Processors", new Integer(jvm
083: .getAvailableProcessors()));
084: renderRequest.setAttribute("jvmProps", jvmProps);
085:
086: if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
087: normalView.include(renderRequest, renderResponse);
088: } else {
089: maximizedView.include(renderRequest, renderResponse);
090: }
091: }
092:
093: protected void doHelp(RenderRequest renderRequest,
094: RenderResponse renderResponse) throws PortletException,
095: IOException {
096: helpView.include(renderRequest, renderResponse);
097: }
098:
099: public void init(PortletConfig portletConfig)
100: throws PortletException {
101: super .init(portletConfig);
102: normalView = portletConfig.getPortletContext()
103: .getRequestDispatcher(NORMALVIEW_JSP);
104: maximizedView = portletConfig.getPortletContext()
105: .getRequestDispatcher(MAXIMIZEDVIEW_JSP);
106: helpView = portletConfig.getPortletContext()
107: .getRequestDispatcher(HELPVIEW_JSP);
108: }
109:
110: public void destroy() {
111: normalView = null;
112: maximizedView = null;
113: helpView = null;
114: super.destroy();
115: }
116: }
|