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.weibo.api.motan.util.StatsUtil.java

public static ConcurrentMap<String, AccessStatisticResult> getTotalAccessStatistic(int peroid) {
    if (peroid > MotanConstants.STATISTIC_PEROID) {
        throw new RuntimeException("peroid need <= " + MotanConstants.STATISTIC_PEROID);
    }//from ww  w .j a v  a2 s . c o m

    long currentTimeMillis = System.currentTimeMillis();

    ConcurrentMap<String, AccessStatisticResult> totalResults = new ConcurrentHashMap<String, AccessStatisticResult>();

    for (Map.Entry<String, AccessStatisticItem> entry : accessStatistics.entrySet()) {
        AccessStatisticItem item = entry.getValue();

        AccessStatisticResult result = item.getStatisticResult(currentTimeMillis,
                MotanConstants.STATISTIC_PEROID);

        String key = entry.getKey();
        String[] keys = key.split(SEPARATE);
        if (keys.length != 3) {
            continue;
        }
        String application = keys[1];
        String module = keys[2];
        key = application + "|" + module;
        AccessStatisticResult appResult = totalResults.get(key);
        if (appResult == null) {
            totalResults.putIfAbsent(key, new AccessStatisticResult());
            appResult = totalResults.get(key);
        }

        appResult.totalCount += result.totalCount;
        appResult.bizExceptionCount += result.bizExceptionCount;
        appResult.slowCount += result.slowCount;
        appResult.costTime += result.costTime;
        appResult.bizTime += result.bizTime;
        appResult.otherExceptionCount += result.otherExceptionCount;

    }

    return totalResults;

}

From source file:org.archive.crawler.reporting.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   w ww.j  a  va  2  s  .  c  om
 *            The HashMap
 * @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 = (AtomicLong) map.get(key);
    if (lw == null) {
        lw = new AtomicLong(0);
        AtomicLong prevVal = map.putIfAbsent(key, lw);
        if (prevVal != null) {
            lw = prevVal;
        }
    }
    lw.addAndGet(increment);
}

From source file:com.graphaware.reco.generic.stats.DefaultStatistics.java

/**
 * {@inheritDoc}/*www.j a va  2s .c  o m*/
 */
@Override
public void incrementStatistic(String task, String name) {
    ConcurrentMap<String, Object> taskStats = getStatistics(task);

    AtomicInteger count = (AtomicInteger) taskStats.get(name);
    if (count == null) {
        taskStats.putIfAbsent(name, new AtomicInteger());
        count = (AtomicInteger) taskStats.get(name);
    }

    count.incrementAndGet();
}

From source file:com.ebay.pulsar.sessionizer.impl.SessionizerErrorManager.java

private long incCounter(String errorName, ErrorType type) {

    ConcurrentMap<String, LongCounter> map = errorCounterMap.get(type.name());
    LongCounter counter = map.get(errorName);
    if (counter == null) {
        counter = new LongCounter();

        LongCounter existed = map.putIfAbsent(errorName, counter);
        if (existed != null) {
            counter = existed;/*from  w  w  w.ja  v a  2s  .c om*/
        }
    }
    return counter.increment();
}

From source file:net.cit.tetrad.rrd.batch.TetradRrdInitializer.java

/**
 * TetradRrd ? ?  /*from   w w  w . j a v  a  2  s  .c  om*/
 * @throws Exception
 */
public void install() throws Exception {
    try {
        // ?  ?  ?
        List<Device> devices = dataAccessObjectForMongo.readDeviceList();

        for (Device device : devices) {
            // ?  ??  RrdDb ?
            tetradRrdDbService.createTetradRrdDb(device);

            // ?? ??  ???  ?
            ConcurrentMap<Integer, MongoWrapper> mongoGroup = MongoInMemory.getMongoGroup();
            Mongo mongo = mongoGroup.get(device.getIdx()).getMongo();

            List<String> deviceNames = mongo.getDatabaseNames();
            for (String databaseName : deviceNames) {
                // ?  ????  RrdDb ?
                tetradRrdDbService.createTetradRrdDb(device, databaseName);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:org.restlet.ext.oauth.OAuthServerResource.java

@Override
protected void doInit() throws ResourceException {
    super.doInit();
    Context ctx = getContext();/*  w  w  w  . j  a va2s  .  co  m*/
    ConcurrentMap<String, Object> attribs = ctx.getAttributes();
    clients = (ClientManager) attribs.get(ClientManager.class.getName());
    tokens = (TokenManager) attribs.get(TokenManager.class.getName());

    getLogger().fine("Found client store = " + clients);
}

From source file:org.elasticsoftware.sip.SipChannelFactoryImpl.java

private Channel assureOpen(ConcurrentMap<String, Channel> cache, SipUser user) {

    // check is channel is open
    Channel c = cache.get(key(user));
    if (c != null && c.isConnected() && c.isOpen()) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("assureOpen. Cache hit [%s]", key(user)));
        }//from   w  ww.  j  av a 2  s . c o m
        return c;
    }

    try {
        if (log.isDebugEnabled()) {
            log.debug(String.format("assureOpen. Connecting address[%s:%d]", user.getDomain(), user.getPort()));
        }
        c = createChannel(user.getDomain(), user.getPort());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    cache.put(key(user), c);
    return c;
}

From source file:org.opendaylight.ovsdb.plugin.internal.NodeDatabase.java

public Row getRow(String dbName, String tableName, String uuid) {
    ConcurrentMap<String, Row> tdb = this.getTableCache(dbName, tableName);
    if (tdb == null) {
        return null;
    }//from  w  ww.ja v a 2 s .  co m
    return tdb.get(uuid);
}

From source file:org.opendaylight.ovsdb.plugin.internal.NodeDatabase.java

public ConcurrentMap<String, Row> getTableCache(String dbName, String tableName) {
    ConcurrentMap<String, ConcurrentMap<String, Row>> tdbMap = getDatabase(dbName);
    if (tdbMap == null) {
        return null;
    }//from   ww w.  j ava2s . c  o  m
    return tdbMap.get(tableName);
}

From source file:com.enonic.cms.web.portal.services.UserServicesAccessManagerImpl.java

private AccessPermission applyAccessRules(String service, String operation,
        ConcurrentMap<String, AccessPermission> siteRules) {
    // search for specific rule: "service.operation"
    AccessPermission accessServiceOperation = siteRules.get(service + "." + operation);
    if (accessServiceOperation != null) {
        return accessServiceOperation;
    }//from  w w w  . j  a  va2 s.c o  m

    // search for generic rule: "service.*"
    AccessPermission accessService = siteRules.get(service + ".*");
    if (accessService != null) {
        siteRules.putIfAbsent(service + "." + operation, accessService);
        return accessService;
    }

    // no rule found -> return default and cache value
    AccessPermission defaultAccess = siteRules.get(ACCESS_RULE_ALL);
    siteRules.putIfAbsent(service + "." + operation, defaultAccess);
    return defaultAccess;
}