Search in sources :

Example 11 with CacheBlock

use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.

the class CachedDirectoryServicesImpl 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) {
    CacheBlock cb;
    String origdn = dn;
    dn = LDAPUtils.formatToRFC(dn);
    switch(eventType) {
        case PersistentSearchChangeType.ADDED:
            cb = (CacheBlock) sdkCache.get(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(dn, attrNames);
            }
            break;
        case PersistentSearchChangeType.REMOVED:
            cb = (CacheBlock) sdkCache.remove(dn);
            if (cb != null) {
                // Clear anyway & help the GC process
                cb.clear();
            }
            if (cosType) {
                removeCachedAttributes(dn, attrNames);
            }
            break;
        case PersistentSearchChangeType.RENAMED:
            // Better to remove the renamed entry, or else it will be just
            // hanging in the cache, until LRU kicks in.
            cb = (CacheBlock) sdkCache.remove(dn);
            if (cb != null) {
                // Clear anyway & help the GC process
                cb.clear();
            }
            if (cosType) {
                removeCachedAttributes(dn, attrNames);
            }
            break;
        case PersistentSearchChangeType.MODIFIED:
            cb = (CacheBlock) sdkCache.get(dn);
            if (cb != null) {
                // Just clear the entry. Don't remove.
                cb.clear();
            }
            if (cosType) {
                removeCachedAttributes(dn, attrNames);
            } else if (aciChange) {
                // Clear all affected entries
                clearCachedEntries(dn);
            }
            break;
    }
    if (debug.messageEnabled()) {
        debug.message("CachedDirectoryServicesImpl.dirtyCache(): " + "Cache dirtied because of Event Notification. Parameters" + " - eventType: " + eventType + ", cosType: " + cosType + ", aciChange: " + aciChange + ", fullDN: " + origdn + "; rfcDN =" + dn);
    }
}
Also used : CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Example 12 with CacheBlock

use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.

the class CachedDirectoryServicesImpl method clearCachedEntries.

private void clearCachedEntries(String affectDNs) {
    Enumeration cacheKeys = sdkCache.keys();
    while (cacheKeys.hasMoreElements()) {
        String key = (String) cacheKeys.nextElement();
        int l1 = key.length();
        int l2 = affectDNs.length();
        if (key.regionMatches(true, (l1 - l2), affectDNs, 0, l2)) {
            // key ends with 'affectDN' string
            CacheBlock cb = (CacheBlock) sdkCache.get(key);
            if (cb != null) {
                cb.clear();
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Example 13 with CacheBlock

use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.

the class CachedDirectoryServicesImpl method dirtyCache.

private void dirtyCache(Set entries) {
    Iterator itr = entries.iterator();
    while (itr.hasNext()) {
        String entryDN = (String) itr.next();
        String key = LDAPUtils.formatToRFC(entryDN);
        CacheBlock cb = (CacheBlock) sdkCache.get(key);
        if (cb != null) {
            cb.clear();
        }
    }
}
Also used : Iterator(java.util.Iterator) CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Example 14 with CacheBlock

use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.

the class CachedDirectoryServicesImpl method doesEntryExists.

public boolean doesEntryExists(SSOToken token, String entryDN) {
    String dn = LDAPUtils.formatToRFC(entryDN);
    CacheBlock cb = (CacheBlock) sdkCache.get(dn);
    if (cb != null && !cb.hasExpiredAndUpdated()) {
        if (debug.messageEnabled()) {
            debug.message("CachedDirectoryServicesImpl.doesEntryExist(): " + "entryDN: " + entryDN + " found in cache & exists: " + cb.isExists());
        }
        return cb.isExists();
    } else {
        boolean isPresent = super.doesEntryExists(token, dn);
        if (debug.messageEnabled()) {
            debug.message("CachedDirectoryServicesImpl.doesEntryExist():" + " entryDN: " + entryDN + " got from DS & exists: " + isPresent);
        }
        // Intialize the CacheBock based on isPresent
        if (cb == null) {
            cb = new CacheBlock(entryDN, isPresent);
            sdkCache.put(dn, cb);
        } else {
            // Cache Block might have just expired, just reset the
            // isExists flag once again
            cb.setExists(isPresent);
        }
        return isPresent;
    }
}
Also used : CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Example 15 with CacheBlock

use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.

the class CachedDirectoryServicesImpl method getObjectType.

/**
     * Gets the type of the object given its DN.
     * 
     * @param token
     *            token a valid SSOToken
     * @param dn
     *            DN of the object whose type is to be known.
     * 
     * @throws AMException
     *             if the data store is unavailable or if the objecttype is
     *             unknown
     * @throws SSOException
     *             if ssoToken is invalid or expired.
     */
public int getObjectType(SSOToken token, String dn) throws AMException, SSOException {
    int objectType = AMObject.UNDETERMINED_OBJECT_TYPE;
    String entryDN = LDAPUtils.formatToRFC(dn);
    CacheBlock cb = (CacheBlock) sdkCache.get(entryDN);
    if (cb != null) {
        validateEntry(token, cb);
        objectType = cb.getObjectType();
        if (objectType != AMObject.UNDETERMINED_OBJECT_TYPE) {
            return objectType;
        }
    }
    // Use admintoken to get object type, so that it can be cached
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    // this DN
    if (cb == null) {
        objectType = super.getObjectType(adminToken, entryDN);
        cb = new CacheBlock(entryDN, true);
        sdkCache.put(entryDN, cb);
    } else {
        objectType = super.getObjectType(adminToken, entryDN, cb.getAttributes(CommonUtils.getPrincipalDN(adminToken), false));
    }
    cb.setObjectType(objectType);
    if (objectType == AMObject.ORGANIZATION || objectType == AMObject.ORGANIZATIONAL_UNIT) {
        cb.setOrganizationDN(entryDN);
    }
    return objectType;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Aggregations

CacheBlock (com.iplanet.am.sdk.common.CacheBlock)32 Enumeration (java.util.Enumeration)6 AMException (com.iplanet.am.sdk.AMException)5 AMHashMap (com.iplanet.am.sdk.AMHashMap)4 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 Set (java.util.Set)4 SSOToken (com.iplanet.sso.SSOToken)2 Map (java.util.Map)2 DN (org.forgerock.opendj.ldap.DN)2 AMObject (com.iplanet.am.sdk.AMObject)1