8000 apache/commons-jcs@18c0116 · GitHub
Skip to content

Commit 18c0116

Browse files
author
John McNally
committed
removed the GroupCache and GroupCacheHub and implemented the ability to get all the keys in a group or invalidate a group within each type of cache (a few do not support groups). The invalidation follows the model used by the special character in a String type of keys. PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/jcs/trunk@224004 13f79535-47bb-0310-9956-ffa450edef68
1 parent 665b142 commit 18c0116

29 files changed

+312
-1219
lines changed

src/java/org/apache/jcs/JCS.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
6060
import org.apache.jcs.engine.control.CompositeCache;
6161
import org.apache.jcs.engine.control.CompositeCacheManager;
62-
import org.apache.jcs.engine.control.group.GroupCacheHub;
6362

6463
/**
6564
* Simple class for using JCS. To use JCS in your application, you can use the
@@ -122,9 +121,9 @@ public static JCS getInstance( String region,
122121
}
123122

124123
/**
125-
* Gets an instance of GroupCacheHub and stores it in the cacheMgr class
124+
* Gets an instance of CompositeCacheManager and stores it in the cacheMgr class
126125
* field, if it is not already set. Unlike the implementation in
127-
* CacheAccess, the cache manager is a GroupCacheHub. NOTE: This can
126+
* CacheAccess, the cache manager is a CompositeCacheManager. NOTE: This can
128127
* will be moved up into GroupCacheAccess.
129128
*/
130129
protected static synchronized void ensureCacheManager()
@@ -133,11 +132,11 @@ protected static synchronized void ensureCacheManager()
133132
{
134133
if ( configFilename == null )
135134
{
136-
cacheMgr = GroupCacheHub.getInstance();
135+
cacheMgr = CompositeCacheManager.getInstance();
137136
}
138137
else
139138
{
140-
cacheMgr = GroupCacheHub.getUnconfiguredInstance();
139+
cacheMgr = CompositeCacheManager.getUnconfiguredInstance();
141140

14214 8096 1
cacheMgr.configure( configFilename );
143142
}

src/java/org/apache/jcs/access/GroupCacheAccess.java

Lines changed: 11 additions & 146 deletions
< 8096 td data-grid-cell-id="diff-4c83236ca0bdaf3aae9a42db562fbada83760d6863eb2976f829e0422111a33e-261-164-1" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-deletionNum-bgColor, var(--diffBlob-deletion-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
import org.apache.jcs.engine.control.CompositeCache;
7272
import org.apache.jcs.engine.control.CompositeCacheManager;
7373
import org.apache.jcs.engine.control.group.GroupAttrName;
74-
import org.apache.jcs.engine.control.group.GroupCacheHub;
7574
import org.apache.jcs.engine.control.group.GroupId;
7675

7776
/**
@@ -86,9 +85,6 @@ public class GroupCacheAccess extends CacheAccess implements IGroupCacheAccess
8685
private final static Log log =
8786
LogFactory.getLog( GroupCacheAccess.class );
8887

89-
private static boolean SET_ATTR_INVOCATION = true;
90-
private static boolean REMOVE_ATTR_INVOCATION = false;
91-
9288
private static CompositeCacheManager cacheMgr;
9389

9490
/**
@@ -115,7 +111,7 @@ public static GroupCacheAccess getGroupAccess( String region )
115111
{
116112
if ( cacheMgr == null )
117113
{
118-
cacheMgr = GroupCacheHub.getInstance();
114+
cacheMgr = CompositeCacheManager.getInstance();
119115
}
120116
}
121117
}
@@ -136,7 +132,7 @@ public static GroupCacheAccess getGroupAccess( String region, ICompositeCacheAtt
136132
{
137133
if ( cacheMgr == null )
138134
{
139-
cacheMgr = GroupCacheHub.getInstance();
135+
cacheMgr = CompositeCacheManager.getInstance();
140136
}
141137
}
142138
}
@@ -166,99 +162,6 @@ private GroupAttrName getGroupAttrName(String group, Object name)
166162
return new GroupAttrName(gid, name);
167163
}
168164

169-
/**
170-
* DefineGroup is used to create a new group object. Attributes may be set
171-
* on the group. If no attributes are specified, the attributes of the
172-
* region or group the new group is associated with are used. If group is
173-
* specified the new group will be associated with the group specified.
174-
*
175-
* @param name Name of the gorup.
176-
*/
177-
public void defineGroup( String name )
178-
throws CacheException
179-
{
180-
defineGroup(name, null);
181-
}
182-
183-
/**
184-
* Description of the Method
185-
*
186-
* @param name Name of the group
187-
* @param attr Default attributes for the group.
188-
*/
189-
public void defineGroup( String name, IElementAttributes attr )
190-
throws CacheException
191-
{
192-
// update the attribute name set.
193-
GroupId groupId = new GroupId( cacheControl.getCacheName(), name );
194-
if ( get(groupId) != null )
195-
{
196-
throw new CacheException( "group " + name + " already exists " );
197-
}
198-
199-
// TODO: revisit and verify that this works
200-
// not sure it will, need special id putting
201-
if (attr == null)
202-
{
203-
put( groupId, new HashSet() );
204-
}
205-
else
206-
{
207-
put( groupId, new HashSet(), attr );
208-
}
209-
}
210-
211-
/**
212-
* Gets the groupAttributes attribute of the GroupCacheAccess object.
213-
* Slighly confusing since the other method conside an "attribute" to be an
214-
* element of the cache and not the parameters governing an element.
215-
*
216-
* @return The Element Attributes for the group
217-
*/
218-
public IElementAttributes getGroupAttributes( String name )
219-
throws CacheException
220-
{
221-
IElementAttributes attr = null;
222-
try
223-
{
224-
attr = cacheControl.getElementAttributes( ( Serializable ) name );
225-
}
226-
catch ( IOException ioe )
227-
{
228-
throw new CacheException(
229-
"Failure getting element attributes due to ", ioe );
230-
}
231-
return attr;
232-
}
233-
234-
/**
235-
* Gets the attributeNames attribute of the GroupCacheAccess object
236-
*
237-
* @return The attributeNames value
238-
*/
239-
public Enumeration getAttributeNames( String group_name )
240-
{
241-
//Set s = getAttributeNameSet( name );
242-
//p( s.toString() );
243-
//return Collections.enumeration(s);
244-
return Collections.enumeration( getAttributeNameSet( group_name ) );
245-
}
246-
247-
/**
248-
* Gets the attributeNameSet attribute of the GroupCacheAccess object
249-
*
250-
* @return The attributeNameSet value
251-
*/
252-
public Set getAttributeNameSet( String groupName )
253-
{
254-
Object obj = get(new GroupId(cacheControl.getCacheName(), groupName));
255-
if ( obj == null || !( obj instanceof Set ) )
256-
{
257-
return new HashSet();
258-
}
259-
return (Set) obj;
260-
}
261-
262165
/**
263166
* Allows the user to put an object into a group within a particular cache
264167
* region. This method sets the object's attributes to the default for the
@@ -288,16 +191,8 @@ public void putInGroup( Object name, String groupName, Object value,
288191
IElementAttributes attr )
289192
throws CacheException
290193
{
291-
Set group = (Set)
292-
get(new GroupId(cacheControl.getCacheName(), groupName));
293-
if (group == null)
294-
{
295-
throw new CacheException(
296-
"Group must be defined prior to being used.");
297-
}
298-
299194
// unbind object first if any.
300-
boolean isPreviousObj = remove( name, groupName, false);
195+
remove( name, groupName);
301196

302197
if (attr == null)
303198
{
@@ -307,57 +202,27 @@ public void putInGroup( Object name, String groupName, Object value,
307202
{
308203
put( getGroupAttrName(groupName, name), value, attr );
309204
}
310-
311-
if (!isPreviousObj)
312-
{
313-
group.add(name);
314-
}
315205
}
316206

317207
/** Description of the Method */
318208
public void remove( Object name, String group )
319209
{
320-
remove( name, group, true );
210+
GroupAttrName key = getGroupAttrName( group, name );
211+
cacheControl.remove(key);
321212
}
322213

323-
/** Description of the Method */
324-
private boolean remove( Object name, String groupName,
325-
boolean removeFromGroup )
214+
/**
215+
* Gets the set of keys of objects currently in the group
216+
*/
217+
public Set getGroupKeys(String group)
326218
{
327-
GroupAttrName key = getGroupAttrName( groupName, name );
328-
// Needs to retrieve the attribute so as to do object unbinding,
329-
// if necessary.
330-
boolean isPreviousObj = cacheControl.get(key) != null;
331-
if (isPreviousObj)
332-
{
333-
cacheControl.remove(key);
334-
}
335-
if (removeFromGroup)
336-
{
337-
Set group = getAttributeNameSet(groupName);
338-
group.remove(name);
339-
}
340-
return isPreviousObj;
219+
return cacheControl.getGroupKeys(group);
341220
}
342221

222+
343223
/** Invalidates a group */
344224
public void invalidateGroup( String group )
345225
{
346-
// Removes all the attributes and attribute names from the Cache.
347-
// In doing so, need to unbind any object associated with the session.
348-
// need a static list not dependent on the current state of the source
349-
// remove each item, may want to try using partial delete here
350-
// move to gorupcache?
351-
Set set = getAttributeNameSet( group );
352-
Object[] ar = set.toArray();
353-
int arS = ar 56FB .length;
354-
for ( int i = 0; i < arS; i++ )
355-
{
356-
remove( ar[i], group, false );
357-
}
358-
359-
// get into concurrent modification problems here.
360-
// could make the removal of the ID invalidate the list?
361226
cacheControl.remove(new GroupId( cacheControl.getCacheName(), group ));
362227
}
363228
}

src/java/org/apache/jcs/access/behavior/IGroupCacheAccess.java

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* information on the Apache Software Foundation, please see
5454
* <http://www.apache.org/>.
5555
*/
56-
import java.util.Enumeration;
56+
import java.util.Set;
5757

5858
import org.apache.jcs.access.exception.CacheException;
5959

@@ -84,35 +84,14 @@ void putInGroup( Object key, String group, Object obj )
8484
void putInGroup( Object key, String group, Object obj, IElementAttributes attr )
8585
throws CacheException;
8686

87-
88-
/**
89-
* DefineGroup is used to create a new group object. IElementAttributes may be set
90-
* on the group. If no attributes are specified, the attributes of the
91-
* region or group the new group is associated with are used. If group is
92-
* specified the new group will be associated with the group specified.
93-
*/
94-
void defineGroup( String name )
95-
throws CacheException;
96-
97-
9887
/** Description of the Method */
99-
void defineGroup( String name, IElementAttributes attr )
100-
throws CacheException;
101-
88+
public void remove( Object name, String group );
10289

10390
/**
104-
* Gets the groupAttributes attribute of the IGroupCacheAccess object
105-
*
106-
* @return The groupAttributes value
91+
* Gets the set of keys of objects currently in the group
10792
*/
108-
IElementAttributes getGroupAttributes( String name )
109-
throws CacheException;
110-
93+
public Set getGroupKeys(String group);
11194

112-
/**
113-
* Gets the attributeNames attribute of the IGroupCacheAccess object
114-
*
115-
* @return The attributeNames value
116-
*/
117-
Enumeration getAttributeNames( String name );
95+
/** Invalidates a group */
96+
public void invalidateGroup( String group );
11897
}

