/**
  * Renames an entry. Currently used for only user renaming.
  *
  * @param token the sso token
  * @param objectType the type of entry
  * @param entryDN the entry DN
  * @param newName the new name (i.e., if RDN is cn=John, the value passed should be "John"
  * @param deleteOldName if true the old name is deleted otherwise it is retained.
  * @return new <code>DN</code> of the renamed entry
  * @throws AMException if the operation was not successful
  */
 public String renameEntry(
     SSOToken token, int objectType, String entryDN, String newName, boolean deleteOldName)
     throws AMException {
   String newDN = super.renameEntry(token, objectType, entryDN, newName, deleteOldName);
   // Just rename the dn in the cache. Don't remove the entry. So when the
   // event notification happens, it won't find the entry as it is already
   // renamed. Chances are this cache rename operation may happen before
   // the notification thread trys clean up.
   // NOTE: We should have the code to remove the entry for rename
   // operation as the operation could have been performed by some other
   // process such as amadmin.
   String oldDN = MiscUtils.formatToRFC(entryDN);
   CacheBlock cb = (CacheBlock) sdkCache.remove(oldDN);
   newDN = MiscUtils.formatToRFC(newDN);
   sdkCache.put(newDN, cb);
   return newDN;
 }
 private synchronized void removeFromCache(String dn) {
   String key = MiscUtils.formatToRFC(dn);
   sdkCache.remove(key);
 }
 /**
  * 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 = MiscUtils.formatToRFC(dn);
   switch (eventType) {
     case AMEvent.OBJECT_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 AMEvent.OBJECT_REMOVED:
       cb = (CacheBlock) sdkCache.remove(dn);
       if (cb != null) {
         cb.clear(); // Clear anyway & help the GC process
       }
       if (cosType) {
         removeCachedAttributes(dn, 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 = (CacheBlock) sdkCache.remove(dn);
       if (cb != null) {
         cb.clear(); // Clear anyway & help the GC process
       }
       if (cosType) {
         removeCachedAttributes(dn, attrNames);
       }
       break;
     case AMEvent.OBJECT_CHANGED:
       cb = (CacheBlock) sdkCache.get(dn);
       if (cb != null) {
         cb.clear(); // Just clear the entry. Don't remove.
       }
       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);
   }
 }