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); }
@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(); }
@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); }
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); } }
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; } } }
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(); }
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; }
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<>(); }
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); }
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); }
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); }
public VectorClock(Vector<Integer> ids) { minClock = 0; vecClock = AtomicLongMap.create(); for (Integer id : ids) { vecClock.put(id, 0); } }
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); }
@Test public void testIntegerMax() throws Exception { AtomicLongMap<String> cache = AtomicLongMap.create(); cache.addAndGet("a", 1L); cache.addAndGet("a", 2L); cache.addAndGet("b", 5L); }
@Test public void testIntegerMin() throws Exception { AtomicLongMap<String> cache = AtomicLongMap.create(); cache.addAndGet("a", 1L); cache.addAndGet("a", 2L); cache.addAndGet("b", 5L); }
@SuppressWarnings("unchecked") @Before public void setup() throws Exception { recursionDepthPerThread = AtomicLongMap.create(); maxRecursionDepthPerThread = AtomicLongMap.create(); totIterations = new AtomicLong(0); }
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); } }
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); } }
@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); }
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(); }
/** * 以Guava的AtomicLongMap,实现线程安全的HashMap<E,AtomicLong>结构的Counter */ public static <E> AtomicLongMap<E> createConcurrentMapCounter() { return AtomicLongMap.create(); }
private EurostagFakeNodes(Map<String, String> fakeNodesMap, AtomicLongMap<String> countUsesMap, Network network) { this.network = network; this.fakeNodesMap = HashBiMap.create(fakeNodesMap); this.countUsesMap = countUsesMap; }
@Override public long getTotalErrorCount() { AtomicLongMap<String> atomicLongMap = ErrorStatisticsAppender.ERROR_NAME_VALUE_MAP; return atomicLongMap.sum(); }
public VectorClock() { minClock = -1; vecClock = AtomicLongMap.create(); }
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()); }
private TestAtomicCounterMap(String name) { // Init name, map using create atomicCounterMapName = name; map = AtomicLongMap.create(); }
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; }
/** * @return the mensaRequests */ public AtomicLongMap<Integer> getMensaRequests() { return mensaRequests; }
/** * @return the requestType */ public AtomicLongMap<RequestMethod> getRequestType() { return requestType; }