src/java/org/apache/jcs/access/monitor/MonitorAccess.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.apache.jcs.access.GroupCacheAccess;
1212
import org.apache.jcs.engine.behavior.ICache;
1313
import org.apache.jcs.engine.control.CompositeCacheManager;
14-
import org.apache.jcs.engine.control.group.GroupCacheHub;
1514
import org.apache.jcs.engine.CacheConstants;
1615

1716
/**
@@ -38,7 +37,7 @@ public MonitorAccess()
3837
{
3938
if ( cacheMgr == null )
4039
{
41-
cacheMgr = GroupCacheHub.getInstance();
40+
cacheMgr = CompositeCacheManager.getInstance();
4241
}
4342
}
4443
}

src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.io.Serializable;
5+
import java.util.Set;
56

67
import org.apache.jcs.engine.behavior.ICache;
78
import org.apache.jcs.engine.behavior.ICacheElement;
@@ -42,4 +43,9 @@ public interface AuxiliaryCache extends ICache
4243

4344
/** Returns the cache name. */
4445
public String getCacheName();
46+
47+
/**
48+
* Gets the set of keys of objects currently in the group
49+
*/
50+
public Set getGroupKeys(String group);
4551
}

src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import java.io.IOException;
5858
import java.io.Serializable;
5959
import java.util.Hashtable;
60+
import java.util.Set;
6061

