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:com.networknt.light.rule.catalog.AbstractCatalogRule.java

public boolean delProduct(Object... objects) throws Exception {
    Map<String, Object> inputMap = (Map<String, Object>) objects[0];
    Map<String, Object> data = (Map<String, Object>) inputMap.get("data");
    String rid = (String) data.get("@rid");
    String host = (String) data.get("host");
    String error = null;// w w  w.j  av a2s  .  co m
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        OrientVertex product = (OrientVertex) DbService.getVertexByRid(graph, rid);
        if (product != null) {
            // check if the product has variant, if yes, you cannot delete it for now
            // TODO fix it after orientdb 2.2 release.
            // https://github.com/orientechnologies/orientdb/issues/1108
            if (product.countEdges(Direction.OUT, "HasComment") > 0) {
                error = "Product has comment(s), cannot be deleted";
                inputMap.put("responseCode", 400);
            } else {
                Map eventMap = getEventMap(inputMap);
                Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data");
                inputMap.put("eventMap", eventMap);
                eventData.put("productId", product.getProperty("productId"));
            }
        } else {
            error = "@rid " + rid + " cannot be found";
            inputMap.put("responseCode", 404);
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    if (error != null) {
        inputMap.put("result", error);
        return false;
    } else {
        // update the branch tree as the number of products has changed.
        Map<String, Object> branchMap = ServiceLocator.getInstance().getMemoryImage("branchMap");
        ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) branchMap.get("treeCache");
        if (cache != null) {
            cache.remove(host + branchType);
        }
        return true;
    }
}

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

public boolean delPost(String bfnType, Object... objects) throws Exception {
    Map<String, Object> inputMap = (Map<String, Object>) objects[0];
    Map<String, Object> data = (Map<String, Object>) inputMap.get("data");
    String rid = (String) data.get("@rid");
    String host = (String) data.get("host");
    String error = null;/*  w  w w . j  av  a2 s .c om*/
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        OrientVertex post = (OrientVertex) DbService.getVertexByRid(graph, rid);
        if (post != null) {
            // check if the post has comment, if yes, you cannot delete it for now
            // TODO fix it after orientdb 2.2 release.
            // https://github.com/orientechnologies/orientdb/issues/1108
            if (post.countEdges(Direction.OUT, "HasComment") > 0) {
                error = "Post has comment(s), cannot be deleted";
                inputMap.put("responseCode", 400);
            } else {
                Map eventMap = getEventMap(inputMap);
                Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data");
                inputMap.put("eventMap", eventMap);
                eventData.put("postId", post.getProperty("postId"));
            }
        } else {
            error = "@rid " + rid + " cannot be found";
            inputMap.put("responseCode", 404);
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    if (error != null) {
        inputMap.put("result", error);
        return false;
    } else {
        // update the bfn tree as the number of posts has changed.
        Map<String, Object> bfnMap = ServiceLocator.getInstance().getMemoryImage("bfnMap");
        ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) bfnMap.get("treeCache");
        if (cache != null) {
            cache.remove(host + bfnType);
        }
        return true;
    }
}

From source file:com.networknt.light.rule.catalog.AbstractCatalogRule.java

public boolean updProduct(Object... objects) throws Exception {
    Map<String, Object> inputMap = (Map<String, Object>) objects[0];
    Map<String, Object> data = (Map<String, Object>) inputMap.get("data");
    String rid = (String) data.get("@rid");
    String host = (String) data.get("host");
    String error = null;/*from w  ww  .  j av  a 2 s. c  o m*/
    Map<String, Object> payload = (Map<String, Object>) inputMap.get("payload");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        // update product itself and we might have a new api to move product from one parent to another.
        Vertex product = DbService.getVertexByRid(graph, rid);
        if (product != null) {
            Map<String, Object> user = (Map<String, Object>) payload.get("user");
            Map eventMap = getEventMap(inputMap);
            Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data");
            inputMap.put("eventMap", eventMap);
            eventData.put("productId", product.getProperty("productId"));
            eventData.put("name", data.get("name"));
            eventData.put("description", data.get("description"));
            eventData.put("variants", data.get("variants"));
            eventData.put("updateDate", new java.util.Date());
            eventData.put("updateUserId", user.get("userId"));

            // tags
            Set<String> inputTags = data.get("tags") != null
                    ? new HashSet<String>(Arrays.asList(((String) data.get("tags")).split("\\s*,\\s*")))
                    : new HashSet<String>();
            Set<String> storedTags = new HashSet<String>();
            for (Vertex vertex : (Iterable<Vertex>) product.getVertices(Direction.OUT, "HasTag")) {
                storedTags.add((String) vertex.getProperty("tagId"));
            }

            Set<String> addTags = new HashSet<String>(inputTags);
            Set<String> delTags = new HashSet<String>(storedTags);
            addTags.removeAll(storedTags);
            delTags.removeAll(inputTags);

            if (addTags.size() > 0)
                eventData.put("addTags", addTags);
            if (delTags.size() > 0)
                eventData.put("delTags", delTags);
        } else {
            error = "@rid " + rid + " cannot be found";
            inputMap.put("responseCode", 404);
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    if (error != null) {
        inputMap.put("result", error);
        return false;
    } else {
        // update the branch tree as the last update time has changed.
        Map<String, Object> branchMap = ServiceLocator.getInstance().getMemoryImage("branchMap");
        ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) branchMap.get("treeCache");
        if (cache != null) {
            cache.remove(host + branchType);
        }
        return true;
    }
}

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

