Skip to content

Commit 8deb381

Browse files
author
John McNally
committed
removed references to MemoryElementDescriptor outside of LRUMemoryCache.
moved common functionality of the LRU and MRU into a base class. PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/jcs/trunk@223991 13f79535-47bb-0310-9956-ffa450edef68
1 parent c2c2d68 commit 8deb381

File tree

7 files changed

+365
-399
lines changed

7 files changed

+365
-399
lines changed

src/java/org/apache/jcs/admin/servlet/JCSAdminServlet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import org.apache.jcs.engine.CacheConstants;
1414
import org.apache.jcs.engine.memory.MemoryCache;
15-
import org.apache.jcs.engine.memory.MemoryElementDescriptor;
1615
import org.apache.jcs.engine.behavior.ICache;
16+
import org.apache.jcs.engine.behavior.ICacheElement;
1717
import org.apache.jcs.engine.control.CompositeCacheManager;
1818
import org.apache.jcs.engine.control.CompositeCache;
1919
import org.apache.velocity.Template;
@@ -199,10 +199,10 @@ public int getByteCount( CompositeCache cache )
199199

200200
while ( iter.hasNext() )
201201
{
202-
MemoryElementDescriptor node = ( MemoryElementDescriptor )
202+
ICacheElement ce = (ICacheElement)
203203
( ( Map.Entry ) iter.next() ).getValue();
204204

205-
out.writeObject( node.ce.getVal() );
205+
out.writeObject( ce.getVal() );
206206
}
207207

208208
// 4 bytes lost for the serialization header

src/java/org/apache/jcs/engine/control/CompositeCache.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
import org.apache.jcs.engine.behavior.IElementAttributes;
7474

7575
import org.apache.jcs.engine.memory.MemoryCache;
76-
import org.apache.jcs.engine.memory.MemoryElementDescriptor;
7776
import org.apache.jcs.engine.memory.lru.LRUMemoryCache;
7877

