Search in sources :

Example 1 with ModificationEvent

use of org.forgerock.openam.entitlement.indextree.events.ModificationEvent in project OpenAM by OpenRock.

the class IndexTreeServiceImpl method update.

/**
     * {@inheritDoc}
     */
public void update(IndexChangeEvent event) {
    EventType type = event.getType();
    if (ModificationEventType.contains(type)) {
        // Modification event received, update the appropriate cached tree.
        ModificationEventType modificationType = (ModificationEventType) type;
        ModificationEvent modification = (ModificationEvent) event;
        String realm = modification.getRealm();
        IndexRuleTree tree = indexTreeCache.get(realm);
        if (tree != null) {
            String pathIndex = modification.getPathIndex();
            switch(modificationType) {
                case ADD:
                    tree.addIndexRule(pathIndex);
                    break;
                case DELETE:
                    tree.removeIndexRule(pathIndex);
                    break;
            }
            if (DEBUG.messageEnabled()) {
                DEBUG.message(String.format("Policy path index '%s' updated for realm '%s'.", pathIndex, realm));
            }
        }
    } else if (type == ErrorEventType.DATA_LOSS) {
        // Error event received, destroy the cache as policy updates may well have been lost, resulting in cached
        // trees becoming inconsistent. This will force all trees to be reloaded with clean data.
        indexTreeCache.clear();
        if (DEBUG.messageEnabled()) {
            DEBUG.message("Potential policy path index loss, cached index trees cleared.");
        }
    }
}
Also used : EventType(org.forgerock.openam.entitlement.indextree.events.EventType) ModificationEventType(org.forgerock.openam.entitlement.indextree.events.ModificationEventType) ErrorEventType(org.forgerock.openam.entitlement.indextree.events.ErrorEventType) ModificationEventType(org.forgerock.openam.entitlement.indextree.events.ModificationEventType) ModificationEvent(org.forgerock.openam.entitlement.indextree.events.ModificationEvent) IndexRuleTree(org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree)

Aggregations

ErrorEventType (org.forgerock.openam.entitlement.indextree.events.ErrorEventType)1 EventType (org.forgerock.openam.entitlement.indextree.events.EventType)1 ModificationEvent (org.forgerock.openam.entitlement.indextree.events.ModificationEvent)1 ModificationEventType (org.forgerock.openam.entitlement.indextree.events.ModificationEventType)1 IndexRuleTree (org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree)1