Example usage for java.util.concurrent ConcurrentMap get

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

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.buddycloud.mediaserver.web.MediaServerResource.java

@SuppressWarnings("unchecked")
protected Series<Header> getMessageHeaders(Message message) {
    ConcurrentMap<String, Object> attrs = message.getAttributes();
    Series<Header> headers = (Series<Header>) attrs.get(HEADERS_KEY);

    if (headers == null) {
        headers = new Series<Header>(Header.class);
        Series<Header> prev = (Series<Header>) attrs.putIfAbsent(HEADERS_KEY, headers);

        if (prev != null) {
            headers = prev;//from   w  w w  .j a  v  a  2 s  .  c  o m
        }
    }

    return headers;
}

From source file:org.wso2.andes.kernel.slot.OrphanedSlotHandler.java

/**
 * Re-assign slots back to the slot manager if this is the last subscriber of this node.
 *
 * @param subscription current subscription fo the leaving node
 * @throws AndesException//from   w w w  .j  av  a 2  s .c om
 */
private void reAssignSlotsIfNeeded(AndesSubscription subscription) throws AndesException {
    if (subscription.isDurable()) {
        // Problem happens only with Queues
        SubscriptionStore subscriptionStore = AndesContext.getInstance().getSubscriptionStore();
        String destination = subscription.getSubscribedDestination();
        Collection<LocalSubscription> localSubscribersForQueue = subscriptionStore
                .getActiveLocalSubscribers(destination, false);
        if (localSubscribersForQueue.size() == 0) {
            String nodeId = HazelcastAgent.getInstance().getNodeId();
            try {
                MBThriftClient.reAssignSlotWhenNoSubscribers(nodeId, subscription.getTargetQueue());
                //remove tracking when orphan slot situation
                ConcurrentMap<String, Set<Slot>> subscriptionSlotTracker = OnflightMessageTracker.getInstance()
                        .getSubscriptionSlotTracker();
                Set<Slot> slotsToRemoveTrackingIfOrphaned = subscriptionSlotTracker
                        .get(subscription.getTargetQueue());
                for (Slot slot : slotsToRemoveTrackingIfOrphaned) {
                    OnflightMessageTracker.getInstance().clearAllTrackingWhenSlotOrphaned(slot);
                }

            } catch (ConnectionException e) {
                log.error("Error occurred while re-assigning the slot to slot manager", e);
                throw new AndesException("Error occurred while re-assigning the slot to slot manager", e);
            }
        }

    }
}

From source file:org.archive.crawler.admin.StatisticsTracker.java

/**
 * Increment a counter for a key in a given HashMap by an arbitrary amount.
 * Used for various aggregate data. The increment amount can be negative.
 *
 * @param map//from ww  w  .  jav a2 s .  co m
 *            The Map or ConcurrentMap
 * @param key
 *            The key for the counter to be incremented, if it does not exist
 *            it will be added (set to equal to <code>increment</code>).
 *            If null it will increment the counter "unknown".
 * @param increment
 *            The amount to increment counter related to the <code>key</code>.
 */
protected static void incrementMapCount(ConcurrentMap<String, AtomicLong> map, String key, long increment) {
    if (key == null) {
        key = "unknown";
    }
    AtomicLong lw = map.get(key);
    if (lw == null) {
        lw = new AtomicLong();
        AtomicLong prevVal = map.putIfAbsent(key, lw);
        if (prevVal != null) {
            lw = prevVal;
        }
    }
    lw.addAndGet(increment);
}

From source file:org.esigate.url.RoundRobinBaseUrlRetrieveStrategyTest.java

public void testGetBaseURL() {
    String[] baseUrls = new String[] { "http://example.com/test/", "http://example1.com/test/",
            "http://example2.com/test/" };
    BaseUrlRetrieveStrategy strategy = new RoundRobinBaseUrlRetrieveStrategy(baseUrls);
    IncomingRequest request = TestUtils.createIncomingRequest().build();
    int times = 5;
    int requestsCount = baseUrls.length * times;
    ConcurrentMap<String, AtomicInteger> counterMap = new ConcurrentHashMap<String, AtomicInteger>();
    for (int i = 0; i < requestsCount; i++) {
        String baseUrl = strategy.getBaseURL(request);
        counterMap.putIfAbsent(baseUrl, new AtomicInteger(0));
        counterMap.get(baseUrl).incrementAndGet();
    }/*from   ww w  . jav  a2s .co  m*/
    for (String baseUrl : baseUrls) {
        assertEquals(times, counterMap.get(baseUrl).get());
    }
}

