use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdCachedServicesImpl method dirtyCache.
/**
* This method will be called by <code>AMIdRepoListener</code>. This
* method will update the cache by removing all the entires which are
* affected as a result of an event notification caused because of
* changes/deletions/renaming of entries with and without aci's.
*
* <p>
* NOTE: The event could have been caused either by changes to an aci entry
* or a costemplate or a cosdefinition or changes to a normal entry
*
* @param dn
* name of entity being modified
* @param eventType
* type of modification
* @param cosType
* true if it is cos related. false otherwise
* @param aciChange
* true if it is aci related. false otherwise
* @param attrNames
* Set of attribute Names which should be removed from the
* CacheEntry in the case of COS change
*/
public void dirtyCache(String dn, int eventType, boolean cosType, boolean aciChange, Set attrNames) {
IdCacheBlock cb;
String originalDN = dn;
dn = DNUtils.normalizeDN(dn);
String cachedID = getCacheId(dn);
switch(eventType) {
case AMEvent.OBJECT_ADDED:
cb = getFromCache(dn);
if (cb != null) {
// Mark an invalid entry as valid now
cb.setExists(true);
}
if (cosType) {
// A cos type event remove all affected attributes
removeCachedAttributes(cachedID, attrNames);
}
break;
case AMEvent.OBJECT_REMOVED:
cb = (IdCacheBlock) idRepoCache.remove(cachedID);
if (cb != null) {
// Clear anyway & help the GC process
cb.clear();
}
if (cosType) {
removeCachedAttributes(cachedID, attrNames);
}
break;
case AMEvent.OBJECT_RENAMED:
// Better to remove the renamed entry, or else it will be just
// hanging in the cache, until LRU kicks in.
cb = (IdCacheBlock) idRepoCache.remove(cachedID);
if (cb != null) {
// Clear anyway & help the GC process
cb.clear();
}
if (cosType) {
removeCachedAttributes(cachedID, attrNames);
}
break;
case AMEvent.OBJECT_CHANGED:
cb = getFromCache(dn);
if (cb != null) {
// Just clear the entry. Don't remove.
cb.clear();
}
if (cosType) {
removeCachedAttributes(cachedID, attrNames);
} else if (aciChange) {
// Clear all affected entries
clearCachedEntries(cachedID);
}
break;
}
if (DEBUG.messageEnabled()) {
DEBUG.message("IdCachedServicesImpl.dirtyCache(): Cache " + "dirtied because of Event Notification. Parameters - " + "eventType: " + eventType + ", cosType: " + cosType + ", aciChange: " + aciChange + ", fullDN: " + originalDN + "; rfcDN =" + dn + "; cachedID=" + cachedID);
}
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdRemoteCachedServicesImpl method dirtyCache.
/**
* This method will be called by <code>AMIdRepoListener</code>. This
* method will update the cache by removing all the entires which are
* affected as a result of an event notification caused because of
* changes/deletions/renaming of entries with and without aci's.
*
* <p>
* NOTE: The event could have been caused either by changes to an aci entry
* or a costemplate or a cosdefinition or changes to a normal entry
*
* @param dn
* name of entity being modified
* @param eventType
* type of modification
* @param cosType
* true if it is cos related. false otherwise
* @param aciChange
* true if it is aci related. false otherwise
* @param attrNames
* Set of attribute Names which should be removed from the
* CacheEntry in the case of COS change
*/
public void dirtyCache(String dn, int eventType, boolean cosType, boolean aciChange, Set attrNames) {
IdCacheBlock cb;
String originalDN = dn;
dn = DNUtils.normalizeDN(dn);
String cachedID = getCacheId(dn);
switch(eventType) {
case IdRepoListener.OBJECT_ADDED:
cb = getFromCache(dn);
if (cb != null) {
// Mark an invalid entry as valid now
cb.setExists(true);
}
if (cosType) {
// A cos type event remove all affected attributes
removeCachedAttributes(cachedID, attrNames);
}
break;
case IdRepoListener.OBJECT_REMOVED:
cb = (IdCacheBlock) idRepoCache.remove(cachedID);
if (cb != null) {
// Clear anyway & help the GC process
cb.clear();
}
if (cosType) {
removeCachedAttributes(cachedID, attrNames);
}
break;
case IdRepoListener.OBJECT_RENAMED:
// Better to remove the renamed entry, or else it will be just
// hanging in the cache, until LRU kicks in.
cb = (IdCacheBlock) idRepoCache.remove(cachedID);
if (cb != null) {
// Clear anyway & help the GC process
cb.clear();
}
if (cosType) {
removeCachedAttributes(cachedID, attrNames);
}
break;
case IdRepoListener.OBJECT_CHANGED:
cb = getFromCache(dn);
if (cb != null) {
// Just clear the entry. Don't remove.
cb.clear();
}
if (cosType) {
removeCachedAttributes(cachedID, attrNames);
} else if (aciChange) {
// Clear all affected entries
clearCachedEntries(cachedID);
}
break;
}
if (DEBUG.messageEnabled()) {
DEBUG.message("IdRemoteCachedServicesImpl.dirtyCache(): Cache " + "dirtied because of Event Notification. Parameters - " + "eventType: " + eventType + ", cosType: " + cosType + ", aciChange: " + aciChange + ", fullDN: " + originalDN + "; rfcDN =" + dn + "; cachedID=" + cachedID);
}
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdRemoteCachedServicesImpl method dirtyCache.
private void dirtyCache(String dn) {
String key = DNUtils.normalizeDN(dn);
IdCacheBlock cb = getFromCache(key);
if (cb != null) {
cb.clear();
}
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdCachedServicesImpl method getAttributes.
public Map getAttributes(SSOToken token, IdType type, String name, String amOrgName, String amsdkDN) throws IdRepoException, SSOException {
cacheStats.incrementGetRequestCount(getSize());
if (MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incGetRqts(li);
}
// Get the identity dn
AMIdentity id = new AMIdentity(token, name, type, amOrgName, amsdkDN);
String dn = id.getUniversalId().toLowerCase();
// Get the principal dn
AMIdentity tokenId = IdUtils.getIdentity(token);
String principalDN = IdUtils.getUniversalId(tokenId);
// Get the cache entry
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
AMHashMap attributes;
if ((cb != null) && cb.hasCompleteSet(principalDN)) {
cacheStats.updateGetHitCount(getSize());
if (MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incCacheHits(li);
}
if (DEBUG.messageEnabled()) {
DEBUG.message("IdCachedServicesImpl." + "getAttributes(): DN: " + dn + " found all attributes in Cache.");
}
attributes = (AMHashMap) cb.getAttributes(principalDN, false);
} else {
// Get all the attributes from data store
if (DEBUG.messageEnabled()) {
DEBUG.message("IdCachedServicesImpl." + "getAttributes(): " + dn + " complete attribute" + " set NOT found in cache. Getting from DS.");
}
attributes = (AMHashMap) super.getAttributes(token, type, name, amOrgName, amsdkDN);
if (cb == null) {
cb = new IdCacheBlock(dn, true);
idRepoCache.put(dn, cb);
}
cb.putAttributes(principalDN, attributes, null, true, false);
if (DEBUG.messageEnabled()) {
DEBUG.message("IdCachedServicesImpl.getAttributes(): " + "attributes NOT found in cache. Fetched from DS.");
}
}
return attributes;
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdRemoteCachedServicesImpl method removeAttributes.
// @Override
public void removeAttributes(SSOToken token, IdType type, String name, Set attrNames, String orgName, String amsdkDN) throws IdRepoException, SSOException {
// Call parent to remove the attributes
super.removeAttributes(token, type, name, attrNames, orgName, amsdkDN);
// Update the cache
AMIdentity id = new AMIdentity(token, name, type, orgName, amsdkDN);
String dn = id.getUniversalId().toLowerCase();
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
if ((cb != null) && !cb.hasExpiredAndUpdated() && cb.isExists()) {
// Remove the attributes
cb.removeAttributes(attrNames);
}
}
Aggregations