public boolean updPost(String bfnType, Object... objects) throws Exception {
    Map<String, Object> inputMap = (Map<String, Object>) objects[0];
    Map<String, Object> data = (Map<String, Object>) inputMap.get("data");
    String rid = (String) data.get("@rid");
    String host = (String) data.get("host");
    String error = null;//  w  ww .j  av a 2s.  c om
    Map<String, Object> payload = (Map<String, Object>) inputMap.get("payload");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        // update post itself and we might have a new api to move post from one parent to another.
        Vertex post = DbService.getVertexByRid(graph, rid);
        if (post != null) {
            Map<String, Object> user = (Map<String, Object>) payload.get("user");
            Map eventMap = getEventMap(inputMap);
            Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data");
            inputMap.put("eventMap", eventMap);
            eventData.put("postId", post.getProperty("postId"));
            eventData.put("title", data.get("title"));
            eventData.put("source", data.get("source"));
            eventData.put("summary", data.get("summary"));
            eventData.put("content", data.get("content"));
            eventData.put("updateDate", new java.util.Date());
            eventData.put("updateUserId", user.get("userId"));
            // tags
            Set<String> inputTags = data.get("tags") != null
                    ? new HashSet<String>(Arrays.asList(((String) data.get("tags")).split("\\s*,\\s*")))
                    : new HashSet<String>();
            Set<String> storedTags = new HashSet<String>();
            for (Vertex vertex : (Iterable<Vertex>) post.getVertices(Direction.OUT, "HasTag")) {
                storedTags.add((String) vertex.getProperty("tagId"));
            }

            Set<String> addTags = new HashSet<String>(inputTags);
            Set<String> delTags = new HashSet<String>(storedTags);
            addTags.removeAll(storedTags);
            delTags.removeAll(inputTags);

            if (addTags.size() > 0)
                eventData.put("addTags", addTags);
            if (delTags.size() > 0)
                eventData.put("delTags", delTags);
        } else {
            error = "@rid " + rid + " cannot be found";
            inputMap.put("responseCode", 404);
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    if (error != null) {
        inputMap.put("result", error);
        return false;
    } else {
        // update the bfn tree as the last update time has changed.
        Map<String, Object> bfnMap = ServiceLocator.getInstance().getMemoryImage("bfnMap");
        ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) bfnMap.get("treeCache");
        if (cache != null) {
            cache.remove(host + bfnType);
        }
        return true;
    }
}

From source file:com.fhzz.dubbo.sync.RegistryServerSync.java