From source file:com.opengamma.component.ComponentConfigLoader.java

private ConcurrentMap<String, String> adjustProperties(ConcurrentMap<String, String> input) {
    ConcurrentMap<String, String> map = new ConcurrentHashMap<String, String>();
    for (String key : input.keySet()) {
        map.put("${" + key + "}", input.get(key));
    }//from   w  w w.  j  av a 2 s. c  om
    return map;
}

From source file:org.apereo.portal.layout.StylesheetUserPreferencesImpl.java

@Override
public Map<String, String> getAllNodesAndValuesForAttribute(String name) {
    Validate.notEmpty(name, "name cannot be null");

    final Builder<String, String> result = ImmutableMap.builder();
    for (final Entry<String, ConcurrentMap<String, String>> layoutNodeAttributesEntry : this.layoutAttributes
            .entrySet()) {//from   www  .j  av a  2  s.  c om
        final ConcurrentMap<String, String> layoutNodeAttributes = layoutNodeAttributesEntry.getValue();
        final String value = layoutNodeAttributes.get(name);
        if (value != null) {
            final String nodeId = layoutNodeAttributesEntry.getKey();
            result.put(nodeId, value);
        }
    }

    return result.build();
}

From source file:com.ejisto.event.listener.SessionRecorderManager.java

private <K, V> Set<V> putIfAbsent(K key, ConcurrentMap<K, Set<V>> container) {
    Set<V> values = container.get(key);
    if (values == null) {
        container.putIfAbsent(key, new HashSet<>());
        values = container.get(key);/*from  w  w w .  jav a  2  s .c om*/
    }
    return new HashSet<>(values);
}

From source file:com.sastix.cms.server.services.cache.hazelcast.HazelcastCacheService.java

@Override
public CacheDTO getCachedResource(QueryCacheDTO queryCacheDTO) throws DataNotFound, CacheValidationException {
    LOG.info("HazelcastCacheService->getCachedResource ({})",
            queryCacheDTO != null ? queryCacheDTO.toString() : "null");
    nullValidationChecker(queryCacheDTO, QueryCacheDTO.class);
    String cacheKey = queryCacheDTO.getCacheKey();

    if (cacheKey == null) {
        throw new CacheValidationException("You cannot get a cache a resource with a null key");
    }/* w w w  .  j a v a  2  s.co m*/

    String cacheRegion = queryCacheDTO.getCacheRegion();
    CacheDTO cacheDTO;
    if (!StringUtils.isEmpty(cacheRegion)) { // GET from cache region
        ConcurrentMap<String, CacheDTO> cMap = cm.getCache(cacheRegion);
        cacheDTO = cMap.get(cacheKey);
    } else {// GET from default cache
        cacheDTO = this.cache.get(cacheKey);
    }

    boolean hasExpired = cacheFileUtilsService.isExpiredCachedResource(cacheDTO);

    if (hasExpired) {
        // Delete from cache silently and return null
        RemoveCacheDTO removeCacheDTO = new RemoveCacheDTO();
        removeCacheDTO.setCacheKey(cacheKey);
        removeCacheDTO.setCacheRegion(cacheRegion);
        removeCachedResource(removeCacheDTO);
        cacheDTO = null;
    }

    if (cacheDTO == null) {
        throw new DataNotFound("A cached resource could not be found with the given key: " + cacheKey);
    }
    return cacheDTO;
}

From source file:com.starit.diamond.client.impl.DefaultSubscriberListener.java

public List<ManagerListener> getManagerListenerList(String dataId, String group, String instanceId) {
    if (null == dataId || null == instanceId) {
        return null;
    }/*from w w  w  .  j  a  va  2  s . c  o  m*/

    List<ManagerListener> ret = null;

    String key = makeKey(dataId, group);
    ConcurrentMap<String, CopyOnWriteArrayList<ManagerListener>> map = allListeners.get(key);
    if (map != null) {
        ret = map.get(instanceId);
        if (ret != null) {
            ret = new ArrayList<ManagerListener>(ret);
        }
    }
    return ret;
}

From source file:com.pandich.dropwizard.curator.PropertySources.java

public PropertySource lookup(final Class clazz, final String name) {

    final ConcurrentMap<String, PropertySource> propertySources = this.classPropertySources.get(clazz);
    if (propertySources == null) {
        return ABSENT;
    }/* ww  w. j  a v a  2s. c  o m*/

    final PropertySource propertySource = propertySources.get(name);
    if (propertySource == null) {
        return ABSENT;
    }

    return propertySource;
}