Java 类com.google.common.util.concurrent.AtomicLongMap 实例源码

项目:ipst    文件:EurostagFakeNodes.java   
public static EurostagFakeNodes build(Network network, EurostagEchExportConfig config) {
    Objects.requireNonNull(network);
    Objects.requireNonNull(config);

    BiMap<String, String> fakeNodesMap = HashBiMap.create(new HashMap<>());
    AtomicLongMap<String> countUsesMap = AtomicLongMap.create();

    //adds 2 default fake nodes
    fakeNodesMap.put(EchUtil.FAKE_NODE_NAME1, EchUtil.FAKE_NODE_NAME1);
    countUsesMap.getAndIncrement(EchUtil.FAKE_NODE_NAME1);
    fakeNodesMap.put(EchUtil.FAKE_NODE_NAME2, EchUtil.FAKE_NODE_NAME2);
    countUsesMap.getAndIncrement(EchUtil.FAKE_NODE_NAME2);

    Identifiables.sort(network.getVoltageLevels()).stream().map(VoltageLevel::getId).forEach(vlId ->
            fakeNodesMap.put(vlId, newEsgId(fakeNodesMap, vlId)));

    return new EurostagFakeNodes(fakeNodesMap, countUsesMap, network);
}
项目:solr-cmd-utils    文件:AggregationCountFilter.java   
@Override
public void end() {

    for(Map.Entry<String, AtomicLongMap<String>> entry : aggregation.entrySet()) {
        String fieldName = entry.getKey();
        AtomicLongMap<String> fieldValue =  entry.getValue();
        for(Map.Entry<String,Long> fieldValueEntry : fieldValue.asMap().entrySet()) {
            String value = fieldValueEntry.getKey();
            Long count = fieldValueEntry.getValue();
            Document document = new Document();
            document.setField("value", value);
            document.setField("count", count);
            document.setField("type", fieldName);
            super.document(document);
        }
    }

    super.end();
}
项目:pinpoint    文件:AtomicLongMapTest.java   
@Test
public void testIncrement() throws Exception {
    AtomicLongMap<String> cache = AtomicLongMap.create();
    cache.addAndGet("a", 1L);
    cache.addAndGet("a", 2L);
    cache.addAndGet("b", 5L);


    Map<String, Long> remove = AtomicLongMapUtils.remove(cache);
    Assert.assertEquals((long) remove.get("a"), 3L);
    Assert.assertEquals((long) remove.get("b"), 5L);

    cache.addAndGet("a", 1L);
    Map<String, Long> remove2 = AtomicLongMapUtils.remove(cache);
    Assert.assertEquals((long) remove2.get("a"), 1L);
}
项目:guava-mock    文件:HashingTest.java   
public void testConsistentHash_probabilities() {
  AtomicLongMap<Integer> map = AtomicLongMap.create();
  Random r = new Random(9);
  for (int i = 0; i < ITERS; i++) {
    countRemaps(r.nextLong(), map);
  }
  for (int shard = 2; shard <= MAX_SHARDS; shard++) {
    // Rough: don't exceed 1.2x the expected number of remaps by more than 20
    assertTrue(map.get(shard) <= 1.2 * ITERS / shard + 20);
  }
}
项目:guava-mock    文件:HashingTest.java   
private void countRemaps(long h, AtomicLongMap<Integer> map) {
  int last = 0;
  for (int shards = 2; shards <= MAX_SHARDS; shards++) {
    int chosen = Hashing.consistentHash(h, shards);
    if (chosen != last) {
      map.incrementAndGet(shards);
      last = chosen;
    }
  }
}
项目:Elasticsearch    文件:TermVectorsFilter.java   
public TermVectorsFilter(Fields termVectorsByField, Fields topLevelFields, Set<String> selectedFields, @Nullable AggregatedDfs dfs) {
    this.fields = termVectorsByField;
    this.topLevelFields = topLevelFields;
    this.selectedFields = selectedFields;

    this.dfs = dfs;
    this.scoreTerms = new HashMap<>();
    this.sizes = AtomicLongMap.create();
    this.similarity = new DefaultSimilarity();
}
项目:googles-monorepo-demo    文件:HashingTest.java   
public void testConsistentHash_probabilities() {
  AtomicLongMap<Integer> map = AtomicLongMap.create();
  Random r = new Random(9);
  for (int i = 0; i < ITERS; i++) {
    countRemaps(r.nextLong(), map);
  }
  for (int shard = 2; shard <= MAX_SHARDS; shard++) {
    // Rough: don't exceed 1.2x the expected number of remaps by more than 20
    assertTrue(map.get(shard) <= 1.2 * ITERS / shard + 20);
  }
}
项目:googles-monorepo-demo    文件:HashingTest.java   
private void countRemaps(long h, AtomicLongMap<Integer> map) {
  int last = 0;
  for (int shards = 2; shards <= MAX_SHARDS; shards++) {
    int chosen = Hashing.consistentHash(h, shards);
    if (chosen != last) {
      map.incrementAndGet(shards);
      last = chosen;
    }
  }
}
项目:turnus    文件:MarkovSimpleScheduler.java   
PartitionMarkowData(List<Actor> actors) {
    this.actors = ActorsSorter.topologicalOrder(actors);
    successorsMap = new HashMap<>();
    for (Actor actor : actors) {
        successorsMap.put(actor, AtomicLongMap.create());
    }
    firings = AtomicLongMap.create();
    lastFiredActor = null;
    firstFiredActor = null;
}
项目:turnus    文件:CriticalPathCollector.java   
Pcp(String partition) {
    this.partition = partition;
    finishTime = 0;
    pcpFirings = AtomicLongMap.create();
    sumPcpWeightMap = new HashMap<>();
    maxBlockedTokens = new HashMap<>();
    maxBlockedMultiplication = new HashMap<>();
    blockingInstances = new HashMap<>();
    partitionsBlockingMap = new HashMap<>();
}
项目:turnus    文件:CriticalPathCollector.java   
Pcp(Pcp o) {
    partition = o.partition;
    finishTime = o.finishTime;
    pcpFirings = AtomicLongMap.create(o.pcpFirings.asMap());
    sumPcpWeightMap = new HashMap<>(o.sumPcpWeightMap);
    maxBlockedTokens = new HashMap<>(o.maxBlockedTokens);
    maxBlockedMultiplication = new HashMap<>(o.maxBlockedMultiplication);
    blockingInstances = new HashMap<>(o.blockingInstances);
    partitionsBlockingMap = new HashMap<>(o.partitionsBlockingMap);
}
项目:turnus    文件:AlgorithmicPartialCriticalPathAnalysis.java   
private Pcp(Action action, double weight, double variance) {
    pcpWeight = weight;
    pcpVariance = variance;

    pcpFirings = AtomicLongMap.create();
    pcpFirings.incrementAndGet(action);

    sumPcpWeightMap = new HashMap<>();
    sumPcpWeightMap.put(action, weight);

    sumPcpVarianceMap = new HashMap<>();
    sumPcpVarianceMap.put(action, variance);
}
项目:turnus    文件:AlgorithmicPartialCriticalPathAnalysis.java   
private Pcp(Pcp o) {
    pcpWeight = o.pcpWeight;
    pcpVariance = o.pcpVariance;

    pcpFirings = AtomicLongMap.create(o.pcpFirings.asMap());
    sumPcpWeightMap = new HashMap<>(o.sumPcpWeightMap);
    sumPcpVarianceMap = new HashMap<>(o.sumPcpVarianceMap);
}
项目:jbosen    文件:VectorClock.java   
public VectorClock(Vector<Integer> ids) {
    minClock = 0;
    vecClock = AtomicLongMap.create();
    for (Integer id : ids) {
        vecClock.put(id, 0);
    }
}
项目:guava-libraries    文件:HashingTest.java   
public void testConsistentHash_probabilities() {
  AtomicLongMap<Integer> map = AtomicLongMap.create();
  Random r = new Random(9);
  for (int i = 0; i < ITERS; i++) {
    countRemaps(r.nextLong(), map);
  }
  for (int shard = 2; shard <= MAX_SHARDS; shard++) {
    // Rough: don't exceed 1.2x the expected number of remaps by more than 20
    assertTrue(map.get(shard) <= 1.2 * ITERS / shard + 20);
  }
}
项目:guava-libraries    文件:HashingTest.java   
private void countRemaps(long h, AtomicLongMap<Integer> map) {
  int last = 0;
  for (int shards = 2; shards <= MAX_SHARDS; shards++) {
    int chosen = Hashing.consistentHash(h, shards);
    if (chosen != last) {
      map.incrementAndGet(shards);
      last = chosen;
    }
  }
}
项目:java-jump-consistent-hash    文件:HashingTest.java   
public void testConsistentHash_probabilities() {
    AtomicLongMap<Integer> map = AtomicLongMap.create();
    Random r = new Random(9);
    for (int i = 0; i < ITERS; i++) {
        countRemaps(r.nextLong(), map);
    }
    for (int shard = 2; shard <= MAX_SHARDS; shard++) {
        // Rough: don't exceed 1.2x the expected number of remaps by more than 20
        assertTrue(map.get(shard) <= 1.2 * ITERS / shard + 20);
    }
}
项目:java-jump-consistent-hash    文件:HashingTest.java   
private void countRemaps(long h, AtomicLongMap<Integer> map) {
    int last = 0;
    for (int shards = 2; shards <= MAX_SHARDS; shards++) {
        int chosen = Hashing.consistentHash(h, shards);
        if (chosen != last) {
            map.incrementAndGet(shards);
            last = chosen;
        }
    }
}
项目:guava    文件:HashingTest.java   
public void testConsistentHash_probabilities() {
  AtomicLongMap<Integer> map = AtomicLongMap.create();
  Random r = new Random(9);
  for (int i = 0; i < ITERS; i++) {
    countRemaps(r.nextLong(), map);
  }
  for (int shard = 2; shard <= MAX_SHARDS; shard++) {
    // Rough: don't exceed 1.2x the expected number of remaps by more than 20
    assertTrue(map.get(shard) <= 1.2 * ITERS / shard + 20);
  }
}
项目:guava    文件:HashingTest.java   
private void countRemaps(long h, AtomicLongMap<Integer> map) {
  int last = 0;
  for (int shards = 2; shards <= MAX_SHARDS; shards++) {
    int chosen = Hashing.consistentHash(h, shards);
    if (chosen != last) {
      map.incrementAndGet(shards);
      last = chosen;
    }
  }
}
项目:guava    文件:HashingTest.java   
public void testConsistentHash_probabilities() {
  AtomicLongMap<Integer> map = AtomicLongMap.create();
  Random r = new Random(9);
  for (int i = 0; i < ITERS; i++) {
    countRemaps(r.nextLong(), map);
  }
  for (int shard = 2; shard <= MAX_SHARDS; shard++) {
    // Rough: don't exceed 1.2x the expected number of remaps by more than 20
    assertTrue(map.get(shard) <= 1.2 * ITERS / shard + 20);
  }
}
项目:guava    文件:HashingTest.java   
private void countRemaps(long h, AtomicLongMap<Integer> map) {
  int last = 0;
  for (int shards = 2; shards <= MAX_SHARDS; shards++) {
    int chosen = Hashing.consistentHash(h, shards);
    if (chosen != last) {
      map.incrementAndGet(shards);
      last = chosen;
    }
  }
}
项目:pinpoint    文件:AtomicLongMapUtils.java   
public static <T> Map<T, Long> remove(AtomicLongMap<T> atomicLongMap) {
    final Map<T, Long> view = atomicLongMap.asMap();

    // view.size() is not recommended, cache entry is striped and volatile field
    final List<T> keySnapshot = keySnapshot(view);

    return remove(atomicLongMap, keySnapshot);
}
项目:pinpoint    文件:AtomicLongMapTest.java   
@Test
public void testIntegerMax() throws Exception {
    AtomicLongMap<String> cache = AtomicLongMap.create();
    cache.addAndGet("a", 1L);
    cache.addAndGet("a", 2L);
    cache.addAndGet("b", 5L);
}
项目:pinpoint    文件:AtomicLongMapTest.java   
@Test
public void testIntegerMin() throws Exception {
    AtomicLongMap<String> cache = AtomicLongMap.create();
    cache.addAndGet("a", 1L);
    cache.addAndGet("a", 2L);
    cache.addAndGet("b", 5L);

}
项目:tiny-async-java    文件:RecursionSafeAsyncCallerIT.java   
@SuppressWarnings("unchecked")
@Before
public void setup() throws Exception {
  recursionDepthPerThread = AtomicLongMap.create();
  maxRecursionDepthPerThread = AtomicLongMap.create();
  totIterations = new AtomicLong(0);
}
项目:ConsensusFixer    文件:SFRComputing.java   
public static void add(int position, byte base, Map<Integer, AtomicLongMap> alignmentMap) {
    try {
        if (!alignmentMap.containsKey(position)) {
            alignmentMap.put(position, AtomicLongMap.create());
        }
        alignmentMap.get(position).incrementAndGet(base);
    } catch (IllegalArgumentException e) {
        System.out.println(e);
    }
}
项目:ConsensusFixer    文件:SFRComputing.java   
private static void addInsert(int position, int insertIndex, byte base, Map<Integer, Map<Integer, AtomicLongMap>> insertionMap) {
    try {
        if (!insertionMap.containsKey(position)) {
            insertionMap.put(position, new ConcurrentHashMap<Integer, AtomicLongMap>());
        }
        add(insertIndex, base, insertionMap.get(position));
    } catch (IllegalArgumentException e) {
        System.out.println(e);
    }
}
项目:Server-Application    文件:StatisticRepository.java   
@PostConstruct
public void init() {
  totalRequests = new AtomicLong(0);
  staffRequests = new AtomicLong(0);
  buildingRequests = new AtomicLong(0);
  sportRequests = new AtomicLong(0);
  newsRequests = new AtomicLong(0);
  mailboxRequests = new AtomicLong(0);
  weatherRequests = new AtomicLong(0);
  timetableRequests = new AtomicLong(0);
  mensaRequests = AtomicLongMap.create();
  errorRequests = new AtomicLong(0);
  requestType = AtomicLongMap.create();
  executionTimes = EvictingQueue.create(10000);
}
项目:googleads-java-lib    文件:ApiServicesRetryStrategy.java   
private ApiServicesRetryStrategy() {
  this.maxAttemptsOnRateExceededError = ConfigCalculator.MAX_ATTEMPTS_ON_RATE_EXCEEDED_ERROR;
  this.maxWaitTimeOnRateExceededError = ConfigCalculator.MAX_WAIT_TIME_ON_RATE_EXCEEDED_ERROR;

  this.tokenWaitUntil = new AtomicLong();
  this.accountWaitUntil = AtomicLongMap.create();
}
项目:util    文件:MapUtil.java   
/**
 * 以Guava的AtomicLongMap,实现线程安全的HashMap<E,AtomicLong>结构的Counter
 */
