You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2009/01/12 10:54:03 UTC
svn commit: r733664 - in
/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal:
servlet/OsgiManager.java system/ShutdownAction.java
system/ShutdownRender.java system/VMStatPlugin.java system/VMStatRender.java
Author: fmeschbe
Date: Mon Jan 12 01:54:01 2009
New Revision: 733664
URL: http://svn.apache.org/viewvc?rev=733664&view=rev
Log:
FELIX-873 Refactor VMStatRender with shutdown support into VMStatPlugin
and support framework restart through system bundle update
Added:
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java (with props)
Removed:
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/ShutdownAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/ShutdownRender.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatRender.java
Modified:
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java?rev=733664&r1=733663&r2=733664&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java Mon Jan 12 01:54:01 2009
@@ -128,9 +128,7 @@
"org.apache.felix.webconsole.internal.obr.InstallFromRepoAction",
"org.apache.felix.webconsole.internal.obr.RefreshRepoAction",
"org.apache.felix.webconsole.internal.system.GCAction",
- "org.apache.felix.webconsole.internal.system.ShutdownAction",
- "org.apache.felix.webconsole.internal.system.ShutdownRender",
- "org.apache.felix.webconsole.internal.system.VMStatRender", };
+ "org.apache.felix.webconsole.internal.system.VMStatPlugin" };
private BundleContext bundleContext;
Added: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java?rev=733664&view=auto
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java (added)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java Mon Jan 12 01:54:01 2009
@@ -0,0 +1,293 @@
+/*
+ * $Url: $
+ * $Id$
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.felix.webconsole.internal.system;
+
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Date;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.webconsole.internal.BaseWebConsolePlugin;
+import org.apache.felix.webconsole.internal.Util;
+import org.apache.felix.webconsole.internal.core.SetStartLevelAction;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.service.log.LogService;
+
+
+public class VMStatPlugin extends BaseWebConsolePlugin
+{
+
+ public static final String LABEL = "vmstat";
+
+ public static final String TITLE = "System Information";
+
+ private static final String ATTR_TERMINATED = "terminated";
+
+ private static final String PARAM_SHUTDOWN_TIMER = "shutdown_timer";
+ private static final String PARAM_SHUTDOWN_TYPE = "shutdown_type";
+
+ private static final String PARAM_SHUTDOWN_TYPE_RESTART = "Restart";
+ private static final String PARAM_SHUTDOWN_TYPE_STOP = "Stop";
+
+ private static final long startDate = ( new Date() ).getTime();
+
+
+ public String getLabel()
+ {
+ return LABEL;
+ }
+
+
+ public String getTitle()
+ {
+ return TITLE;
+ }
+
+
+ protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException,
+ IOException
+ {
+ if ( request.getParameter( PARAM_SHUTDOWN_TIMER ) == null )
+ {
+
+ // whether to stop or restart the framework
+ final boolean restart = PARAM_SHUTDOWN_TYPE_RESTART.equals( request.getParameter( PARAM_SHUTDOWN_TYPE ) );
+
+ // simply terminate VM in case of shutdown :-)
+ Thread t = new Thread( "Stopper" )
+ {
+ public void run()
+ {
+ try
+ {
+ Thread.sleep( 2000L );
+ }
+ catch ( InterruptedException ie )
+ {
+ // ignore
+ }
+
+ getLog().log( LogService.LOG_INFO, "Shutting down server now!" );
+
+ // stopping bundle 0 (system bundle) stops the framework
+ try
+ {
+ Bundle systemBundle = getBundleContext().getBundle( 0 );
+ if ( restart )
+ {
+ systemBundle.update();
+ }
+ else
+ {
+ systemBundle.stop();
+ }
+ }
+ catch ( BundleException be )
+ {
+ getLog().log( LogService.LOG_ERROR, "Problem stopping or restarting the Framework", be );
+ }
+ }
+ };
+ t.start();
+
+ request.setAttribute( ATTR_TERMINATED, ATTR_TERMINATED );
+ request.setAttribute( PARAM_SHUTDOWN_TYPE, new Boolean( restart ) );
+ }
+
+ // render the response without redirecting
+ doGet( request, response );
+ }
+
+
+ protected void renderContent( HttpServletRequest request, HttpServletResponse response ) throws ServletException,
+ IOException
+ {
+ PrintWriter pw = response.getWriter();
+
+ pw.println( "" );
+
+ if ( request.getAttribute( ATTR_TERMINATED ) != null )
+ {
+ pw.println( "<tr>" );
+ pw.println( "<td colspan='2' class='techcontentcell'>" );
+ pw.println( "<table class='content' cellpadding='0' cellspacing='0' width='100%'>" );
+ pw.println( "<tr class='content'>" );
+
+ Object restart = request.getAttribute( PARAM_SHUTDOWN_TYPE );
+ if ( ( restart instanceof Boolean ) && ( ( Boolean ) restart ).booleanValue() )
+ {
+ pw.println( "<th class='content important'>Framework is restarting. stand by ...</th>" );
+
+ pw.println( "<td class='content'>" );
+ pw.println( "<form name='reloadform' method='get'>" );
+ pw.println( "<input class='submit important' type='submit' value='Reload')\"> " );
+ pw.println( "Reloading in <span id='reloadcountdowncell'> </span>" );
+ pw.println( "<script language='JavaScript'>" );
+ pw.println( "shutdown(10, 'reloadform', 'reloadcountdowncell');" );
+ pw.println( "</script>" );
+
+ pw.println( "</form>" );
+ pw.println( "</td" );
+ }
+ else
+ {
+ pw.println( "<th class='content important'>Framework has been stopped.</th>" );
+ }
+
+ pw.println( "</tr>" );
+ pw.println( "</table>" );
+ pw.println( "</td>" );
+ pw.println( "</tr>" );
+ return;
+ }
+
+ boolean shutdownTimer = false;
+ String target = request.getRequestURI();
+ if ( request.getParameter( PARAM_SHUTDOWN_TIMER ) != null )
+ {
+ target = getLabel(); // ShutdownRender.NAME;
+ shutdownTimer = true;
+ }
+
+ pw.println( "<table class='content' cellpadding='0' cellspacing='0' width='100%'>" );
+
+ pw.println( "<tr class='content'>" );
+ pw.println( "<th colspan='2' class='content container'>Start Level Information:</th>" );
+ pw.println( "</tr>" );
+
+ pw.println( "<tr class='content'>" );
+ pw.println( "<td class='content'>System Start Level</td>" );
+ pw.println( "<td class='content'>" );
+ pw.println( "<form method='post'>" );
+ pw.println( "<input type='hidden' name='" + Util.PARAM_ACTION + "' value='" + SetStartLevelAction.NAME + "'>" );
+ pw.println( "<input class='input' type='text' size='3' name='systemStartLevel' value='"
+ + getStartLevel().getStartLevel() + "'/>" );
+ pw.println( " <input class='submit' type='submit' name='" + SetStartLevelAction.LABEL
+ + "' value='Change'>" );
+ pw.println( "</form>" );
+ pw.println( "</td>" );
+ pw.println( "</tr>" );
+ pw.println( "<tr class='content'>" );
+ pw.println( "<td class='content'>Default Bundle Start Level</td>" );
+ pw.println( "<td class='content'>" );
+ pw.println( "<form method='post'>" );
+ pw.println( "<input type='hidden' name='" + Util.PARAM_ACTION + "' value='" + SetStartLevelAction.NAME + "'>" );
+ pw.println( "<input class='input' type='text' size='3' name='bundleStartLevel' value='"
+ + getStartLevel().getInitialBundleStartLevel() + "'/>" );
+ pw.println( " <input class='submit' type='submit' name='" + SetStartLevelAction.LABEL
+ + "' value='Change'>" );
+ pw.println( "</form>" );
+ pw.println( "</td>" );
+ pw.println( "</tr>" );
+
+ pw.println( "<tr class='content'>" );
+ pw.println( "<td colspan='2' class='content'> </th>" );
+ pw.println( "</tr>" );
+
+ pw.println( "<tr class='content'>" );
+ pw.println( "<th colspan='2' class='content container'>Server Information:</th>" );
+ pw.println( "</tr>" );
+
+ pw.println( "<tr class='content'>" );
+ pw.println( "<td class='content'>Last Started</td>" );
+ pw.println( "<td class='content'>" );
+ pw.println( "<script language='JavaScript'>" );
+ pw.println( "localDate(" + startDate /* <%= Server.getStartTime() %> */
+ + ")" );
+ pw.println( "</script>" );
+ pw.println( "</td>" );
+ pw.println( "</tr>" );
+
+ pw.println( "<tr class='content'>" );
+ pw.println( "<form name='shutdownform' method='post' action='" + target + "'>" );
+ pw.println( "<td class='content'>Framework</td>" );
+ pw.println( "<td class='content'>" );
+
+ if ( !shutdownTimer )
+ {
+ pw.println( "<input type='hidden' name='" + PARAM_SHUTDOWN_TIMER + "' value='" + PARAM_SHUTDOWN_TIMER
+ + "'>" );
+ pw
+ .println( "<input class='submit important' type='submit' name='"
+ + PARAM_SHUTDOWN_TYPE
+ + "' value='Restart' onclick=\"return confirm('This will stop and restart the framework and all bundles. Please confirm to continue.')\">" );
+ pw
+ .println( "<input class='submit important' type='submit' name='"
+ + PARAM_SHUTDOWN_TYPE
+ + "' value='Stop' onclick=\"return confirm('This will stop the framework and all bundles. Please confirm to continue.')\">" );
+ }
+ else
+ {
+ pw.println( "<input type='hidden' name='" + PARAM_SHUTDOWN_TYPE + "' value='"
+ + request.getParameter( PARAM_SHUTDOWN_TYPE ) + "'>" );
+ pw.println( "<input class='submit important' type='button' value='Abort' onclick=\"abort('"
+ + request.getRequestURI() + "')\"> " );
+ pw.println( "Shutdown in <span id='countdowncell'> </span>" );
+ pw.println( "<script language='JavaScript'>" );
+ pw.println( "shutdown(3, 'shutdownform', 'countdowncell');" );
+ pw.println( "</script>" );
+ }
+
+ pw.println( "</td>" );
+ pw.println( "</form>" );
+ pw.println( "</tr>" );
+
+ pw.println( "<tr class='content'>" );
+ pw.println( "<td colspan='2' class='content'> </th>" );
+ pw.println( "</tr>" );
+
+ pw.println( "<tr class='content'>" );
+ pw.println( "<th colspan='2' class='content container'>Java Information:</th>" );
+ pw.println( "</tr>" );
+
+ long freeMem = Runtime.getRuntime().freeMemory() / 1024;
+ long totalMem = Runtime.getRuntime().totalMemory() / 1024;
+ long usedMem = totalMem - freeMem;
+
+ this.infoLine( pw, "Java Runtime", System.getProperty( "java.runtime.name" ) + "(build "
+ + System.getProperty( "java.runtime.version" ) + ")" );
+ this.infoLine( pw, "Java Virtual Machine", System.getProperty( "java.vm.name" ) + "(build "
+ + System.getProperty( "java.vm.version" ) + ", " + System.getProperty( "java.vm.info" ) + ")" );
+ this.infoLine( pw, "Total Memory", totalMem + " KB" );
+ this.infoLine( pw, "Used Memory", usedMem + " KB" );
+ this.infoLine( pw, "Free Memory", freeMem + " KB" );
+
+ pw.println( "<tr class='content'>" );
+ pw.println( "<form method='post'>" );
+ pw.println( "<td class='content'>Garbage Collection</td>" );
+ pw.println( "<td class='content'>" );
+ pw.println( "<input type='hidden' name='" + Util.PARAM_ACTION + "' value='" + GCAction.NAME + "'>" );
+ pw.println( "<input class='submit' type='submit' name='" + GCAction.LABEL + "' value='Run'>" );
+ pw.println( "</form></td></tr>" );
+
+ pw.println( "</table>" );
+ }
+
+
+ private void infoLine( PrintWriter pw, String label, String value )
+ {
+ pw.println( "<tr class='content'>" );
+ pw.println( "<td class='content'>" + label + "</td>" );
+ pw.println( "<td class='content'>" );
+ pw.println( value );
+ pw.println( "</td></tr>" );
+ }
+
+}
Propchange: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url