You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by le...@apache.org on 2004/06/18 12:24:39 UTC

svn commit: rev 21414 - excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http

Author: leif
Date: Fri Jun 18 03:24:38 2004
New Revision: 21414

Added:
   excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/HTMLGCHandler.java
   excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/XMLCreateSampleHandler.java
   excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/XMLGCHandler.java
   excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/XMLSampleLeaseHandler.java
Modified:
   excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/HTMLInstrumentManagerHandler.java
   excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/InstrumentManagerHTTPConnector.java
Log:
Add a way for users to invoke a GC from the HTML interface.
Add a few additional handlers for XML needed for the swing client.

Added: excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/HTMLGCHandler.java
==============================================================================
--- (empty file)
+++ excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/HTMLGCHandler.java	Fri Jun 18 03:24:38 2004
@@ -0,0 +1,83 @@
+/* 
+ * Copyright 2002-2004 The Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.excalibur.instrument.manager.http;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Map;
+
+import org.apache.excalibur.instrument.manager.http.server.HTTPRedirect;
+import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
+import org.apache.excalibur.instrument.manager.interfaces.InstrumentSampleDescriptor;
+import org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentSampleException;
+
+/**
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version CVS $Revision: 1.6 $ $Date: 2004/03/06 14:01:28 $
+ * @since 4.1
+ */
+public class HTMLGCHandler
+    extends AbstractHTMLHandler
+{
+    /*---------------------------------------------------------------
+     * Constructors
+     *-------------------------------------------------------------*/
+    /**
+     * Creates a new HTMLGCHandler.
+     *
+     * @param manager Reference to the InstrumentManagerClient.
+     */
+    public HTMLGCHandler( InstrumentManagerClient manager )
+    {
+        super( "/gc.html", manager );
+    }
+    
+    /*---------------------------------------------------------------
+     * AbstractHTTPURLHandler Methods
+     *-------------------------------------------------------------*/
+    /**
+     * Handles the specified request.
+     *
+     * @param The full path being handled.
+     * @param parameters A Map of the parameters in the request.
+     * @param os The PrintWriter to write the result to.
+     */
+    public void doGet( String path, Map parameters, PrintWriter out )
+        throws IOException
+    {
+        long oldMemory = getMemory();
+        
+        System.gc();
+        
+        long newMemory = getMemory();
+        
+        throw new HTTPRedirect(
+            "instrument-manager.html?oldMemory=" + oldMemory + "&newMemory=" + newMemory );
+    }
+            
+    /*---------------------------------------------------------------
+     * Methods
+     *-------------------------------------------------------------*/
+    private long getMemory()
+    {
+        Runtime rt = Runtime.getRuntime();
+        return rt.totalMemory() - rt.freeMemory();
+    }
+}
+

Modified: excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/HTMLInstrumentManagerHandler.java
==============================================================================
--- excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/HTMLInstrumentManagerHandler.java	(original)
+++ excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/HTMLInstrumentManagerHandler.java	Fri Jun 18 03:24:38 2004
@@ -59,6 +59,16 @@
     public void doGet( String path, Map parameters, PrintWriter out )
         throws IOException
     {
+        long oldMemory = getLongParameter( parameters, "oldMemory", 0 );
+        long newMemory = getLongParameter( parameters, "newMemory", 0 );
+        
+        String gcLabel = "<a href='gc.html'>Perform Garbage Collection</a>";
+        if ( ( oldMemory != 0 ) && ( newMemory != 0 ) )
+        {
+            gcLabel = gcLabel + " (Freed: " + ( oldMemory - newMemory ) + "bytes.  "
+                + "Now " + newMemory + " bytes.";
+        }
+        
         // This is the root
         out.println( "<html>" );
         out.println( "<head><title>" + getInstrumentManagerClient().getDescription()
@@ -66,11 +76,13 @@
         out.println( "<body>" );
         
         breadCrumbs( out, false );
+
         
         out.println( "<h2>Instrument Manager</h2>" );
         startTable( out );
         tableRow( out, 0, "Name", getInstrumentManagerClient().getName() );
         tableRow( out, 0, "Description", getInstrumentManagerClient().getDescription() );
+        tableRow( out, 0, "GC", gcLabel );
         endTable( out );
         
         InstrumentableDescriptor[] instrumentables =

Modified: excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/InstrumentManagerHTTPConnector.java
==============================================================================
--- excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/InstrumentManagerHTTPConnector.java	(original)
+++ excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/InstrumentManagerHTTPConnector.java	Fri Jun 18 03:24:38 2004
@@ -148,8 +148,13 @@
             initAndRegisterHandler(
                 new XMLInstrumentHandler( client ), nameBase + "instrument" );
             initAndRegisterHandler( new XMLSampleHandler( client ), nameBase + "sample" );
+            initAndRegisterHandler(
+                new XMLSampleLeaseHandler( client ), nameBase + "sample-lease" );
+            initAndRegisterHandler(
+                new XMLCreateSampleHandler( client ), nameBase + "create-sample" );
             initAndRegisterHandler(	new XMLSnapshotHandler( client ), nameBase + "snapshot" );
             initAndRegisterHandler(	new XMLSnapshotsHandler( client ), nameBase + "snapshots" );
+            initAndRegisterHandler(	new XMLGCHandler( client ), nameBase + "gc" );
         }
         
         if ( m_html )
@@ -168,6 +173,7 @@
             initAndRegisterHandler(
                 new HTMLCreateSampleHandler( client ), nameBase + "create-sample" );
             initAndRegisterHandler( new SampleChartHandler( client ), "sample-chart" );
+            initAndRegisterHandler(	new HTMLGCHandler( client ), nameBase + "gc" );
             initAndRegisterHandler( new HTMLRootHandler( client ), nameBase + "root" );
         }
         

