Skip to content

Commit 5cc026f

Browse files
author
John McNally
committed
keeping the two parts of the GroupId key separate.
using the GroupId in GroupAttrName instead of only part of it. made appropriate changes to GroupCache to account for the above changes. PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/jcs/trunk@223989 13f79535-47bb-0310-9956-ffa450edef68
1 parent 047066d commit 5cc026f

File tree

3 files changed

+61
-45
lines changed

3 files changed

+61
-45
lines changed

src/java/org/apache/jcs/engine/control/group/GroupAttrName.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,32 @@
66
* Description of the Class
77
*
88
* @author asmuts
9+
* @author <a href="mailto:jmcnally@apache.org">John McNally</a>
910
* @created January 15, 2002
1011
*/
1112
public class GroupAttrName implements Serializable
1213
{
1314
//final GroupId groupId;
1415
/** Description of the Field */
15-
public final String groupId;
16-
final Object attrName;
17-
16+
public final GroupId groupId;
17+
public final Object attrName;
18+
private String toString;
1819

1920
/**
2021
* Constructor for the GroupAttrName object
2122
*
2223
* @param groupId
2324
* @param attrName
2425
*/
25-
public GroupAttrName( String groupId, Object attrName )
26+
public GroupAttrName( GroupId groupId, Object attrName )
2627
{
27-
//this.groupId = new GroupId(groupId);
2828
this.groupId = groupId;
2929
this.attrName = attrName;
3030

3131
if ( groupId == null || attrName == null )
3232
{
33-
throw new IllegalArgumentException( "groupId " + groupId + " and attrName " + attrName + ", must not be null." );
33+
throw new IllegalArgumentException( "groupId " + groupId +
34+
" and attrName " + attrName + ", must not be null." );
3435
}
3536
}
3637

@@ -57,7 +58,13 @@ public int hashCode()
5758
/** Description of the Method */
5859
public String toString()
5960
{
60-
return "[groupId=" + groupId + ", attrName=" + attrName + "]";
61+
if (toString == null)
62+
{
63+
toString = "[GAN: groupId=" + groupId +
64+
", attrName=" + attrName + "]";
65+
}
66+
67+
return toString;
6168
}
6269

6370
}

src/java/org/apache/jcs/engine/control/group/GroupCache.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,15 @@ public ICacheElement getGAN( GroupAttrName key, boolean invocation )
231231

232232
Object obj = null;
233233
// not necessary?, stops at getaux
234-
readLock( key.groupId );
234+
readLock( key.groupId.toString() );
235235
try
236236
{
237237
obj = super.get( key, invocation );
238238
//p( "got obj" );
239239
}
240240
finally
241241
{
242-
locker.done( key.groupId );
242+
locker.done( key.groupId.toString() );
243243
}
244244
return ( ICacheElement ) obj;
245245
}
@@ -279,18 +279,18 @@ public ICacheElement getGI( GroupId gid, boolean invocation )
279279
}
280280
}
281281
Object obj = null;
282-
readLock( gid.key );
282+
readLock( gid.toString() );
283283
try
284284
{
285285
if ( invocation )
286286
{
287287
// Invocation is NOT local
288-
obj = systemGroupIdCache.localGet( gid.key );
288+
obj = systemGroupIdCache.localGet( gid.toString() );
289289
}
290290
else
291291
{
292292
// Invocation is local
293-
obj = systemGroupIdCache.get( gid.key );
293+
obj = systemGroupIdCache.get( gid.toString() );
294294
}
295295

296296
if ( log.isDebugEnabled() )
@@ -300,7 +300,7 @@ public ICacheElement getGI( GroupId gid, boolean invocation )
300300
}
301301
finally
302302
{
303-
locker.done( gid.key );
303+
locker.done( gid.toString() );
304304
}
305305