@PostConstruct
public void start() {
    registry.subscribe(SUBSCRIBE, new NotifyListener() {
        @Override//from   w  w w.  ja  v a  2s  . c o m
        //  ???override?subcribe?route?Provider????
        public void notify(List<URL> urls) {
            if (urls == null || urls.isEmpty()) {
                return;
            }
            // Map<category, Map<servicename, Map<Long, URL>>>
            final Map<String, Map<String, Map<Long, URL>>> categories = new HashMap<String, Map<String, Map<Long, URL>>>();
            for (URL url : urls) {
                String category = url.getParameter(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
                if (Constants.EMPTY_PROTOCOL.equalsIgnoreCase(url.getProtocol())) { // ?empty??groupversion*
                    ConcurrentMap<String, Map<Long, URL>> services = registryCache.get(category);
                    if (services != null) {
                        String group = url.getParameter(Constants.GROUP_KEY);
                        String version = url.getParameter(Constants.VERSION_KEY);
                        // ?empty??groupversion*
                        if (!Constants.ANY_VALUE.equals(group) && !Constants.ANY_VALUE.equals(version)) {
                            services.remove(url.getServiceKey());
                        } else {
                            for (Map.Entry<String, Map<Long, URL>> serviceEntry : services.entrySet()) {
                                String service = serviceEntry.getKey();
                                if (Tool.getInterface(service).equals(url.getServiceInterface())
                                        && (Constants.ANY_VALUE.equals(group)
                                                || StringUtils.isEquals(group, Tool.getGroup(service)))
                                        && (Constants.ANY_VALUE.equals(version)
                                                || StringUtils.isEquals(version, Tool.getVersion(service)))) {
                                    services.remove(service);
                                }
                            }
                        }
                    }
                } else {
                    Map<String, Map<Long, URL>> services = categories.get(category);
                    if (services == null) {
                        services = new HashMap<String, Map<Long, URL>>();
                        categories.put(category, services);
                    }
                    String service = url.getServiceKey();
                    Map<Long, URL> ids = services.get(service);
                    if (ids == null) {
                        ids = new HashMap<Long, URL>();
                        services.put(service, ids);
                    }
                    ids.put(ID.incrementAndGet(), url);
                }
            }
            for (Map.Entry<String, Map<String, Map<Long, URL>>> categoryEntry : categories.entrySet()) {
                String category = categoryEntry.getKey();
                ConcurrentMap<String, Map<Long, URL>> services = registryCache.get(category);
                if (services == null) {
                    services = new ConcurrentHashMap<String, Map<Long, URL>>();
                    registryCache.put(category, services);
                }
                services.putAll(categoryEntry.getValue());
            }
        }
    });
}

From source file:org.onosproject.store.trivial.impl.SimpleGroupStore.java

/**
 * Updates the existing group entry with the information
 * from group description.//from  ww w.  j ava 2 s  .  c o m
 *
 * @param deviceId the device ID
 * @param oldAppCookie the current group key
 * @param type update type
 * @param newBuckets group buckets for updates
 * @param newAppCookie optional new group key
 */
@Override
public void updateGroupDescription(DeviceId deviceId, GroupKey oldAppCookie, UpdateType type,
        GroupBuckets newBuckets, GroupKey newAppCookie) {
    // Check if a group is existing with the provided key
    Group oldGroup = getGroup(deviceId, oldAppCookie);
    if (oldGroup == null) {
        return;
    }

    List<GroupBucket> newBucketList = getUpdatedBucketList(oldGroup, type, newBuckets);
    if (newBucketList != null) {
        // Create a new group object from the old group
        GroupBuckets updatedBuckets = new GroupBuckets(newBucketList);
        GroupKey newCookie = (newAppCookie != null) ? newAppCookie : oldAppCookie;
        GroupDescription updatedGroupDesc = new DefaultGroupDescription(oldGroup.deviceId(), oldGroup.type(),
                updatedBuckets, newCookie, oldGroup.appId());
        StoredGroupEntry newGroup = new DefaultGroup(oldGroup.id(), updatedGroupDesc);
        newGroup.setState(GroupState.PENDING_UPDATE);
        newGroup.setLife(oldGroup.life());
        newGroup.setPackets(oldGroup.packets());
        newGroup.setBytes(oldGroup.bytes());
        // Remove the old entry from maps and add new entry using new key
        ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(oldGroup.deviceId());
        ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(oldGroup.deviceId());
        keyTable.remove(oldGroup.appCookie());
        idTable.remove(oldGroup.id());
        keyTable.put(newGroup.appCookie(), newGroup);
        idTable.put(newGroup.id(), newGroup);
        notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, newGroup));
    }
}

From source file:org.onosproject.store.trivial.SimpleGroupStore.java

/**
 * Updates the existing group entry with the information
 * from group description./* w w w  . j a  v  a  2 s . c  o m*/
 *
 * @param deviceId the device ID
 * @param oldAppCookie the current group key
 * @param type update type
 * @param newBuckets group buckets for updates
 * @param newAppCookie optional new group key
 */
