KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > util > DOMPool


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/util/DOMPool.java,v 1.5.2.1 2004/06/12 20:29:05 sebb Exp $
2
/*
3  * Copyright 2003-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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
19 package org.apache.jmeter.protocol.http.util;
20
21 import java.util.HashMap JavaDoc;
22 import org.w3c.dom.Document JavaDoc;
23
24 /**
25  * The purpose of this class is to cache the DOM Documents in memory and
26  * by-pass parsing. For old systems or laptops, it's not practical to parse the
27  * XML documents every time. Therefore using a memory cache can reduce the CPU
28  * usage.
29  * <p>
30  * For now this is a simple version to test the feasibility of caching. If it
31  * works, this class will be replaced with an Apache commons or something
32  * equivalent. If I was familiar with Apache Commons Pool, I would probably
33  * use it, but since I don't know the API, it is quicker for Proof of Concept
34  * to just write a dumb one. If the number documents in the pool exceed several
35  * hundred, it will take a long time for the lookup.
36  * <p>
37  * Created on: Jun 17, 2003<br>
38  *
39  * @author Peter Lin
40  * @version $Revision: 1.5.2.1 $
41  */

42 public final class DOMPool
43 {
44     /**
45      * The cache is created with an initial size of 50. Running a webservice
46      * test on an old system will likely run into memory or CPU problems long
47      * before the HashMap is an issue.
48      */

49     private static HashMap JavaDoc MEMCACHE = new HashMap JavaDoc(50);
50
51     /**
52      * Return a document.
53      * @param key
54      * @return Document
55      */

56     public static Document JavaDoc getDocument(Object JavaDoc key)
57     {
58         return (Document JavaDoc) MEMCACHE.get(key);
59     }
60
61     /**
62      * Add an object to the cache.
63      * @param key
64      * @param data
65      */

66     public static void putDocument(Object JavaDoc key, Object JavaDoc data)
67     {
68         MEMCACHE.put(key, data);
69     }
70     
71     /**
72      * Private constructor to prevent instantiation.
73      */

74     private DOMPool()
75     {
76     }
77 }
78
Popular Tags