com.atlassian.crowd.service.cache
Class CacheImpl

java.lang.Object
  extended by com.atlassian.crowd.service.cache.CacheImpl
All Implemented Interfaces:
BasicCache

public class CacheImpl
extends java.lang.Object
implements BasicCache


Constructor Summary
CacheImpl(net.sf.ehcache.CacheManager ehCacheManager)
           
CacheImpl(java.net.URL configLocation)
           
 
Method Summary
 void addGroupToUser(java.lang.String userName, java.lang.String groupName)
          Adds the group to the user/group membership in cache
 void addIsUserOrGroup(java.lang.String name, java.lang.Boolean isValidUserOrGroup)
          Updates the cache with information if the specified name is a valid user or group
 void addToAllGroupNamesCache(java.lang.String groupName)
          If we have a list of all groups, when we add one we should update the list.
 void addToAllUsers(java.lang.String userName)
          Adds userName to the list of all users in the system.
 void addUserToGroup(java.lang.String userName, java.lang.String groupName)
          Adds the user to the user/group membership in cache
 void cacheAllGroupNames(java.util.List groupNames)
          Adds, or if it already exists, replaces the list of all group names.
 void cacheAllMembers(java.lang.String groupName, java.util.List userNames)
          Cache a list of all users in this group.
 void cacheAllMemberships(java.lang.String userName, java.util.List groupNames)
          Cache a list of all groups this user belongs to.
 void cacheAllUserNames(java.util.List userNames)
          Adds a list of all users, or if one already exists, replaces it.
 void cacheAncestorsForGroups(java.util.Map<java.lang.String,java.util.Set<java.lang.String>> ancestorsByGroup)
          Cache a map of group name -> ancestor group names.
 void cacheGroup(SOAPGroup group)
          Adds a group, or if it exists, replaces the old SOAPGroup instance.
 void cacheUser(SOAPPrincipal user)
          Adds, or if they exist, replaces an existing user.
 void cacheUserWithAttributes(SOAPPrincipal user)
          Caches the specified user and it's properties
 boolean containsGroupRelationships()
           
 void flush()
          Clears the underlying cache.
 java.util.List getAllGroupNames()
          Returns a List of Strings containing all group names, or null if the list is not cached.
 java.util.List getAllMembers(java.lang.String groupName)
          Returns a list of users that belong to groupName belongs to, or null if there aren't any.
 java.util.List getAllMemberships(java.lang.String userName)
          Returns a list of groups that userName belongs to, or null if they don't belong to any.
 java.util.List getAllUserNames()
           
 java.util.Map<java.lang.String,java.util.Set<java.lang.String>> getAncestorsForGroups()
          Returns a map of group name -> ancestor group names, or null if the map is not cached.
 SOAPGroup getGroup(java.lang.String groupName)
          Returns the group, or null if it's not in the cache.
 java.lang.String getGroupName(java.lang.String groupname)
          Returns the groupname in correct case if it exists in the cache, null otherwise.
protected  java.lang.String getKey(java.lang.String name)
          Return a version of the name appropriate for use as a cache key.
protected  java.util.List<java.lang.String> getKeys(java.util.List<java.lang.String> names)
          Applies getKey over a collection.
 SOAPPrincipal getUser(java.lang.String userName)
          Returns the SOAPPrincipal representing userName, or null if it's not in the cache.
 java.lang.String getUserName(java.lang.String username)
          Returns the username in correct case if it exists in the cache, null otherwise.
 SOAPPrincipal getUserWithAttributes(java.lang.String userName)
          Returns the SOAPPrincipal with Attributes representing userName, or null if it's not in the cache.
 java.lang.Boolean isMember(java.lang.String userName, java.lang.String groupName)
          Maintains a list of true/false for "is this user a member of this group".
 java.lang.Boolean isMemberInGroupCache(java.lang.String userName, java.lang.String groupName)
          Checks the group->user cache to see if the user is a member.
