001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.store;
018:
019: import org.apache.avalon.framework.thread.ThreadSafe;
020:
021: import java.util.Enumeration;
022: import java.util.Hashtable;
023:
024: /**
025: *
026: * @deprecated Use the Avalon Excalibur Store instead.
027: *
028: * @author <a href="mailto:scoobie@betaversion.org">Federico Barbieri</a>
029: * (Betaversion Productions)
030: * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
031: * (Apache Software Foundation)
032: * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
033: * (Apache Software Foundation)
034: * @version CVS $Id: MemoryStore.java 433543 2006-08-22 06:22:54Z crossley $
035: */
036: public class MemoryStore implements Store, ThreadSafe {
037: /* WARNING: Hashtable is threadsafe, whereas HashMap is not.
038: * Should we move this class over to the Collections API,
039: * use Collections.synchronizedMap(Map map) to ensure
040: * accesses are synchronized.
041: */
042:
043: /** The shared store */
044: private Hashtable table = new Hashtable();
045:
046: /**
047: * Get the object associated to the given unique key.
048: */
049: public synchronized Object get(Object key) {
050: return (table.get(key));
051: }
052:
053: /**
054: * Store the given object in a persistent state. It is up to the
055: * caller to ensure that the key has a persistent state across
056: * different JVM executions.
057: */
058: public synchronized void store(Object key, Object value) {
059: this .hold(key, value);
060: }
061:
062: /**
063: * Holds the given object in a volatile state. This means
064: * the object store will discard held objects if the
065: * virtual machine is restarted or some error happens.
066: */
067: public synchronized void hold(Object key, Object value) {
068: table.put(key, value);
069: }
070:
071: /**
072: * Remove the object associated to the given key.
073: */
074: public synchronized void remove(Object key) {
075: table.remove(key);
076: }
077:
078: public synchronized void free() {
079: }
080:
081: /**
082: * Indicates if the given key is associated to a contained object.
083: */
084: public synchronized boolean containsKey(Object key) {
085: return (table.containsKey(key));
086: }
087:
088: /**
089: * Returns the list of used keys as an Enumeration of Objects.
090: */
091: public synchronized Enumeration keys() {
092: return (table.keys());
093: }
094:
095: /**
096: * Returns count of the objects in the store, or -1 if could not be
097: * obtained.
098: */
099: public synchronized int size() {
100: return table.size();
101: }
102: }
|