KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > manager > http > XMLGCHandler


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
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package org.apache.excalibur.instrument.manager.http;
21
22 import java.io.IOException JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.apache.excalibur.instrument.manager.DefaultInstrumentManager;
27 import org.apache.excalibur.instrument.manager.InstrumentSampleDescriptor;
28 import org.apache.excalibur.instrument.manager.NoSuchInstrumentSampleException;
29
30 /**
31  *
32  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
33  * @version CVS $Revision: 1.6 $ $Date: 2004/03/06 14:01:28 $
34  * @since 4.1
35  */

36 public class XMLGCHandler
37     extends AbstractXMLHandler
38 {
39     /*---------------------------------------------------------------
40      * Constructors
41      *-------------------------------------------------------------*/

42     /**
43      * Creates a new XMLGCHandler.
44      *
45      * @param manager Reference to the DefaultInstrumentManager.
46      * @param connector The InstrumentManagerHTTPConnector.
47      */

48     public XMLGCHandler( DefaultInstrumentManager manager,
49                          InstrumentManagerHTTPConnector connector )
50     {
51         super( "/gc.xml", manager, connector );
52     }
53     
54     /*---------------------------------------------------------------
55      * AbstractHTTPURLHandler Methods
56      *-------------------------------------------------------------*/

57     /**
58      * Handles the specified request.
59      *
60      * @param The full path being handled.
61      * @param parameters A Map of the parameters in the request.
62      * @param os The PrintWriter to write the result to.
63      */

64     public void doGet( String JavaDoc path, Map JavaDoc parameters, PrintWriter JavaDoc out )
65         throws IOException JavaDoc
66     {
67         long oldMemory = getMemory();
68         
69         System.gc();
70         
71         long newMemory = getMemory();
72         
73         out.println( InstrumentManagerHTTPConnector.XML_BANNER );
74         out.println( "<gc old-memory=\"" + oldMemory + "\" new-memory=\"" + newMemory + "\"/>" );
75     }
76             
77     /*---------------------------------------------------------------
78      * Methods
79      *-------------------------------------------------------------*/

80     private long getMemory()
81     {
82         Runtime JavaDoc rt = Runtime.getRuntime();
83         return rt.totalMemory() - rt.freeMemory();
84     }
85 }
86
87
Popular Tags