Example usage for java.util.concurrent ConcurrentMap remove

List of usage examples for java.util.concurrent ConcurrentMap remove

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentMap remove.

Prototype

V remove(Object key);

Source Link

Document

Removes the mapping for a key from this map if it is present (optional operation).

Usage

From source file:org.sakaiproject.memory.impl.GenericMultiRefCacheImpl.java

private void cleanEntityReferences(Object key, Object value) {
    if (M_log.isDebugEnabled())
        M_log.debug("cleanEntityReferences(Object " + key + ", Object " + value + ")");
    if (value == null)
        return;/*  w ww.j a  v  a2s .c o m*/

    final MultiRefCacheEntry cachedEntry = (MultiRefCacheEntry) value;

    // remove this key from any of the entity references in m_refs that are dependent on this entry
    for (Iterator iRefs = cachedEntry.getRefs().iterator(); iRefs.hasNext();) {
        String ref = (String) iRefs.next();
        ConcurrentMap<Object, Object> keys = m_refsStore.get(ref);
        if (keys != null && keys.remove(key) != null) {
            // remove the ref entry if it no longer has any cached keys in
            // its collection
            // TODO This isn't thread safe.
            if (keys.isEmpty()) {
                m_refsStore.remove(ref, keys);
            }
        }
    }
    if (mrcDebug)
        logCacheState("cleanEntityReferences(" + key + ")");
}

From source file:com.networknt.light.rule.rule.AbstractRuleRule.java

