Example usage for org.apache.commons.lang3.concurrent ConcurrentUtils putIfAbsent

List of usage examples for org.apache.commons.lang3.concurrent ConcurrentUtils putIfAbsent

Introduction

In this page you can find the example usage for org.apache.commons.lang3.concurrent ConcurrentUtils putIfAbsent.

Prototype

public static <K, V> V putIfAbsent(final ConcurrentMap<K, V> map, final K key, final V value) 

Source Link

Document

Puts a value in the specified ConcurrentMap if the key is not yet present.

Usage

From source file:org.onlab.util.GroupedThreadFactory.java

/**
 * Returns thread factory for producing threads associated with the specified
 * group name. The group name-space is hierarchical, based on slash-delimited
 * name segments, e.g. {@code onos/intent}.
 *
 * @param groupName group name/*from w  w  w .j av a2 s . com*/
 * @return thread factory
 */
public static GroupedThreadFactory groupedThreadFactory(String groupName) {
    GroupedThreadFactory factory = FACTORIES.get(groupName);
    if (factory != null) {
        return factory;
    }

    // Find the parent group or root the group hierarchy under default group.
    int i = groupName.lastIndexOf(DELIMITER);
    if (i > 0) {
        String name = groupName.substring(0, i);
        ThreadGroup parentGroup = groupedThreadFactory(name).threadGroup();
        factory = new GroupedThreadFactory(new ThreadGroup(parentGroup, groupName));
    } else {
        factory = new GroupedThreadFactory(new ThreadGroup(groupName));
    }

    return ConcurrentUtils.putIfAbsent(FACTORIES, groupName, factory);
}

From source file:org.onosproject.provider.nil.link.impl.NullLinkProvider.java

private boolean addLdesc(DeviceId did, LinkDescription ldesc) {
    Set<LinkDescription> ldescs = ConcurrentUtils.putIfAbsent(linkDescrs, did, Sets.newConcurrentHashSet());
    return ldescs.add(ldesc);
}

From source file:org.opendaylight.atrium.util.AtriumGroupedThreadFactory.java

/**
 * Returns thread factory for producing threads associated with the specified
 * group name. The group name-space is hierarchical, based on slash-delimited
 * name segments, //from  ww  w . jav  a2  s .  com
 *
 * @param groupName group name
 * @return thread factory
 */
public static AtriumGroupedThreadFactory groupedThreadFactory(String groupName) {
    AtriumGroupedThreadFactory factory = FACTORIES.get(groupName);
    if (factory != null) {
        return factory;
    }

    // Find the parent group or root the group hierarchy under default group.
    int i = groupName.lastIndexOf(DELIMITER);
    if (i > 0) {
        String name = groupName.substring(0, i);
        ThreadGroup parentGroup = groupedThreadFactory(name).threadGroup();
        factory = new AtriumGroupedThreadFactory(new ThreadGroup(parentGroup, groupName));
    } else {
        factory = new AtriumGroupedThreadFactory(new ThreadGroup(groupName));
    }

    return ConcurrentUtils.putIfAbsent(FACTORIES, groupName, factory);
}