@Override
public void updateGroupDescription(DeviceId deviceId, GroupKey oldAppCookie, UpdateType type,
        GroupBuckets newBuckets, GroupKey newAppCookie) {
    // Check if a group is existing with the provided key
    Group oldGroup = getGroup(deviceId, oldAppCookie);
    if (oldGroup == null) {
        return;
    }

    List<GroupBucket> newBucketList = getUpdatedBucketList(oldGroup, type, newBuckets);
    if (newBucketList != null) {
        // Create a new group object from the old group
        GroupBuckets updatedBuckets = new GroupBuckets(newBucketList);
        GroupKey newCookie = (newAppCookie != null) ? newAppCookie : oldAppCookie;
        GroupDescription updatedGroupDesc = new DefaultGroupDescription(oldGroup.deviceId(), oldGroup.type(),
                updatedBuckets, newCookie, oldGroup.givenGroupId(), oldGroup.appId());
        StoredGroupEntry newGroup = new DefaultGroup(oldGroup.id(), updatedGroupDesc);
        newGroup.setState(GroupState.PENDING_UPDATE);
        newGroup.setLife(oldGroup.life());
        newGroup.setPackets(oldGroup.packets());
        newGroup.setBytes(oldGroup.bytes());
        // Remove the old entry from maps and add new entry using new key
        ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(oldGroup.deviceId());
        ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(oldGroup.deviceId());
        keyTable.remove(oldGroup.appCookie());
        idTable.remove(oldGroup.id());
        keyTable.put(newGroup.appCookie(), newGroup);
        idTable.put(newGroup.id(), newGroup);
        notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, newGroup));
    }
}

From source file:org.onosproject.yms.app.ysr.DefaultYangSchemaRegistry.java

/**
 * Removes schema node from schema map.//from  w  w  w  .ja v  a  2s.  c  o m
 *
 * @param removableNode schema node which needs to be removed
 */
private void removeSchemaNode(YangSchemaNode removableNode) {
    String name = removableNode.getName();
    String revName = name;
    String date = getDateInStringFormat(removableNode);
    if (date != null) {
        revName = name + AT + date;
    }
    ConcurrentMap<String, YangSchemaNode> revMap = yangSchemaStore.get(name);
    if (revMap != null && !revMap.isEmpty() && revMap.size() != 1) {
        revMap.remove(revName);
    } else {
        yangSchemaStore.remove(removableNode.getName());
    }
}

From source file:org.onosproject.store.group.impl.DistributedGroupStore.java

@Override
public void removeExtraneousGroupEntry(Group group) {
    log.debug("remove extraneous group entry {} of device {} from store", group.id(), group.deviceId());
    ConcurrentMap<GroupId, Group> extraneousIdTable = getExtraneousGroupIdTable(group.deviceId());
    extraneousIdTable.remove(group.id());
}

From source file:org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertsServiceImpl.java

private <T> void updateReferences(ServiceAlert existingServiceAlert, ServiceAlert serviceAlert,
        ConcurrentMap<T, Set<AgencyAndId>> map, AffectsKeyFactory<T> affectsKeyFactory) {

    Set<T> existingEffects = Collections.emptySet();
    if (existingServiceAlert != null) {
        existingEffects = affectsKeyFactory.getKeysForAffects(existingServiceAlert);
    }//w  ww  .  ja v a 2 s.c o m

    Set<T> newEffects = Collections.emptySet();
    if (serviceAlert != null) {
        newEffects = affectsKeyFactory.getKeysForAffects(serviceAlert);
    }

    for (T existingEffect : existingEffects) {
        if (newEffects.contains(existingEffect))
            continue;
        AgencyAndId id = ServiceAlertLibrary.agencyAndId(existingServiceAlert.getId());
        Set<AgencyAndId> ids = map.get(existingEffect);
        ids.remove(id);
        if (ids.isEmpty())
            map.remove(existingEffect);
    }

    for (T newEffect : newEffects) {
        if (existingEffects.contains(newEffect))
            continue;
        AgencyAndId id = ServiceAlertLibrary.agencyAndId(serviceAlert.getId());
        Set<AgencyAndId> ids = map.get(newEffect);
        if (ids == null) {
            ids = new HashSet<AgencyAndId>();
            map.put(newEffect, ids);
        }
        ids.add(id);
    }
}