Search in sources :

Example 26 with CacheBlock

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

the class CachedRemoteServicesImpl 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 (getDebug().messageEnabled()) {
        getDebug().message("CachedRemoteServicesImpl.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 27 with CacheBlock

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

the class CachedRemoteServicesImpl method validateEntry.

/**
     * Method to be called to validate the entry before any of the get/put/
     * remove methods are called.
     * 
     * @throws AMException
     *             if the entry does not exist in the DS
     */
private void validateEntry(SSOToken token, CacheBlock cb) throws AMException {
    if (!cb.hasExpiredAndUpdated() && !cb.isExists()) {
        // Entry does not exist in DS, invalid entry
        String[] params = { cb.getEntryDN() };
        boolean isPresent = super.doesEntryExists(token, params[0]);
        if (getDebug().messageEnabled()) {
            getDebug().message("CachedRemoteServicesImpl.validateEntry():" + " DN" + params[0] + " got from DS & exists: " + isPresent);
        }
        if (isPresent) {
            // Intialize the CacheBlock based on isPresent
            // else throw '461' exception/error message.
            // This is for certain containers created dynamically.
            // eg. ou=agents,ou=container,ou=agents.
            String dn = LDAPUtils.formatToRFC(params[0]);
            cb = new CacheBlock(params[0], isPresent);
            sdkCache.put(dn, cb);
        } else {
            String locale = MiscUtils.getUserLocale(token);
            throw new AMException(AMSDKBundle.getString("461", params, locale), "461", params);
        }
    }
}
Also used : AMException(com.iplanet.am.sdk.AMException) CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Example 28 with CacheBlock

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

the class CachedRemoteServicesImpl method toString.

/**
     * Prints the contents of the cache. For getDebug() purpose only
     */
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("\n<<<<<<< BEGIN SDK CACHE CONTENTS >>>>>>>>");
    if (!sdkCache.isEmpty()) {
        // Should never be null
        Enumeration cacheKeys = sdkCache.keys();
        while (cacheKeys.hasMoreElements()) {
            String key = (String) cacheKeys.nextElement();
            CacheBlock cb = (CacheBlock) sdkCache.get(key);
            sb.append("\nSDK Cache Block: ").append(key);
            sb.append(cb.toString());
        }
    } else {
        sb.append("<empty>");
    }
    sb.append("\n<<<<<<< END SDK CACHE CONTENTS >>>>>>>>");
    return sb.toString();
}
Also used : Enumeration(java.util.Enumeration) CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Example 29 with CacheBlock

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

the class CachedRemoteServicesImpl method dirtyCache.

private void dirtyCache(String dn) {
    String key = LDAPUtils.formatToRFC(dn);
    CacheBlock cb = (CacheBlock) sdkCache.get(key);
    if (cb != null) {
        cb.clear();
    }
}
Also used : CacheBlock(com.iplanet.am.sdk.common.CacheBlock)

Example 30 with CacheBlock

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

the class CachedRemoteServicesImpl method createAMTemplate.

/**
     * Create an AMTemplate (COSTemplate)
     * 
     * @param token
     *            token
     * @param entryDN
     *            DN of the profile whose template is to be set
     * @param objectType
     *            the object type
     * @param serviceName
     *            Service Name
     * @param attributes
     *            attributes to be set
     * @param priority
     *            template priority
     * @return String DN of the newly created template
     */
public String createAMTemplate(SSOToken token, String entryDN, int objectType, String serviceName, Map attributes, int priority) throws AMException {
    String templateDN = super.createAMTemplate(token, entryDN, objectType, serviceName, attributes, priority);
    // Mark the entry as exists in cache
    String dn = LDAPUtils.formatToRFC(templateDN);
    CacheBlock cb = (CacheBlock) sdkCache.get(dn);
    if (cb != null) {
        cb.setExists(true);
    }
    return templateDN;
}
Also used : 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