KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > servermanager > ServerManagerPortlet


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.console.servermanager;
19
20 import java.io.IOException JavaDoc;
21
22 import javax.portlet.ActionRequest;
23 import javax.portlet.ActionResponse;
24 import javax.portlet.PortletConfig;
25 import javax.portlet.PortletException;
26 import javax.portlet.PortletRequestDispatcher;
27 import javax.portlet.RenderRequest;
28 import javax.portlet.RenderResponse;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.geronimo.console.BasePortlet;
33 import org.apache.geronimo.kernel.Kernel;
34 import org.apache.geronimo.kernel.KernelRegistry;
35 import org.apache.geronimo.system.main.Daemon;
36
37 public class ServerManagerPortlet extends BasePortlet {
38
39     private static final Log log = LogFactory.getLog(ServerManagerPortlet.class);
40
41     private PortletRequestDispatcher normalView;
42
43     private PortletRequestDispatcher shutdownView;
44
45     private PortletRequestDispatcher helpView;
46
47     private Kernel kernel;
48
49     public void processAction(ActionRequest actionRequest,
50             ActionResponse actionResponse) throws PortletException, IOException JavaDoc {
51         if (actionRequest.getParameter("reboot") != null) {
52             log.info("Reboot initiated by user request: " + actionRequest.getUserPrincipal().getName());
53             new Thread JavaDoc() {
54                 public void run() {
55                     try {
56                         Thread.sleep(2000);
57                     } catch (InterruptedException JavaDoc e) {
58                     }
59                     kernel.shutdown();
60                     Daemon.main(new String JavaDoc[0]);
61                 }
62             }.start();
63         }
64     }
65
66     protected void doView(RenderRequest request, RenderResponse response)
67             throws PortletException, IOException JavaDoc {
68         if (request.getParameter("shutdown") != null) {
69             log.info("Shutting down by user request: " + request.getUserPrincipal().getName());
70             shutdownView.include(request, response);
71             response.flushBuffer();
72             kernel.shutdown();
73             System.exit(0);
74         } else {
75             normalView.include(request, response);
76         }
77     }
78
79     protected void doHelp(RenderRequest renderRequest,
80             RenderResponse renderResponse) throws PortletException, IOException JavaDoc {
81         helpView.include(renderRequest, renderResponse);
82     }
83
84     public void init(PortletConfig portletConfig) throws PortletException {
85         super.init(portletConfig);
86         normalView = portletConfig.getPortletContext().getRequestDispatcher(
87                 "/WEB-INF/view/servermanager/normal.jsp");
88         shutdownView = portletConfig.getPortletContext().getRequestDispatcher(
89                 "/WEB-INF/view/servermanager/shutdown.jsp");
90         helpView = portletConfig.getPortletContext().getRequestDispatcher(
91                 "/WEB-INF/view/servermanager/help.jsp");
92         kernel = KernelRegistry.getSingleKernel();
93     }
94
95     public void destroy() {
96         normalView = null;
97         shutdownView = null;
98         helpView = null;
99         super.destroy();
100     }
101
102 }
103
Popular Tags