7978
import org.apache.jcs.engine.control.event.ElementEvent;
@@ -802,14 +801,14 @@ protected void dispose( boolean fromRemote )
802801
{
803802
Map.Entry entry = ( Map.Entry ) itr.next();
804803

805-
MemoryElementDescriptor me = ( MemoryElementDescriptor ) entry.getValue();
804+
ICacheElement ce = (ICacheElement) entry.getValue();
806805
try
807806
{
808-
if ( aux.getCacheType() == ICacheType.LATERAL_CACHE && !me.ce.getElementAttributes().getIsLateral() )
807+
if ( aux.getCacheType() == ICacheType.LATERAL_CACHE && !ce.getElementAttributes().getIsLateral() )
809808
{
810809
continue;
811810
}
812-
aux.update( me.ce );
811+
aux.update( ce );
813812
}
814813
catch ( Exception e )
815814
{
@@ -868,9 +867,9 @@ public void save()
868867
{
869868
Map.Entry entry = ( Map.Entry ) itr.next();
870869

871-
MemoryElementDescriptor me = ( MemoryElementDescriptor ) entry.getValue();
870+
ICacheElement ce = (ICacheElement) entry.getValue();
872871

873-
aux.update( me.ce );
872+
aux.update(ce);
874873
}
875874
}
876875
}
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
package org.apache.jcs.engine.memory;
2+
3+
import java.io.IOException;
4+
import java.io.Serializable;
5+
import java.util.HashMap;
6+
import java.util.Hashtable;
7+
import java.util.Iterator;
8+
import java.util.Map;
9+
10+
import org.apache.commons.logging.Log;
11+
import org.apache.commons.logging.LogFactory;
12+
import org.apache.jcs.engine.CacheConstants;
13+
import org.apache.jcs.engine.CacheElement;
14+
import org.apache.jcs.engine.behavior.ICacheElement;
15+
import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
16+
import org.apache.jcs.engine.behavior.IElementAttributes;
17+
import org.apache.jcs.engine.control.CompositeCache;
18+
import org.apache.jcs.engine.memory.MemoryCache;
19+
import org.apache.jcs.engine.memory.shrinking.ShrinkerThread;
20+
import org.apache.jcs.engine.control.group.GroupId;
21+
import org.apache.jcs.engine.control.group.GroupAttrName;
22+
23+
/**
24+
* Some common code for the LRU and MRU caches.
25+
*
26+
*@author <a href="mailto:asmuts@yahoo.com">Aaron Smuts</a>
27+
*@author <a href="mailto:jtaylor@apache.org">James Taylor</a>
28+
*@author <a href="mailto:jmcnally@apache.org">John McNally</a>
29+
*@created May 13, 2002
30+
*@version $Id$
31+
*/
32+
public abstract class AbstractMemoryCache
33+
implements MemoryCache, Serializable
34+
{
35+
private final static Log log =
36+
LogFactory.getLog( AbstractMemoryCache.class );
37+
38+
protected String cacheName;
39+
40+
/**
41+
* Map where items are stored by key
42+
*/
43+
protected Map map;
44+
45+
/**
46+
* Region Elemental Attributes, used as a default.
47+
*/
48+
public IElementAttributes attr;
49+
50+
/**
51+
* Cache Attributes
52+
*/
53+
public ICompositeCacheAttributes cattr;
54+
55+
/**
56+
* The cache region this store is associated with
57+
*/
58+
protected CompositeCache cache;
59+
60+
// status
61+
protected int status;
62+
63+
// make configurable
64+
protected int chunkSize = 2;
65+
66+
/**
67+
* The background memory shrinker
68+
*/
69+
private ShrinkerThread shrinker;
70+
71+
72+
/**
73+
* Constructor for the LRUMemoryCache object
74+
*/
75+
public AbstractMemoryCache()
76+
{
77+
status = CacheConstants.STATUS_ERROR;
78+
map = new Hashtable();
79+
}
80+
81+
/**
82+
* For post reflection creation initialization
83+
*
84+
*@param hub
85+
*/
86+
public synchronized void initialize( CompositeCache hub )
87+
{
88+
this.cacheName = hub.getCacheName();
89+
this.cattr = hub.getCacheAttributes();
90+
this.cache = hub;
91+
92+
status = CacheConstants.STATUS_ALIVE;
93+
94+
if ( cattr.getUseMemoryShrinker() && shrinker == null )
95+
{
96+
shrinker = new ShrinkerThread( this );
97+
shrinker.setPriority( shrinker.MIN_PRIORITY );
98+
shrinker.start();
99+
}
100+
}
101+
102+
/**
103+
* Removes an item from the cache
104+
*
105+
*@param key Identifies item to be removed
106+
*@return Description of the Return Value
107+
*@exception IOException Description of the Exception
108+
*/
109+
public abstract boolean remove( Serializable key )
110+
throws IOException;
111+
112+
/**
113+
* Get an item from the cache
114+
*
115+
*@param key Description of the Parameter
116+
*@return Description of the Return Value
117+
*@exception IOException Description of the Exception
118+
*/
119+
public abstract ICacheElement get( Serializable key )
120+
throws IOException;
121+
122+
/**
123+
* Get an item from the cache without effecting its order or last access
124+
* time
125+
*
126+
*@param key Description of the Parameter
127+
*@return The quiet value
128+
*@exception IOException Description of the Exception
129+
*/
130+
public abstract ICacheElement getQuiet( Serializable key )
131+
throws IOException;
132+
133+
/**
134+
* Puts an item to the cache.
135+
*
136+
*@param ce Description of the Parameter
137+
*@exception IOException Description of the Exception
138+
*/
139+
public abstract void update( ICacheElement ce )
140+
throws IOException;
141+
142+
143+
/**
144+
* Get an Array of the keys for all elements in the memory cache
145+
*
146+
*@return An Object[]
147+
*/
148+
public abstract Object[] getKeyArray();
149+
150+
151+
/**
152+
* Removes all cached items from the cache.
153+
*
154+
* @exception IOException
155+
*/
156+
public void removeAll()
157+
throws IOException
158+
{
159+
map = new HashMap();
160+
}
161+
162+
/**
163+
* Prepares for shutdown.
164+
*
165+
* @exception IOException
166+
*/
167+
public void dispose()
168+
throws IOException
169+
{
170+
}
171+
172+
/**
173+
* Returns the cache statistics.
174+
*
175+
* @return The stats value
176+
*/
177+
public String getStats()
178+
{
179+
return "";
180+
}
181+
182+
/**
183+
* Returns the current cache size.
184+
*
185+
* @return The size value
186+
*/
187+
public int getSize()
188+
{
189+
return this.map.size();
190+
}
191+
192+
/**
193+
* Returns the cache status.
194+
*
195+
* @return The status value
196+
*/
197+
public int getStatus()
198+
{
199+
return this.status;
200+
//return this.STATUS_ALIVE;
201+
}
202+
203+
/**
204+
* Returns the cache name.
205+
*
206+
* @return The cacheName value
207+
*/
208+
public String getCacheName()
209+
{
210+
return this.cattr.getCacheName();
211+
}
212+
213+
/**
214+
* Puts an item to the cache.
215+
*
216+
* @param me
217+
* @exception IOException
218+
*/
219+
public void waterfal( ICacheElement ce )
220+
throws IOException
221+
{
222+
this.cache.spoolToDisk( ce );
223+
}
224+
225+
/**
226+
* Gets the iterator attribute of the LRUMemoryCache object
227+
*
228+
* @return The iterator value
229+
*/
230+
public Iterator getIterator()
231+
{
232+
return map.entrySet().iterator();
233+
}
234+
235+
/**
236+
* Returns the CacheAttributes.
237+
*
238+
* @return The CacheAttributes value
239+
*/
240+
public ICompositeCacheAttributes getCacheAttributes()
241+
{
242+
return this.cattr;
243+
}
244+
245+
/**
246+
* Sets the CacheAttributes.
247+
*
248+
* @param cattr The new CacheAttributes value
249+
*/
250+
public void setCacheAttributes( ICompositeCacheAttributes cattr )
251+
{
252+
this.cattr = cattr;
253+
}
254+
255+
/**
256+
* Gets the cache hub / region taht the MemoryCache is used by
257+
*
258+
*@return The cache value
259+
*/
260+
public CompositeCache getCompositeCache()
261+
{
262+
return this.cache;
263+
}
264+
}

src/java/org/apache/jcs/engine/memory/MemoryElementDescriptor.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
1111
import org.apache.jcs.engine.control.CompositeCache;
1212

13-
import org.apache.jcs.engine.memory.MemoryElementDescriptor;
1413
import org.apache.jcs.engine.control.CompositeCache;
1514

1615
/**

0 commit comments

Comments
 (0)