protected  boolean isUserDirty(SOAPPrincipal latestSoapPrincipal, SOAPPrincipal cachedSoapPrincipal)
           
 java.lang.Boolean isUserOrGroup(java.lang.String name)
          Will return true if there is enough information in the cache to determine if the string represents a user or group
 void removeAllMembers(java.lang.String groupName)
          Removes the list of users in the group.
 void removeAllMemberships(java.lang.String userName)
          Called by CachingUserManager.removeUser(String) to ensure the users details are removed from any and all user->groups and (user+group)->[yes,no] caches.
 void removeAllMembershipsFromUserMembershipsCache(java.lang.String userName)
          Removes the list of groups the user belongs to.
 void removeCachedGroupMembership(java.lang.String userName, java.lang.String groupName)
          Removes all the membership details for this specific userName, groupName pair, when a group is being removed.
 void removeCachedGroupMemberships(java.lang.String groupName)
          Called by CachingGroupManager.removeGroup(String) to ensure the group details are removed from any and all user->groups and (user+group)->[yes,no] caches.
 void removeCachedUser(java.lang.String userName, java.lang.String groupName)
          Removes membership details for the specified user/group
 void removeFromAllGroupNamesCache(java.lang.String groupName)
          When we remove a group, if we have already cached the list of all available groups, we need to remove this group.
 void removeFromAllUsers(java.lang.String userName)
          Removes the user from the cache
 void removeGroup(java.lang.String groupName)
          Removes the group, if it exists
 void removeGroupFromUser(java.lang.String userName, java.lang.String groupName)
          Removes the group from the user/group membership in the cache
 void removeMembership(java.lang.String userName, java.lang.String groupName)
          Remove any stored [yes,no] membership relationship for a userName & groupName combination.
 boolean removeUser(java.lang.String userName)
          Removes the user from the cache.
 void removeUserFromGroup(java.lang.String userName, java.lang.String groupName)
          Removes the user from the user/group membership in the cache
 java.util.List setMembers(java.lang.String groupName, java.lang.String[] userNameArray)
          Caches the member list for a group called groupName.
 void setMembership(java.lang.String userName, java.lang.String groupName, java.lang.Boolean isMember)
          Adds or replaces a membership relationship between the user and the group.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheImpl

public CacheImpl(java.net.URL configLocation)

CacheImpl

public CacheImpl(net.sf.ehcache.CacheManager ehCacheManager)
Method Detail

getKey

protected java.lang.String getKey(java.lang.String name)
Return a version of the name appropriate for use as a cache key.

The default implementation toLowers the name to produce a case-insensitive cache.

Parameters:
name - key.
Returns:
standardised key.

getKeys

protected java.util.List<java.lang.String> getKeys(java.util.List<java.lang.String> names)
Applies getKey over a collection.

Parameters:
names - set of names.
Returns:
collection of keys.

flush

public void flush()
Description copied from interface: BasicCache
Clears the underlying cache. May clear more than just one cache - assume that all state in all caches is lost when you call this.

Specified by:
flush in interface BasicCache

cacheUser

public void cacheUser(SOAPPrincipal user)
Description copied from interface: BasicCache
Adds, or if they exist, replaces an existing user.

Specified by:
cacheUser in interface BasicCache
Parameters:
user - the user to add/replace

isUserDirty

protected boolean isUserDirty(SOAPPrincipal latestSoapPrincipal,
                              SOAPPrincipal cachedSoapPrincipal)

cacheUserWithAttributes

public void cacheUserWithAttributes(SOAPPrincipal user)
Description copied from interface: BasicCache
Caches the specified user and it's properties

Specified by:
cacheUserWithAttributes in interface BasicCache
Parameters:
user - SOAPPrincipal to cache

removeUser

public boolean removeUser(java.lang.String userName)
Description copied from interface: BasicCache
Removes the user from the cache.

Specified by:
removeUser in interface BasicCache
Parameters:
userName - the user to remove
Returns:
true if the user was cached, false otherwise.

getUser

public SOAPPrincipal getUser(java.lang.String userName)
Description copied from interface: BasicCache
Returns the SOAPPrincipal representing userName, or null if it's not in the cache.

Specified by:
getUser in interface BasicCache
Parameters:
userName - the user to retrieve
Returns:
SOAPPrincipal representing the user, or null if not in cache

getUserWithAttributes

public SOAPPrincipal getUserWithAttributes(java.lang.String userName)
Description copied from interface: BasicCache
Returns the SOAPPrincipal with Attributes representing userName, or null if it's not in the cache.