protected void delRule(Map<String, Object> data) throws Exception {
    String ruleClass = (String) data.get("ruleClass");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {/*  w ww .ja  v a 2s  . co m*/
        graph.begin();
        Vertex rule = graph.getVertexByKey("Rule.ruleClass", ruleClass);
        if (rule != null) {
            graph.removeVertex(rule);
        }
        graph.commit();
        // check if the rule is in compile cache, remove it.
        Map<String, Object> compileMap = ServiceLocator.getInstance().getMemoryImage("compileMap");
        ConcurrentMap<String, String> cache = (ConcurrentMap<String, String>) compileMap.get("cache");
        if (cache != null) {
            cache.remove(ruleClass);
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}

From source file:com.networknt.light.rule.menu.AbstractMenuRule.java

protected void delMenu(Map<String, Object> data) throws Exception {
    String host = (String) data.get("host");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {//ww w.  j a  v  a  2s  . co  m
        graph.begin();
        Vertex menu = graph.getVertexByKey("Menu.host", host);
        if (menu != null) {
            // cascade deleting all menuItems belong to the host only.
            for (Vertex menuItem : graph.getVerticesOfClass("MenuItem")) {
                if (host.equals(menuItem.getProperty("host"))) {
                    graph.removeVertex(menuItem);
                }
            }
            graph.removeVertex(menu);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }

    Map<String, Object> menuMap = ServiceLocator.getInstance().getMemoryImage("menuMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) menuMap.get("cache");
    if (cache != null) {
        cache.remove(host);
    }
}

From source file:com.networknt.light.rule.menu.AbstractMenuRule.java

protected void updMenu(Map<String, Object> data) throws Exception {
    String host = (String) data.get("host");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {//from   w  ww  . j av a  2s .c o  m
        graph.begin();
        Vertex menu = graph.getVertexByKey("Menu.host", host);
        if (menu != null) {
            Set<String> addMenuItems = (Set) data.get("addMenuItems");
            if (addMenuItems != null) {
                for (String menuItemId : addMenuItems) {
                    Vertex menuItem = graph.getVertexByKey("MenuItem.menuItemId", menuItemId);
                    menu.addEdge("Own", menuItem);
                }
            }
            Set<String> delMenuItems = (Set) data.get("delMenuItems");
            if (delMenuItems != null) {
                for (String menuItemId : delMenuItems) {
                    Vertex menuItem = graph.getVertexByKey("MenuItem.menuItemId", menuItemId);
                    for (Edge edge : (Iterable<Edge>) menu.getEdges(Direction.OUT, "Own")) {
                        if (edge.getVertex(Direction.IN).equals(menuItem))
                            graph.removeEdge(edge);
                    }
                }
            }
            menu.setProperty("updateDate", data.get("updateDate"));
        }
        Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId"));
        updateUser.addEdge("Update", menu);
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
    // remove the cache item in order to reload the menu.
    Map<String, Object> menuMap = (Map<String, Object>) ServiceLocator.getInstance().getMemoryImage("menuMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) menuMap.get("cache");
    if (cache != null) {
        cache.remove(data.get("host"));
    }
}

From source file:com.networknt.light.rule.form.AbstractFormRule.java

protected void delForm(String formId) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {/*from  www .  j  a v a  2s . com*/
        graph.begin();
        Vertex form = graph.getVertexByKey("Form.formId", formId);
        if (form != null) {
            List<Map<String, Object>> actions = form.getProperty("action");
            for (Map<String, Object> action : actions) {
                String ruleClass = Util.getCommandRuleId(action);
                Vertex validation = graph.getVertexByKey("Validation.ruleClass", ruleClass);
                if (validation != null) {
                    graph.removeVertex(validation);
                }
            }
            graph.removeVertex(form);
        }
        graph.commit();
    } catch (Exception e) {
        graph.rollback();
        logger.error("Exception:", e);
    } finally {
        graph.shutdown();
    }
    Map<String, Object> formMap = ServiceLocator.getInstance().getMemoryImage("formMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) formMap.get("cache");
    if (cache != null) {
        cache.remove(formId);
    }
}

From source file:com.networknt.light.rule.form.AbstractFormRule.java

protected String addForm(Map<String, Object> data) throws Exception {
    String json = null;//from   www.  j av a  2s.  c  o m
    String formId = (String) data.get("formId");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId"));
        OrientVertex form = graph.addVertex("class:Form", data);
        createUser.addEdge("Create", form);
        // According to action in the list, populate validation schema.
        List<Map<String, Object>> actions = form.getProperty("action");
        for (Map<String, Object> action : actions) {
            String ruleClass = Util.getCommandRuleId(action);
            graph.addVertex("class:Validation", "ruleClass", ruleClass, "schema", data.get("schema"));
        }
        graph.commit();
        json = form.getRecord().toJSON();
    } catch (Exception e) {
        graph.rollback();
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    Map<String, Object> formMap = ServiceLocator.getInstance().getMemoryImage("formMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) formMap.get("cache");
    if (cache != null) {
        cache.remove(formId);
    }
    return json;
}

From source file:com.networknt.light.rule.transform.AbstractTransformRule.java

protected void delTransformRequest(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {//from   w  w w.  ja v a2s  . c o  m
        graph.begin();
        OIndex<?> reqRuleSequenceIdx = graph.getRawGraph().getMetadata().getIndexManager()
                .getIndex("ReqRuleSequenceIdx");
        OCompositeKey key = new OCompositeKey(data.get("ruleClass"), data.get("sequence"));
        OIdentifiable oid = (OIdentifiable) reqRuleSequenceIdx.get(key);
        if (oid != null) {
            ODocument transform = (ODocument) oid.getRecord();
            transform.delete();
            transform.save();
            graph.commit();
        }
    } catch (Exception e) {
        graph.rollback();
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    // remove the cached list if in order to reload it
    Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) ruleMap.get("cache");
    if (cache != null) {
        cache.remove(data.get("ruleClass"));
    }
}

From source file:com.networknt.light.rule.transform.AbstractTransformRule.java

protected void delTransformResponse(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {/* ww w.  j  a  va2  s. c om*/
        graph.begin();
        OIndex<?> resRuleSequenceIdx = graph.getRawGraph().getMetadata().getIndexManager()
                .getIndex("ResRuleSequenceIdx");
        OCompositeKey key = new OCompositeKey(data.get("ruleClass"), data.get("sequence"));
        OIdentifiable oid = (OIdentifiable) resRuleSequenceIdx.get(key);
        if (oid != null) {
            ODocument transform = (ODocument) oid.getRecord();
            transform.delete();
            transform.save();
            graph.commit();
        }
    } catch (Exception e) {
        graph.rollback();
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    // remove the cached list if in order to reload it
    Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) ruleMap.get("cache");
    if (cache != null) {
        cache.remove(data.get("ruleClass"));
    }
}

From source file:com.networknt.light.rule.transform.AbstractTransformRule.java

protected void addTransformResponse(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {//from w  w  w .j  a  v  a 2  s.c om
        graph.begin();
        Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId"));
        Object transformData = data.get("transformData");
        if (transformData != null) {
            Map<String, Object> map = mapper.readValue((String) transformData,
                    new TypeReference<HashMap<String, Object>>() {
                    });
            data.put("transformData", map);
        }
        OrientVertex transform = graph.addVertex("class:TransformResponse", data);
        createUser.addEdge("Create", transform);
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
    // remove the cached list if in order to reload it
    Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) ruleMap.get("cache");
    if (cache != null) {
        cache.remove(data.get("ruleClass"));
    }
}

From source file:com.networknt.light.rule.transform.AbstractTransformRule.java

protected void addTransformRequest(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {//from  w  w  w. j a v  a 2 s.c  o  m
        graph.begin();
        Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId"));
        // transformData is a json string, convert it to map.
        Object transformData = data.get("transformData");
        if (transformData != null) {
            Map<String, Object> map = mapper.readValue((String) transformData,
                    new TypeReference<HashMap<String, Object>>() {
                    });
            data.put("transformData", map);
        }
        OrientVertex transform = graph.addVertex("class:TransformRequest", data);
        createUser.addEdge("Create", transform);
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
    // remove the cached list if in order to reload it
    Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) ruleMap.get("cache");
    if (cache != null) {
        cache.remove(data.get("ruleClass"));
    }
}