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.servermanager; 019 020 import java.io.IOException; 021 022 import javax.portlet.ActionRequest; 023 import javax.portlet.ActionResponse; 024 import javax.portlet.PortletConfig; 025 import javax.portlet.PortletException; 026 import javax.portlet.PortletRequestDispatcher; 027 import javax.portlet.RenderRequest; 028 import javax.portlet.RenderResponse; 029 030 import org.apache.commons.logging.Log; 031 import org.apache.commons.logging.LogFactory; 032 import org.apache.geronimo.console.BasePortlet; 033 import org.apache.geronimo.kernel.Kernel; 034 import org.apache.geronimo.kernel.KernelRegistry; 035 import org.apache.geronimo.system.main.Daemon; 036 037 public class ServerManagerPortlet extends BasePortlet { 038 039 private static final Log log = LogFactory.getLog(ServerManagerPortlet.class); 040 041 private PortletRequestDispatcher normalView; 042 043 private PortletRequestDispatcher shutdownView; 044 045 private PortletRequestDispatcher helpView; 046 047 private Kernel kernel; 048 049 public void processAction(ActionRequest actionRequest, 050 ActionResponse actionResponse) throws PortletException, IOException { 051 if (actionRequest.getParameter("reboot") != null) { 052 log.info("Reboot initiated by user request: " + actionRequest.getUserPrincipal().getName()); 053 new Thread() { 054 public void run() { 055 try { 056 Thread.sleep(2000); 057 } catch (InterruptedException e) { 058 } 059 kernel.shutdown(); 060 Daemon.main(new String[0]); 061 } 062 }.start(); 063 } 064 } 065 066 protected void doView(RenderRequest request, RenderResponse response) 067 throws PortletException, IOException { 068 if (request.getParameter("shutdown") != null) { 069 log.info("Shutting down by user request: " + request.getUserPrincipal().getName()); 070 shutdownView.include(request, response); 071 response.flushBuffer(); 072 kernel.shutdown(); 073 System.exit(0); 074 } else { 075 normalView.include(request, response); 076 } 077 } 078 079 protected void doHelp(RenderRequest renderRequest, 080 RenderResponse renderResponse) throws PortletException, IOException { 081 helpView.include(renderRequest, renderResponse); 082 } 083 084 public void init(PortletConfig portletConfig) throws PortletException { 085 super.init(portletConfig); 086 normalView = portletConfig.getPortletContext().getRequestDispatcher( 087 "/WEB-INF/view/servermanager/normal.jsp"); 088 shutdownView = portletConfig.getPortletContext().getRequestDispatcher( 089 "/WEB-INF/view/servermanager/shutdown.jsp"); 090 helpView = portletConfig.getPortletContext().getRequestDispatcher( 091 "/WEB-INF/view/servermanager/help.jsp"); 092 kernel = KernelRegistry.getSingleKernel(); 093 } 094 095 public void destroy() { 096 normalView = null; 097 shutdownView = null; 098 helpView = null; 099 super.destroy(); 100 } 101 102 }