public static <E> AtomicLongMap<E> createConcurrentMapCounter() {
    return AtomicLongMap.create();
}
项目:ipst    文件:EurostagFakeNodes.java   
private EurostagFakeNodes(Map<String, String> fakeNodesMap, AtomicLongMap<String> countUsesMap, Network network) {
    this.network = network;
    this.fakeNodesMap = HashBiMap.create(fakeNodesMap);
    this.countUsesMap = countUsesMap;
}
项目:cachecloud    文件:ErrorLoggerWatcher.java   
@Override
public long getTotalErrorCount() {
    AtomicLongMap<String> atomicLongMap = ErrorStatisticsAppender.ERROR_NAME_VALUE_MAP;
    return atomicLongMap.sum();
}
项目:jbosen    文件:VectorClock.java   
public VectorClock() {
    minClock = -1;
    vecClock = AtomicLongMap.create();
}
项目:pinpoint    文件:AtomicLongMapTest.java   
public void testRemove_thread_safety() throws InterruptedException {
    final AtomicLongMap<String> cache = AtomicLongMap.create();

    final int totalThread = 5;
    final ExecutorService executorService = Executors.newFixedThreadPool(totalThread);

    final AtomicLong totalCounter = new AtomicLong();
    final AtomicBoolean writerThread = new AtomicBoolean(true);
    final AtomicBoolean removeThread = new AtomicBoolean(true);

    final CountDownLatch writerLatch = new CountDownLatch(totalThread);

    for (int i = 0; i < totalThread; i++) {
        final int writerName = i;
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                while (writerThread.get()) {
                    cache.incrementAndGet("aa");
                    cache.incrementAndGet("cc");
                    cache.incrementAndGet("aa");
                    cache.incrementAndGet("bb");
                    cache.incrementAndGet("bb");
                    cache.incrementAndGet("bb");
                    cache.incrementAndGet("cc");
                    cache.incrementAndGet("d");
                    totalCounter.addAndGet(8);
                }
                writerLatch.countDown();
                logger.debug("shutdown {}", writerName);
            }
        });
    }

    final AtomicLong sumCounter = new AtomicLong();
    executorService.execute(new Runnable() {
        @Override
        public void run() {
            while (removeThread.get()) {
                Map<String, Long> remove = AtomicLongMapUtils.remove(cache);
                sumCounter.addAndGet(sum(remove));
                logger.debug("sum:{}", remove);

                Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
            }
        }
    });

    Uninterruptibles.sleepUninterruptibly(5000, TimeUnit.MILLISECONDS);
    writerThread.set(false);
    writerLatch.await();


    Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
    removeThread.set(false);
    Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);


    executorService.shutdown();
    logger.debug("total={} sum:{}", totalCounter.get(), sumCounter.get());
    Assert.assertEquals("concurrent remove and increment", totalCounter.get(), sumCounter.get());


}
项目:onos    文件:TestAtomicCounterMap.java   
private TestAtomicCounterMap(String name) {
    // Init name, map using create
    atomicCounterMapName = name;
    map = AtomicLongMap.create();
}
项目:ConsensusFixer    文件:Alignment.java   
private static double singleEntry(Map.Entry<Integer, AtomicLongMap> e, Map<Integer, String> consensusMap, int minimalCoverage) {
    if (e.getValue() == null) {
        return -1;
    }
    Map<Byte, Long> bases = e.getValue().asMap();
    long max = -1;
    double sum = 0;
    char base = ' ';
    long base_non_gap_max = -1;
    for (Map.Entry<Byte, Long> se : bases.entrySet()) {
        long i = se.getValue();
        sum += i;
        if (i > max) {
            max = i;
        }
        if (se.getKey() != GAP && i > base_non_gap_max) {
            base_non_gap_max = i;
            base = (char) se.getKey().byteValue();
        }
    }
    if (sum >= minimalCoverage) {
        SortedSet<Byte> keys = new TreeSet<>(bases.keySet());
        if (bases.containsKey(GAP) && bases.get(GAP) / sum >= Globals.PLURALITY_N) {
            if (!Globals.RM_DEL) {
                consensusMap.put(e.getKey(), "N");
            } else {
                consensusMap.put(e.getKey(), "");
            }
        } else {
            if (bases.containsKey(GAP)) {
                sum -= bases.get(GAP);
            }
            if (Globals.MAJORITY_VOTE) {
                consensusMap.put(e.getKey(), String.valueOf(base));
            } else {
                StringBuilder w_sb = new StringBuilder();
                for (Byte b : keys) {
                    if (b != GAP && bases.containsKey(b) && bases.get(b) / sum >= Globals.PLURALITY) {
                        w_sb.append((char) b.byteValue());
                    }
                }
                consensusMap.put(e.getKey(), wobbles.get(w_sb.toString()));
            }
        }
    }
    return sum;
}
项目:Server-Application    文件:StatisticRepository.java   
/**
 * @return the mensaRequests
 */
public AtomicLongMap<Integer> getMensaRequests() {
  return mensaRequests;
}
项目:Server-Application    文件:StatisticRepository.java   
/**
 * @return the requestType
 */
public AtomicLongMap<RequestMethod> getRequestType() {
  return requestType;
}