6162
import org.apache.commons.logging.Log;
6263
import org.apache.commons.logging.LogFactory;
@@ -252,6 +253,8 @@ public final ICacheElement get( Serializable key )
252253
return null;
253254
}
254255

256+
public abstract Set getGroupKeys(String groupName);
257+
255258
/**
256259
* @see org.apache.jcs.engine.behavior.ICache#remove
257260
*/
@@ -260,7 +263,6 @@ public final boolean remove( Serializable key )
260263
String keyAsString = key.toString();
261264

262265
writeLock( keyAsString );
263-
264266
try
265267
{
266268
// Remove element from purgatory if it is there

src/java/org/apache/jcs/auxiliary/disk/hsql/HSQLCache.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import java.sql.SQLException;
6969
import java.sql.Statement;
7070
import java.util.Properties;
71+
import java.util.Set;
7172

7273
import org.apache.commons.logging.Log;
7374
import org.apache.commons.logging.LogFactory;
@@ -80,6 +81,7 @@
8081
* HSQLDB Based Local Persistence.
8182
*
8283
* <b>VERY EXPERIMENTAL, and only partially implemented</b>
84+
* Requires String keys and does not work with groups.
8385
*
8486
* @author Aaron Smuts
8587
* @created January 15, 2002
@@ -498,6 +500,14 @@ static byte[] serialize( Serializable obj )
498500
return baos.toByteArray();
499501
}
500502

503+
public Set getGroupKeys(String groupName)
504+
{
505+
if (true)
506+
{
507+
throw new UnsupportedOperationException("Groups not implemented.");
508+
}
509+
return null;
510+
}
501511
}
502512

503513

0 commit comments

Comments
 (0)