306306
return ( ICacheElement ) obj;
@@ -581,7 +581,7 @@ public void putGAN( GroupAttrName key, Serializable val,
581581
log.debug( "in putGAN( gan,val,attr,boolean invocation) " );
582582
}
583583

584-
writeLock( key.groupId );
584+
writeLock( key.toString() );
585585
try
586586
{
587587

@@ -598,9 +598,9 @@ public void putGAN( GroupAttrName key, Serializable val,
598598
super.update( ce, localOnly );
599599

600600
// UPDATE THE ATTRIBUTENAME LIST, get it first
601-
GroupId groupId = new GroupId( this.getCacheName(), key.groupId );
601+
GroupId groupId = key.groupId;
602602
HashSet attrNameSet = null;
603-
attrNameSet = ( HashSet ) systemGroupIdCache.get( groupId.key );
603+
attrNameSet = (HashSet)systemGroupIdCache.get(groupId.toString());
604604

605605
if ( attrNameSet == null )
606606
{
@@ -613,7 +613,7 @@ public void putGAN( GroupAttrName key, Serializable val,
613613
log.debug( "putGAN( gan,val,attr,boolean invocation) > attrNameSet.size() = " + attrNameSet.size() );
614614
}
615615

616-
CacheElement ceID = new CacheElement( this.getCacheName(), groupId.key, attrNameSet );
616+
CacheElement ceID = new CacheElement( this.getCacheName(), groupId, attrNameSet );
617617
ceID.setElementAttributes( attrE );
618618

619619
// DO NOT SEND THE UPDATE LIST REMOTELY
@@ -623,7 +623,7 @@ public void putGAN( GroupAttrName key, Serializable val,
623623
}
624624
finally
625625
{
626-
locker.done( key.groupId );
626+
locker.done( key.toString() );
627627
}
628628
}
629629

@@ -642,7 +642,7 @@ protected void createGroup( String group, IElementAttributes attrE )
642642
GroupId groupId = new GroupId( this.getCacheName(), group );
643643
HashSet attrNameSet = null;
644644

645-
attrNameSet = ( HashSet ) systemGroupIdCache.get( groupId.key );
645+
attrNameSet = ( HashSet ) systemGroupIdCache.get( groupId.toString() );
646646

647647
if ( attrNameSet == null )
648648
{
@@ -654,7 +654,7 @@ protected void createGroup( String group, IElementAttributes attrE )
654654
}
655655
try
656656
{
657-
CacheElement ceID = new CacheElement( this.getCacheName(), groupId.key, attrNameSet );
657+
CacheElement ceID = new CacheElement( this.getCacheName(), groupId, attrNameSet );
658658
ceID.setElementAttributes( attrE );
659659
//updateCaches(groupId.key, attrNameSet, attrE );
660660
//super.update( ceID, EXCLUDE_REMOTE_CACHE );
@@ -807,19 +807,19 @@ public void updateGroupAttrNameSet( GroupAttrName key,
807807

808808
// update the attribute name set.
809809
// Note: necessary to use super.get to avoid read lock within the current write lock.
810-
GroupId groupId = new GroupId( this.getCacheName(), key.groupId );
810+
GroupId groupId = key.groupId;
811811
HashSet attrNameSet = null;
812812
CacheElement ce = null;
813813

814814
if ( invocation )
815815
{
816816
// Invocation is NOT local
817-
ce = ( CacheElement ) systemGroupIdCache.localGet( groupId.key );
817+
ce = ( CacheElement ) systemGroupIdCache.localGet( groupId.toString() );
818818
}
819819
else
820820
{
821821
// Invocation is local
822-
ce = ( CacheElement ) systemGroupIdCache.get( groupId.key );
822+
ce = ( CacheElement ) systemGroupIdCache.get( groupId.toString() );
823823
}
824824

825825
// IF THE NAME SET IS FOUND
@@ -854,7 +854,7 @@ public void updateGroupAttrNameSet( GroupAttrName key,
854854

855855
CacheElement ceID
856856
= new CacheElement( this.getCacheName(),
857-
groupId.key,
857+
groupId,
858858
attrNameSet );
859859

860860
ceID.setElementAttributes( ce.attr );
@@ -888,11 +888,11 @@ else if ( remove )
888888
// unlike insertion, removal should go remote if locally invoked
889889
if ( invocation )
890890
{
891-
systemGroupIdCache.localRemove( groupId.key );
891+
systemGroupIdCache.localRemove( groupId.toString() );
892892
}
893893
else
894894
{
895-
systemGroupIdCache.remove( groupId.key );
895+
systemGroupIdCache.remove( groupId.toString() );
896896
}
897897
}
898898
}
@@ -936,24 +936,24 @@ protected boolean removeGI( GroupId groupId, boolean invocation, boolean skipLoc
936936

937937
if ( !skipLock )
938938
{
939-
writeLock( groupId.key );
939+
writeLock( groupId.toString() );
940940
}
941941
try
942942
{
943943
if ( invocation )
944944
{
945-
ok = systemGroupIdCache.localRemove( groupId.key );
945+
ok = systemGroupIdCache.localRemove( groupId.toString() );
946946
}
947947
else
948948
{
949-
ok = systemGroupIdCache.remove( groupId.key );
949+
ok = systemGroupIdCache.remove( groupId.toString() );
950950
}
951951
}
952952
finally
953953
{
954954
if ( !skipLock )
955955
{
956-
locker.done( groupId.key );
956+
locker.done( groupId.toString() );
957957
}
958958
}
959959
return ok;

src/java/org/apache/jcs/engine/control/group/GroupId.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,63 @@
77
* cache items in the same cache.
88
*
99
* @author asmuts
10+
* @author <a href="mailto:jmcnally@apache.org">John McNally</a>
1011
* @created January 15, 2002
1112
*/
1213
public class GroupId implements Serializable
1314
{
14-
1515
/** Description of the Field */
16-
public final String key;
17-
16+
public final String groupName;
17+
public final String cacheName;
18+
private String toString;
1819

1920
/**
2021
* Constructor for the GroupId object
2122
*
2223
* @param cacheName
23-
* @param key
24+
* @param groupName
2425
*/
25-
public GroupId( String cacheName, String key )
26+
public GroupId( String cacheName, String groupName )
2627
{
27-
this.key = cacheName + key;
28+
this.cacheName = cacheName;
29+
this.groupName = groupName;
2830

29-
if ( key == null )
31+
if ( cacheName == null )
32+
{
33+
throw new IllegalArgumentException("cacheName must not be null.");
34+
}
35+
if ( groupName == null )
3036
{
31-
throw new IllegalArgumentException( "key must not be null." );
37+
throw new IllegalArgumentException("groupName must not be null.");
3238
}
3339
}
3440

35-
3641
/** Description of the Method */
3742
public boolean equals( Object obj )
3843
{
39-
if ( obj == null || !( obj instanceof GroupId ) )
44+
if ( obj == null || !(obj instanceof GroupId) )
4045
{
4146
return false;
4247
}
43-
GroupId to = ( GroupId ) obj;
44-
return key.equals( to.key );
48+
GroupId g = (GroupId)obj;
49+
return cacheName.equals(g.cacheName) && groupName.equals(g.groupName);
4550
}
4651

4752

4853
/** Description of the Method */
4954
public int hashCode()
5055
{
51-
return key.hashCode();
56+
return cacheName.hashCode() + groupName.hashCode();
5257
}
5358

54-
5559
/** Description of the Method */
5660
public String toString()
5761
{
58-
return "[grouId=" + key + "]";
62+
if (toString == null)
63+
{
64+
toString = "[groupId=" + cacheName + ", " + groupName + ']';
65+
}
66+
67+
return toString;
5968
}
6069
}

0 commit comments

Comments
 (0)