001: /**********************************************************************
002: Copyright (c) 2003 Erik Bengtson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015:
016: Contributors:
017: ...
018: **********************************************************************/package org.jpox.cache;
019:
020: import java.util.Collection;
021: import java.util.Map;
022: import java.util.Set;
023:
024: import org.jpox.util.SoftValueMap;
025:
026: /**
027: * Level 1 Cache using Soft referenced objects in a Map.
028: * <P>If map entry value object is not actively being used, i.e. no other
029: * object has a strong reference to it, it may become garbage collected at
030: * the discretion of the garbage collector (typically if the VM is low on
031: * memory). If this happens, the entry in the <code>SoftValueMap</code>
032: * corresponding to the value object will also be removed.
033: *
034: * @see java.lang.ref.SoftReference
035: * @version $Revision: 1.4 $
036: */
037: public class SoftRefCache implements Level1Cache {
038: private Map softCache = new SoftValueMap();
039:
040: /**
041: * Default constructor (required)
042: */
043: public SoftRefCache() {
044: //default constructor
045: }
046:
047: public Object put(Object key, Object value) {
048: return softCache.put(key, value);
049: }
050:
051: public Object get(Object key) {
052: return softCache.get(key);
053: }
054:
055: public boolean containsKey(Object key) {
056: return softCache.containsKey(key);
057: }
058:
059: public Object remove(Object key) {
060: return softCache.remove(key);
061: }
062:
063: public void clear() {
064: softCache.clear();
065: }
066:
067: /* (non-Javadoc)
068: * @see java.util.Map#containsValue(java.lang.Object)
069: */
070: public boolean containsValue(Object value) {
071: return softCache.containsValue(value);
072: }
073:
074: /* (non-Javadoc)
075: * @see java.util.Map#entrySet()
076: */
077: public Set entrySet() {
078: return softCache.entrySet();
079: }
080:
081: /* (non-Javadoc)
082: * @see java.util.Map#isEmpty()
083: */
084: public boolean isEmpty() {
085: return softCache.isEmpty();
086: }
087:
088: /* (non-Javadoc)
089: * @see java.util.Map#keySet()
090: */
091: public Set keySet() {
092: return softCache.keySet();
093: }
094:
095: /* (non-Javadoc)
096: * @see java.util.Map#putAll(java.util.Map)
097: */
098: public void putAll(Map t) {
099: softCache.putAll(t);
100: }
101:
102: /* (non-Javadoc)
103: * @see java.util.Map#size()
104: */
105: public int size() {
106: return softCache.size();
107: }
108:
109: /* (non-Javadoc)
110: * @see java.util.Map#values()
111: */
112: public Collection values() {
113: return softCache.values();
114: }
115: }
|