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