Added: excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/XMLCreateSampleHandler.java
==============================================================================
--- (empty file)
+++ excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/XMLCreateSampleHandler.java	Fri Jun 18 03:24:38 2004
@@ -0,0 +1,97 @@
+/* 
+ * Copyright 2002-2004 The Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.excalibur.instrument.manager.http;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Map;
+
+import org.apache.excalibur.instrument.manager.http.server.HTTPRedirect;
+import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
+import org.apache.excalibur.instrument.manager.interfaces.InstrumentDescriptor;
+import org.apache.excalibur.instrument.manager.interfaces.InstrumentSampleDescriptor;
+import org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentException;
+
+/**
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version CVS $Revision: 1.6 $ $Date: 2004/03/06 14:01:28 $
+ * @since 4.1
+ */
+public class XMLCreateSampleHandler
+    extends AbstractXMLHandler
+{
+    /*---------------------------------------------------------------
+     * Constructors
+     *-------------------------------------------------------------*/
+    /**
+     * Creates a new XMLCreateSampleHandler.
+     *
+     * @param manager Reference to the InstrumentManagerClient.
+     */
+    public XMLCreateSampleHandler( InstrumentManagerClient manager )
+    {
+        super( "/create-sample.html", manager );
+    }
+    
+    /*---------------------------------------------------------------
+     * AbstractHTTPURLHandler Methods
+     *-------------------------------------------------------------*/
+    /**
+     * Handles the specified request.
+     *
+     * @param The full path being handled.
+     * @param parameters A Map of the parameters in the request.
+     * @param os The PrintWriter to write the result to.
+     */
+    public void doGet( String path, Map parameters, PrintWriter out )
+        throws IOException
+    {
+        String name = getParameter( parameters, "name" );
+        String description = getParameter( parameters, "description" );
+        long interval = getLongParameter( parameters, "interval" );
+        int size = getIntegerParameter( parameters, "size" );
+        long lease = getLongParameter( parameters, "lease" );
+        int type = getIntegerParameter( parameters, "type" );
+        boolean packed = ( getParameter( parameters, "packed", null ) != null );
+        
+        InstrumentDescriptor desc;
+        try
+        {
+            desc = getInstrumentManagerClient().locateInstrumentDescriptor( name );
+        }
+        catch ( NoSuchInstrumentException e )
+        {
+            throw new FileNotFoundException(
+                "The specified instrument does not exist: " + name );
+        }
+        
+        // Register the new lease
+        InstrumentSampleDescriptor sample =
+            desc.createInstrumentSample( description, interval, size, lease, type );
+        
+        out.println( InstrumentManagerHTTPConnector.XML_BANNER );
+        outputSample( out, sample, "", packed );
+    }
+            
+    /*---------------------------------------------------------------
+     * Methods
+     *-------------------------------------------------------------*/
+}
+