Specified by:
getUserWithAttributes in interface BasicCache
Parameters:
userName - the user to retrieve
Returns:
SOAPPrincipal with Attributes representing the user, or null i fnot in cache

getAllUserNames

public java.util.List getAllUserNames()
Specified by:
getAllUserNames in interface BasicCache
Returns:
a List with all user names, or null if none are cached.

cacheAllUserNames

public void cacheAllUserNames(java.util.List userNames)
Description copied from interface: BasicCache
Adds a list of all users, or if one already exists, replaces it.

Specified by:
cacheAllUserNames in interface BasicCache
Parameters:
userNames - the list of usernames to add

getGroup

public SOAPGroup getGroup(java.lang.String groupName)
Description copied from interface: BasicCache
Returns the group, or null if it's not in the cache.

Specified by:
getGroup in interface BasicCache
Parameters:
groupName - the group to retrieve
Returns:
the group or null if it is not in cache

cacheGroup

public void cacheGroup(SOAPGroup group)
Description copied from interface: BasicCache
Adds a group, or if it exists, replaces the old SOAPGroup instance.

Specified by:
cacheGroup in interface BasicCache
Parameters:
group - the group to add/replace in cache

removeGroup

public void removeGroup(java.lang.String groupName)
Description copied from interface: BasicCache
Removes the group, if it exists

Specified by:
removeGroup in interface BasicCache
Parameters:
groupName - the group to remove in cache

getAllGroupNames

public java.util.List getAllGroupNames()
Description copied from interface: BasicCache
Returns a List of Strings containing all group names, or null if the list is not cached.

Specified by:
getAllGroupNames in interface BasicCache
Returns:
a List of Strings containing all group names, or null if the list is not cached.

cacheAllGroupNames

public void cacheAllGroupNames(java.util.List groupNames)
Description copied from interface: BasicCache
Adds, or if it already exists, replaces the list of all group names.

Specified by:
cacheAllGroupNames in interface BasicCache
Parameters:
groupNames - list of group names to add/replace

cacheAncestorsForGroups

public void cacheAncestorsForGroups(java.util.Map<java.lang.String,java.util.Set<java.lang.String>> ancestorsByGroup)
Description copied from interface: BasicCache
Cache a map of group name -> ancestor group names.

Specified by:
cacheAncestorsForGroups in interface BasicCache
Parameters:
ancestorsByGroup - map containing ancestor group names by group name

getAncestorsForGroups

public java.util.Map<java.lang.String,java.util.Set<java.lang.String>> getAncestorsForGroups()
Description copied from interface: BasicCache
Returns a map of group name -> ancestor group names, or null if the map is not cached.

Specified by:
getAncestorsForGroups in interface BasicCache
Returns:
map containing ancestor group names by group name

containsGroupRelationships

public boolean containsGroupRelationships()
Specified by:
containsGroupRelationships in interface BasicCache
Returns:
true if the cache contains enough information to reliably compute parent group relationships. If not, returns false.

isMemberInGroupCache

public java.lang.Boolean isMemberInGroupCache(java.lang.String userName,
                                              java.lang.String groupName)
Description copied from interface: BasicCache
Checks the group->user cache to see if the user is a member.

Specified by:
isMemberInGroupCache in interface BasicCache
Parameters:
userName - the user to check
groupName - the group to check
Returns:
Boolean.TRUE if the user is a member. Boolean.FALSE if not. null if we don't have enough information to tell.

addGroupToUser

public void addGroupToUser(java.lang.String userName,
                           java.lang.String groupName)
Description copied from interface: BasicCache
Adds the group to the user/group membership in cache

Specified by:
addGroupToUser in interface BasicCache
Parameters:
userName - the user to update
groupName - the group to add

addUserToGroup

public void addUserToGroup(java.lang.String userName,
                           java.lang.String groupName)
Description copied from interface: BasicCache
Adds the user to the user/group membership in cache

Specified by:
addUserToGroup in interface BasicCache
Parameters:
userName - the user to add
groupName - the group to update

removeGroupFromUser

public void removeGroupFromUser(java.lang.String userName,
                                java.lang.String groupName)
