KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > store > MemoryStore


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

16 package org.apache.cocoon.components.store;
17
18 import org.apache.avalon.framework.thread.ThreadSafe;
19
20 import java.util.Enumeration JavaDoc;
21 import java.util.Hashtable JavaDoc;
22
23 /**
24  *
25  * @deprecated Use the Avalon Excalibur Store instead.
26  *
27  * @author <a HREF="mailto:scoobie@betaversion.org">Federico Barbieri</a>
28  * (Betaversion Productions)
29  * @author <a HREF="mailto:stefano@apache.org">Stefano Mazzocchi</a>
30  * (Apache Software Foundation)
31  * @author <a HREF="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
32  * (Apache Software Foundation)
33  * @version CVS $Id: MemoryStore.java 30932 2004-07-29 17:35:38Z vgritsenko $
34  */

35 public class MemoryStore implements Store, ThreadSafe {
36     /* WARNING: Hashtable is threadsafe, whereas HashMap is not.
37      * Should we move this class over to the Collections API,
38      * use Collections.synchronizedMap(Map map) to ensure
39      * accesses are synchronized.
40      */

41
42     /** The shared store */
43     private Hashtable JavaDoc table = new Hashtable JavaDoc();
44
45     /**
46      * Get the object associated to the given unique key.
47      */

48     public synchronized Object JavaDoc get(Object JavaDoc key) {
49         return(table.get(key));
50     }
51
52     /**
53      * Store the given object in a persistent state. It is up to the
54      * caller to ensure that the key has a persistent state across
55      * different JVM executions.
56      */

57     public synchronized void store(Object JavaDoc key, Object JavaDoc value) {
58         this.hold(key,value);
59     }
60
61     /**
62      * Holds the given object in a volatile state. This means
63      * the object store will discard held objects if the
64      * virtual machine is restarted or some error happens.
65      */

66     public synchronized void hold(Object JavaDoc key, Object JavaDoc value) {
67         table.put(key,value);
68     }
69
70     /**
71      * Remove the object associated to the given key.
72      */

73     public synchronized void remove(Object JavaDoc key) {
74         table.remove(key);
75     }
76
77     public synchronized void free() {}
78
79     /**
80      * Indicates if the given key is associated to a contained object.
81      */

82     public synchronized boolean containsKey(Object JavaDoc key) {
83         return(table.containsKey(key));
84     }
85
86     /**
87      * Returns the list of used keys as an Enumeration of Objects.
88      */

89     public synchronized Enumeration JavaDoc keys() {
90         return(table.keys());
91     }
92
93     /**
94      * Returns count of the objects in the store, or -1 if could not be
95      * obtained.
96      */

97     public synchronized int size()
98     {
99         return table.size();
100     }
101 }
102
Popular Tags