Added: excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/XMLGCHandler.java
==============================================================================
--- (empty file)
+++ excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/XMLGCHandler.java	Fri Jun 18 03:24:38 2004
@@ -0,0 +1,82 @@
+/* 
+ * Copyright 2002-2004 The Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.excalibur.instrument.manager.http;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Map;
+
+import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
+import org.apache.excalibur.instrument.manager.interfaces.InstrumentSampleDescriptor;
+import org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentSampleException;
+
+/**
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version CVS $Revision: 1.6 $ $Date: 2004/03/06 14:01:28 $
+ * @since 4.1
+ */
+public class XMLGCHandler
+    extends AbstractXMLHandler
+{
+    /*---------------------------------------------------------------
+     * Constructors
+     *-------------------------------------------------------------*/
+    /**
+     * Creates a new XMLGCHandler.
+     *
+     * @param manager Reference to the InstrumentManagerClient.
+     */
+    public XMLGCHandler( InstrumentManagerClient manager )
+    {
+        super( "/gc.xml", manager );
+    }
+    
+    /*---------------------------------------------------------------
+     * AbstractHTTPURLHandler Methods
+     *-------------------------------------------------------------*/
+    /**
+     * Handles the specified request.
+     *
+     * @param The full path being handled.
+     * @param parameters A Map of the parameters in the request.
+     * @param os The PrintWriter to write the result to.
+     */
+    public void doGet( String path, Map parameters, PrintWriter out )
+        throws IOException
+    {
+        long oldMemory = getMemory();
+        
+        System.gc();
+        
+        long newMemory = getMemory();
+        
+        out.println( InstrumentManagerHTTPConnector.XML_BANNER );
+        out.println( "<gc old-memory=\"" + oldMemory + "\" new-memory=\"" + newMemory + "\"/>" );
+    }
+            
+    /*---------------------------------------------------------------
+     * Methods
+     *-------------------------------------------------------------*/
+    private long getMemory()
+    {
+        Runtime rt = Runtime.getRuntime();
+        return rt.totalMemory() - rt.freeMemory();
+    }
+}
+

Added: excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/XMLSampleLeaseHandler.java
==============================================================================
--- (empty file)
+++ excalibur/trunk/instrument-manager/http/src/java/org/apache/excalibur/instrument/manager/http/XMLSampleLeaseHandler.java	Fri Jun 18 03:24:38 2004
@@ -0,0 +1,90 @@
+/* 
+ * Copyright 2002-2004 The Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.excalibur.instrument.manager.http;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Map;
+
+import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
+import org.apache.excalibur.instrument.manager.interfaces.InstrumentSampleDescriptor;
+import org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentSampleException;
+
+/**
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version CVS $Revision: 1.6 $ $Date: 2004/03/06 14:01:28 $
+ * @since 4.1
+ */
+public class XMLSampleLeaseHandler
+    extends AbstractXMLHandler
+{
+    /*---------------------------------------------------------------
+     * Constructors
+     *-------------------------------------------------------------*/
+    /**
+     * Creates a new XMLSampleLeaseHandler.
+     *
+     * @param manager Reference to the InstrumentManagerClient.
+     */
+    public XMLSampleLeaseHandler( InstrumentManagerClient manager )
+    {
+        super( "/sample-lease.xml", manager );
+    }
+    
+    /*---------------------------------------------------------------
+     * AbstractHTTPURLHandler Methods
+     *-------------------------------------------------------------*/
+    /**
+     * Handles the specified request.
+     *
+     * @param The full path being handled.
+     * @param parameters A Map of the parameters in the request.
+     * @param os The PrintWriter to write the result to.
+     */
+    public void doGet( String path, Map parameters, PrintWriter out )
+        throws IOException
+    {
+        String name = getParameter( parameters, "name" );
+        long lease = getLongParameter( parameters, "lease" );
+        boolean packed = ( getParameter( parameters, "packed", null ) != null );
+        
+        InstrumentSampleDescriptor desc;
+        try
+        {
+            desc = getInstrumentManagerClient().locateInstrumentSampleDescriptor( name );
+        }
+        catch ( NoSuchInstrumentSampleException e )
+        {
+            throw new FileNotFoundException(
+                "The specified instrument does not exist: " + name );
+        }
+        
+        // Renew the lease
+        desc.extendLease( lease );
+        
+        out.println( InstrumentManagerHTTPConnector.XML_BANNER );
+        outputSample( out, desc, "", packed );
+    }
+            
+    /*---------------------------------------------------------------
+     * Methods
+     *-------------------------------------------------------------*/
+}
+

---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org