Description copied from interface: BasicCache
Removes the group from the user/group membership in the cache

Specified by:
removeGroupFromUser in interface BasicCache
Parameters:
userName - the user to update
groupName - the group to remove

removeUserFromGroup

public void removeUserFromGroup(java.lang.String userName,
                                java.lang.String groupName)
Description copied from interface: BasicCache
Removes the user from the user/group membership in the cache

Specified by:
removeUserFromGroup in interface BasicCache
Parameters:
userName - the user to remove
groupName - the group to update

setMembers

public java.util.List setMembers(java.lang.String groupName,
                                 java.lang.String[] userNameArray)
Description copied from interface: BasicCache
Caches the member list for a group called groupName. Since group member information arrives when the group is fetched from the Crowd server, this is also called from CachingGroupManager.getGroup(String).

Specified by:
setMembers in interface BasicCache
Parameters:
groupName - the group
userNameArray - the list of user names
Returns:
A List of all members of the group.

removeCachedGroupMembership

public void removeCachedGroupMembership(java.lang.String userName,
                                        java.lang.String groupName)
Description copied from interface: BasicCache
Removes all the membership details for this specific userName, groupName pair, when a group is being removed.

Specified by:
removeCachedGroupMembership in interface BasicCache
Parameters:
userName - the user associated with the membership
groupName - the group associate with the membership

removeCachedGroupMemberships

public void removeCachedGroupMemberships(java.lang.String groupName)
Description copied from interface: BasicCache
Called by CachingGroupManager.removeGroup(String) to ensure the group details are removed from any and all user->groups and (user+group)->[yes,no] caches.

Specified by:
removeCachedGroupMemberships in interface BasicCache
Parameters:
groupName - the group to clean up

removeFromAllGroupNamesCache

public void removeFromAllGroupNamesCache(java.lang.String groupName)
Description copied from interface: BasicCache
When we remove a group, if we have already cached the list of all available groups, we need to remove this group.

Specified by:
removeFromAllGroupNamesCache in interface BasicCache
Parameters:
groupName - the group to remove form cache

addToAllGroupNamesCache

public void addToAllGroupNamesCache(java.lang.String groupName)
Description copied from interface: BasicCache
If we have a list of all groups, when we add one we should update the list.

Specified by:
addToAllGroupNamesCache in interface BasicCache
Parameters:
groupName - MUST be in the case returned by the underlying system (ie. not forced to lower-case).

removeCachedUser

public void removeCachedUser(java.lang.String userName,
                             java.lang.String groupName)
Description copied from interface: BasicCache
Removes membership details for the specified user/group

Specified by:
removeCachedUser in interface BasicCache
Parameters:
userName - the user to update
groupName - the group to update

removeAllMemberships

public void removeAllMemberships(java.lang.String userName)
Description copied from interface: BasicCache
Called by CachingUserManager.removeUser(String) to ensure the users details are removed from any and all user->groups and (user+group)->[yes,no] caches.

Specified by:
removeAllMemberships in interface BasicCache
Parameters:
userName - the user to cleanup

setMembership

public void setMembership(java.lang.String userName,
                          java.lang.String groupName,
                          java.lang.Boolean isMember)
Description copied from interface: BasicCache
Adds or replaces a membership relationship between the user and the group. Updates the list of memberships returned by getAllMemberships() to keep them in sync.

Specified by:
setMembership in interface BasicCache
Parameters:
userName - the username associated to the membership to cache
groupName - the group name associated to the membership to cache
isMember - true if the user is a member, false if not.

removeMembership

public void removeMembership(java.lang.String userName,
                             java.lang.String groupName)
Description copied from interface: BasicCache
Remove any stored [yes,no] membership relationship for a userName & groupName combination.

Specified by:
removeMembership in interface BasicCache
Parameters:
userName - the username associated to the membership to cache
groupName - the group name associated to the membership to cache

isMember

public java.lang.Boolean isMember(java.lang.String userName,
                                  java.lang.String groupName)
Description copied from interface: BasicCache
Maintains a list of true/false for "is this user a member of this group". Returns null if no information is cached.

