Skip to content

Commit

Permalink
KNL-1502 Cache raw type, memoryService.newCache() (sakaiproject#4072)
Browse files Browse the repository at this point in the history
Add generics to cache, remove memoryService.newCache()
  • Loading branch information
axxter99 authored and buckett committed Mar 13, 2017
1 parent 03d2d13 commit 8aa3d8f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public abstract class DbAuthzGroupService extends BaseAuthzGroupService implemen
/** Our log (commons). */
private static Logger M_log = LoggerFactory.getLogger(DbAuthzGroupService.class);
/** All the event functions we know exist on the db. */
protected Collection m_functionCache = new HashSet();
protected Collection<String> m_functionCache = new HashSet<>();
/** All the event role names we know exist on the db. */
protected Collection m_roleNameCache = new HashSet();
/** Table name for realms. */
Expand Down Expand Up @@ -236,12 +236,12 @@ public void init()
// pre-cache role and function names
cacheRoleNames();
cacheFunctionNames();
m_realmRoleGRCache = m_memoryService.newCache("org.sakaiproject.authz.impl.DbAuthzGroupService.realmRoleGroupCache");
m_realmRoleGRCache = m_memoryService.getCache("org.sakaiproject.authz.impl.DbAuthzGroupService.realmRoleGroupCache");
M_log.info("init(): table: " + m_realmTableName + " external locks: " + m_useExternalLocks);

authzUserGroupIdsCache = m_memoryService.newCache("org.sakaiproject.authz.impl.DbAuthzGroupService.authzUserGroupIdsCache");
authzUserGroupIdsCache = m_memoryService.getCache("org.sakaiproject.authz.impl.DbAuthzGroupService.authzUserGroupIdsCache");

maintainRolesCache = m_memoryService.newCache("org.sakaiproject.authz.impl.DbAuthzGroupService.maintainRolesCache");
maintainRolesCache = m_memoryService.getCache("org.sakaiproject.authz.impl.DbAuthzGroupService.maintainRolesCache");
//get the set of maintain roles and cache them on startup
getMaintainRoles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public abstract class SakaiSecurity implements SecurityService, Observer
private static Logger M_log = LoggerFactory.getLogger(SakaiSecurity.class);

/** A cache of calls to the service and the results. */
protected Cache m_callCache = null;
protected Cache<String, Boolean> m_callCache = null;

/** ThreadLocalManager key for our SecurityAdvisor Stack. */
protected final static String ADVISOR_STACK = "SakaiSecurity.advisor.stack";
Expand Down Expand Up @@ -173,12 +173,12 @@ public void init()
* Cache for holding the super user check cached results
* Only used in the new caching system
*/
Cache m_superCache;
Cache<String, Boolean> m_superCache;
/**
* Cache for holding the content authz check cached results
* Only used in the new caching system
*/
Cache m_contentCache;
Cache<String, Boolean> m_contentCache;

/**
* KNL-1230
Expand All @@ -191,12 +191,12 @@ Boolean getFromCache(String key, boolean isSuper) {
Boolean result = null;
if (m_callCache != null) {
if (isSuper) {
result = (Boolean) m_superCache.get(key);
result = m_superCache.get(key);
} else {
if (key.contains("@/content")) {
result = (Boolean) m_contentCache.get(key);
result = m_contentCache.get(key);
} else {
result = (Boolean) m_callCache.get(key);
result = m_callCache.get(key);
}
}
// see note below about forced cache expiration
Expand Down Expand Up @@ -526,7 +526,7 @@ String makeCacheKey(String userId, String role, String function, String referenc
void logCacheState(String operator) {
if (cacheDebug) {
String name = m_callCache.getName();
net.sf.ehcache.Ehcache ehcache = (Ehcache) m_callCache.unwrap(Ehcache.class); // DEBUGGING ONLY
net.sf.ehcache.Ehcache ehcache = m_callCache.unwrap(Ehcache.class); // DEBUGGING ONLY
StringBuilder entriesSB = new StringBuilder();
List keys = ehcache.getKeysWithExpiryCheck(); // only current keys
entriesSB.append(" * keys(").append(keys.size()).append("):").append(new ArrayList<Object>(keys)).append("\n");
Expand Down Expand Up @@ -863,7 +863,7 @@ protected SecurityAdvisor.SecurityAdvice adviseIsAllowed(String userId, String f
// a Stack grows to the right - process from top to bottom
for (int i = advisors.size() - 1; i >= 0; i--)
{
SecurityAdvisor advisor = (SecurityAdvisor) advisors.elementAt(i);
SecurityAdvisor advisor = advisors.elementAt(i);

SecurityAdvisor.SecurityAdvice advice = advisor.isAllowed(userId, function, reference);
if (advice != SecurityAdvisor.SecurityAdvice.PASS)
Expand Down Expand Up @@ -898,14 +898,14 @@ public SecurityAdvisor popAdvisor(SecurityAdvisor advisor)
{
if (advisor == null)
{
rv = (SecurityAdvisor) advisors.pop();
rv = advisors.pop();
}
else
{
SecurityAdvisor sa = advisors.firstElement();
if (advisor.equals(sa))
{
rv = (SecurityAdvisor) advisors.pop();
rv = advisors.pop();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ActivityServiceImpl implements ActivityService, Observer {

private static Logger log = LoggerFactory.getLogger(ActivityServiceImpl.class);

private Cache userActivityCache = null;
private Cache<String, Long> userActivityCache = null;
private final String USER_ACTIVITY_CACHE_NAME = "org.sakaiproject.event.api.ActivityService.userActivityCache";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class BasicTimeService implements TimeService
private Hashtable<String, LocalTzFormat> M_localeTzMap = new Hashtable<String, LocalTzFormat>();

// Cache of userIds to Timezone/Locales
private Cache M_userTzCache;
private Cache<String, String[]> M_userTzCache;

// Default Timezone/Locale
protected String[] M_tz_locale_default = new String[] { TimeZone.getDefault().getID(), Locale.getDefault().toString() };
Expand Down Expand Up @@ -149,7 +149,7 @@ public void init()


//register the Cache
M_userTzCache = memoryService.newCache("org.sakaiproject.time.impl.BasicTimeService.userTimezoneCache");
M_userTzCache = memoryService.getCache("org.sakaiproject.time.impl.BasicTimeService.userTimezoneCache");
}

/**
Expand All @@ -169,7 +169,7 @@ protected String[] getUserTimezoneLocale()
String userId = sessionManager.getCurrentSessionUserId();
if (userId == null) return M_tz_locale_default;

String[] timeZoneLocale = (String[]) M_userTzCache.get(userId);
String[] timeZoneLocale = M_userTzCache.get(userId);
if (timeZoneLocale != null) return timeZoneLocale;

// Otherwise, get the user's preferred time zone
Expand All @@ -195,7 +195,7 @@ protected LocalTzFormat getLocalTzFormat(String[] timeZoneLocale)
//we need to convert the String[] to a string key
String tzLocaleString = stringAraytoKeyString(timeZoneLocale);

LocalTzFormat tzFormat = (LocalTzFormat) M_localeTzMap.get(tzLocaleString);
LocalTzFormat tzFormat = M_localeTzMap.get(tzLocaleString);
if (M_log.isDebugEnabled())
{
M_log.debug("M_localeTzMap contains: " + M_localeTzMap.size() + " members");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class AuthenticationCache {
private static final Logger log = LoggerFactory.getLogger(AuthenticationCache.class);

private MemoryService memoryService;
private Cache authCache = null;
private Cache<String, AuthenticationRecord> authCache = null;
/**
* List of algorithms to attempt to use, best ones should come first.
*/
Expand All @@ -76,15 +76,15 @@ public void destroy() {
/**
* The central cache object, should be injected
*/
public void setAuthCache(Cache authCache) {
public void setAuthCache(Cache<String, AuthenticationRecord> authCache) {
this.authCache = authCache;
if (log.isDebugEnabled() && (authCache != null)) log.debug("authCache ");
}

public Authentication getAuthentication(String authenticationId, String password)
throws AuthenticationException {
Authentication auth = null;
AuthenticationRecord record = (AuthenticationRecord) authCache.get(authenticationId);
AuthenticationRecord record = authCache.get(authenticationId);
if (record != null) {
byte[] salt = new byte[saltLength];
System.arraycopy(record.encodedPassword, 0, salt, 0, salt.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setMemoryService(MemoryService memoryService) {
this.memoryService = memoryService;
}

public void setUserCache(Cache userCache) {
public void setUserCache(Cache userCache) {
this.userCache = userCache;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public abstract class BasePreferencesService implements PreferencesService, Sing
/** The initial portion of a relative access point URL. */
protected String m_relativeAccessPoint = null;
/** the cache for Preference objects **/
private Cache m_cache;
private Cache<String, BasePreferences> m_cache;
/**********************************************************************************************************************************************************************************************************************************************************
* Abstractions, etc.
*********************************************************************************************************************************************************************************************************************************************************/
Expand Down Expand Up @@ -228,7 +228,7 @@ public void init()


//register a cache
m_cache = memoryService().newCache(BasePreferencesService.class.getName() +".preferences");
m_cache = memoryService().getCache(BasePreferencesService.class.getName() +".preferences");

M_log.info("init()");
}
Expand Down Expand Up @@ -426,7 +426,7 @@ protected BasePreferences findPreferences(String id)
}

// Try the cache
BasePreferences prefs = (BasePreferences) m_cache.get(id);
BasePreferences prefs = m_cache.get(id);

// Failing that, try the storage
if (prefs == null) {
Expand Down Expand Up @@ -580,12 +580,12 @@ public Entity getEntity(Reference ref)
/**
* @inheritDoc
*/
public Collection getEntityAuthzGroups(Reference ref, String userId)
public Collection<String> getEntityAuthzGroups(Reference ref, String userId)
{
// double check that it's mine
if (!APPLICATION_ID.equals(ref.getType())) return null;

Collection rv = new Vector();
Collection<String> rv = new Vector<String>();

// for preferences access: no additional role realms
try
Expand Down Expand Up @@ -783,7 +783,7 @@ public class BasePreferences implements PreferencesEdit, SessionBindingListener
protected ResourcePropertiesEdit m_properties = null;

/** The sets of keyed ResourceProperties. */
protected Map m_props = null;
protected Map<String, ResourcePropertiesEdit> m_props = null;
/** The event code for this edit. */
protected String m_event = null;
/** Active flag. */
Expand All @@ -803,7 +803,7 @@ public BasePreferences(String id)
ResourcePropertiesEdit props = new BaseResourcePropertiesEdit();
m_properties = props;

m_props = new Hashtable();
m_props = new Hashtable<>();

// if the id is not null (a new user, rather than a reconstruction)
// and not the anon (id == "") user,
Expand Down Expand Up @@ -833,7 +833,7 @@ public BasePreferences(Element el)
// setup for properties
m_properties = new BaseResourcePropertiesEdit();

m_props = new Hashtable();
m_props = new Hashtable<>();

m_id = el.getAttribute("id");

Expand Down Expand Up @@ -938,14 +938,14 @@ protected void setAll(Preferences prefs)
m_properties.addAll(prefs.getProperties());

// %%% is this deep enough? -ggolden
m_props = new Hashtable();
m_props = new Hashtable<>();
m_props.putAll(((BasePreferences) prefs).m_props);
}

/**
* @inheritDoc
*/
public Element toXml(Document doc, Stack stack)
public Element toXml(Document doc, Stack<Element> stack)
{
Element prefs = doc.createElement("preferences");

Expand All @@ -955,7 +955,7 @@ public Element toXml(Document doc, Stack stack)
}
else
{
((Element) stack.peek()).appendChild(prefs);
stack.peek().appendChild(prefs);
}

stack.push(prefs);
Expand Down Expand Up @@ -1041,7 +1041,7 @@ public ResourceProperties getProperties()
*/
public ResourceProperties getProperties(String key)
{
ResourceProperties rv = (ResourceProperties) m_props.get(key);
ResourceProperties rv = m_props.get(key);
if (rv == null)
{
// new, throwaway empty one
Expand All @@ -1054,7 +1054,7 @@ public ResourceProperties getProperties(String key)
/**
* @inheritDoc
*/
public Collection getKeys()
public Collection<String> getKeys()
{
return m_props.keySet();
}
Expand Down Expand Up @@ -1103,7 +1103,7 @@ public ResourcePropertiesEdit getPropertiesEdit(String key)
{
synchronized (m_props)
{
ResourcePropertiesEdit rv = (ResourcePropertiesEdit) m_props.get(key);
ResourcePropertiesEdit rv = m_props.get(key);
if (rv == null)
{
// new one saved in the map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public abstract class BaseUserDirectoryService implements UserDirectoryService,
protected final String M_curUserKey = getClass().getName() + ".currentUser";

/** A cache of users */
protected Cache m_callCache = null;
protected Cache<String, UserEdit> m_callCache = null;

/** Optional service to provide site-specific aliases for a user's display ID and display name. */
protected ContextualUserDisplayService m_contextualUserDisplayService = null;
Expand Down Expand Up @@ -144,7 +144,7 @@ public PasswordPolicyProvider getPasswordPolicy() {
}
// Try getting the default impl via ComponentManager
if ( m_passwordPolicyProvider == null ) {
m_passwordPolicyProvider = (PasswordPolicyProvider) ComponentManager.get(PasswordPolicyProvider.class);
m_passwordPolicyProvider = ComponentManager.get(PasswordPolicyProvider.class);
}
// If all else failed, manually instantiate default implementation
if ( m_passwordPolicyProvider == null ) {
Expand Down Expand Up @@ -235,7 +235,7 @@ protected boolean unlockCheck(List<String> locks, String resource)

while(locksIterator.hasNext()) {

if(securityService().unlock((String) locksIterator.next(), resource))
if(securityService().unlock(locksIterator.next(), resource))
return true;

}
Expand Down Expand Up @@ -331,7 +331,7 @@ protected List<String> unlock(List<String> locks, String resource) throws UserPe
StringBuilder locksFailedSb = new StringBuilder();
while (locksIterator.hasNext()) {

String lock = (String) locksIterator.next();
String lock = locksIterator.next();

if (unlockCheck(lock, resource))
{
Expand Down Expand Up @@ -576,7 +576,7 @@ public void init()
// Check for optional contextual user display service.
if (m_contextualUserDisplayService == null)
{
m_contextualUserDisplayService = (ContextualUserDisplayService) ComponentManager.get(ContextualUserDisplayService.class);
m_contextualUserDisplayService = ComponentManager.get(ContextualUserDisplayService.class);
}

// Fallback to the default password service.
Expand Down Expand Up @@ -852,7 +852,7 @@ public List getUsers(Collection<String> ids)
Set<String> searchIds = new HashSet<String>();
for (Iterator<String> idIter = ids.iterator(); idIter.hasNext(); )
{
String id = (String)idIter.next();
String id = idIter.next();
id = cleanEid(id);
if (id != null) searchIds.add(id);
}
Expand Down Expand Up @@ -1895,12 +1895,12 @@ public Entity getEntity(Reference ref)
/**
* @inheritDoc
*/
public Collection getEntityAuthzGroups(Reference ref, String userId)
public Collection<String> getEntityAuthzGroups(Reference ref, String userId)
{
// double check that it's mine
if (!APPLICATION_ID.equals(ref.getType())) return null;

Collection rv = new Vector();
Collection<String> rv = new Vector<String>();

// for user access: user and template realms
try
Expand Down Expand Up @@ -2282,7 +2282,7 @@ protected void setAll(User user)
/**
* @inheritDoc
*/
public Element toXml(Document doc, Stack stack)
public Element toXml(Document doc, Stack<Element> stack)
{
Element user = doc.createElement("user");

Expand All @@ -2292,7 +2292,7 @@ public Element toXml(Document doc, Stack stack)
}
else
{
((Element) stack.peek()).appendChild(user);
stack.peek().appendChild(user);
}

stack.push(user);
Expand Down

0 comments on commit 8aa3d8f

Please sign in to comment.