001: /*
002: * Created on Aug 20, 2004 by pjacob
003: *
004: */
005: package com.whirlycott.cache.test;
006:
007: import java.io.Serializable;
008: import java.util.Collection;
009: import java.util.Collections;
010: import java.util.Map;
011: import java.util.Set;
012:
013: import net.sf.ehcache.Cache;
014: import net.sf.ehcache.CacheException;
015: import net.sf.ehcache.CacheManager;
016: import net.sf.ehcache.Element;
017: import net.sf.ehcache.ObjectExistsException;
018:
019: import com.whirlycott.cache.ManagedCache;
020:
021: /**
022: * @author pjacob
023: *
024: */
025: public class EhcacheImpl implements ManagedCache {
026:
027: protected Cache cache = null;
028:
029: public EhcacheImpl() {
030: CacheManager cacheManager = null;
031: try {
032: cacheManager = CacheManager.create();
033: } catch (CacheException e) {
034: e.printStackTrace();
035: }
036: cache = new Cache("test", Constants.STORE_COUNT, false, false,
037: 3600, 3600);
038: try {
039: cacheManager.addCache(cache);
040: } catch (IllegalStateException e1) {
041: e1.printStackTrace();
042: } catch (ObjectExistsException e1) {
043: e1.printStackTrace();
044: } catch (CacheException e1) {
045: e1.printStackTrace();
046: }
047:
048: }
049:
050: /* (non-Javadoc)
051: * @see com.whirlycott.cache.ManagedCache#setMostlyRead(boolean)
052: */
053: public void setMostlyRead(boolean _mostlyRead) {
054: // TODO Auto-generated method stub
055:
056: }
057:
058: /* (non-Javadoc)
059: * @see com.whirlycott.cache.ManagedCache#store(java.lang.Object, java.lang.Object)
060: */
061: public void store(Object k, Object v) {
062: Element e = new Element((Serializable) k, (Serializable) v);
063: cache.put(e);
064: }
065:
066: /* (non-Javadoc)
067: * @see java.util.Map#size()
068: */
069: public int size() {
070: // TODO Auto-generated method stub
071: return cache.getSize();
072: }
073:
074: /* (non-Javadoc)
075: * @see java.util.Map#clear()
076: */
077: public void clear() {
078: }
079:
080: /* (non-Javadoc)
081: * @see java.util.Map#isEmpty()
082: */
083: public boolean isEmpty() {
084: // TODO Auto-generated method stub
085: return false;
086: }
087:
088: /* (non-Javadoc)
089: * @see java.util.Map#containsKey(java.lang.Object)
090: */
091: public boolean containsKey(Object key) {
092: // TODO Auto-generated method stub
093: return false;
094: }
095:
096: /* (non-Javadoc)
097: * @see java.util.Map#containsValue(java.lang.Object)
098: */
099: public boolean containsValue(Object value) {
100: // TODO Auto-generated method stub
101: return false;
102: }
103:
104: /* (non-Javadoc)
105: * @see java.util.Map#values()
106: */
107: public Collection values() {
108: // TODO Auto-generated method stub
109: return null;
110: }
111:
112: /* (non-Javadoc)
113: * @see java.util.Map#putAll(java.util.Map)
114: */
115: public void putAll(Map t) {
116: // TODO Auto-generated method stub
117:
118: }
119:
120: /* (non-Javadoc)
121: * @see java.util.Map#entrySet()
122: */
123: public Set entrySet() {
124: return Collections.EMPTY_SET;
125: }
126:
127: /* (non-Javadoc)
128: * @see java.util.Map#keySet()
129: */
130: public Set keySet() {
131: // TODO Auto-generated method stub
132: return null;
133: }
134:
135: /* (non-Javadoc)
136: * @see java.util.Map#get(java.lang.Object)
137: */
138: public Object get(Object key) {
139: Object retval = null;
140: try {
141: retval = cache.get((Serializable) key);
142: } catch (IllegalStateException e) {
143: // TODO Auto-generated catch block
144: e.printStackTrace();
145: } catch (CacheException e) {
146: // TODO Auto-generated catch block
147: e.printStackTrace();
148: }
149: return retval;
150: }
151:
152: /* (non-Javadoc)
153: * @see java.util.Map#remove(java.lang.Object)
154: */
155: public Object remove(Object key) {
156: cache.remove((Serializable) key);
157: return null;
158: }
159:
160: /* (non-Javadoc)
161: * @see java.util.Map#put(java.lang.Object, java.lang.Object)
162: */
163: public Object put(Object key, Object value) {
164: final Element e = new Element((Serializable) key,
165: (Serializable) value);
166: cache.put(e);
167: return null;
168: }
169:
170: }
|