Specified by:
isMember in interface BasicCache
Parameters:
userName - the username associated to the membership to update
groupName - the group name associated to the membership to update
Returns:
true if the user is a member of the group, false if not. If there is no information in cache, returns null

getAllMemberships

public java.util.List getAllMemberships(java.lang.String userName)
Description copied from interface: BasicCache
Returns a list of groups that userName belongs to, or null if they don't belong to any.

Specified by:
getAllMemberships in interface BasicCache
Parameters:
userName - the user
Returns:
list of all memberships in lower-case.

cacheAllMemberships

public void cacheAllMemberships(java.lang.String userName,
                                java.util.List groupNames)
Description copied from interface: BasicCache
Cache a list of all groups this user belongs to.

Specified by:
cacheAllMemberships in interface BasicCache
Parameters:
userName - the username associated to the membership to cache
groupNames - list of group names associated to the membership to cache

removeAllMembershipsFromUserMembershipsCache

public void removeAllMembershipsFromUserMembershipsCache(java.lang.String userName)
Description copied from interface: BasicCache
Removes the list of groups the user belongs to. Used when the user is being deleted.

Specified by:
removeAllMembershipsFromUserMembershipsCache in interface BasicCache
Parameters:
userName - the username for which the memberships will be removed

getAllMembers

public java.util.List getAllMembers(java.lang.String groupName)
Description copied from interface: BasicCache
Returns a list of users that belong to groupName belongs to, or null if there aren't any.

Specified by:
getAllMembers in interface BasicCache
Parameters:
groupName - the group
Returns:
list of all members in lower-case.

cacheAllMembers

public void cacheAllMembers(java.lang.String groupName,
                            java.util.List userNames)
Description copied from interface: BasicCache
Cache a list of all users in this group.

Specified by:
cacheAllMembers in interface BasicCache
Parameters:
groupName - the group name to cache
userNames - the list of usersnames to cache

removeAllMembers

public void removeAllMembers(java.lang.String groupName)
Description copied from interface: BasicCache
Removes the list of users in the group. Used when the group is being deleted.

Specified by:
removeAllMembers in interface BasicCache
Parameters:
groupName - the group name for which the memberships will be removed

isUserOrGroup

public java.lang.Boolean isUserOrGroup(java.lang.String name)
Description copied from interface: BasicCache
Will return true if there is enough information in the cache to determine if the string represents a user or group

Specified by:
isUserOrGroup in interface BasicCache
Parameters:
name - the name to check
Returns:
if there is enough information in the cache true iff the string represents a user or group. null if there is no information in the cache

addIsUserOrGroup

public void addIsUserOrGroup(java.lang.String name,
                             java.lang.Boolean isValidUserOrGroup)
Description copied from interface: BasicCache
Updates the cache with information if the specified name is a valid user or group

Specified by:
addIsUserOrGroup in interface BasicCache
Parameters:
name - the name to add to cache
isValidUserOrGroup - boolean to signify if the specified name is a valid user or group

addToAllUsers

public void addToAllUsers(java.lang.String userName)
Description copied from interface: BasicCache
Adds userName to the list of all users in the system.

Specified by:
addToAllUsers in interface BasicCache
Parameters:
userName - MUST be in the case returned by the underlying system (ie. not forced to lower-case).

removeFromAllUsers

public void removeFromAllUsers(java.lang.String userName)
Description copied from interface: BasicCache
Removes the user from the cache

Specified by:
removeFromAllUsers in interface BasicCache
Parameters:
userName - can be in a case different to that stored in the underlying system.

getUserName

public java.lang.String getUserName(java.lang.String username)
Description copied from interface: BasicCache
Returns the username in correct case if it exists in the cache, null otherwise.

Specified by:
getUserName in interface BasicCache
Parameters:
username - the username
Returns:
the username in correct case, null if it doesn't exist in cache

getGroupName

public java.lang.String getGroupName(java.lang.String groupname)
Description copied from interface: BasicCache
Returns the groupname in correct case if it exists in the cache, null otherwise.

Specified by:
getGroupName in interface BasicCache
Parameters:
groupname - the group
Returns:
the group name in correct case, null if it doesn't exist in cache


Copyright © 2011 Atlassian. All Rights Reserved.