List of usage examples for com.google.common.util.concurrent AtomicDouble AtomicDouble
public AtomicDouble()
From source file:com.qwazr.utils.WordCount.java
public static float compare(WordCount dic1, WordCount dic2) { HashSet<String> wordSet = new HashSet<String>(dic1.wordCount.keySet()); wordSet.addAll(dic2.wordCount.keySet()); AtomicDouble similarity = new AtomicDouble(); wordSet.forEach(new Consumer<String>() { @Override//from w w w .j ava2 s .c o m public void accept(String word) { final AtomicInteger c1 = dic1.wordCount.get(word); final AtomicInteger c2 = dic2.wordCount.get(word); if (c1 == null || c2 == null) return; final double v1 = c1.doubleValue(); final double v2 = c2.doubleValue(); final double delta = v1 > v2 ? v2 / v1 : v1 / v2; similarity.addAndGet(delta); } }); return similarity.floatValue() / (float) wordSet.size(); }
From source file:com.github.lynxdb.server.common.Average.java
public Average() { sum = new AtomicDouble(); count = new AtomicInteger(); }
From source file:it.stilo.g.algo.GraphInfo.java
public static AtomicDouble[] getGraphInfo(final WeightedGraph a, int runner) { long time = System.currentTimeMillis(); final CountDownLatch latch = new CountDownLatch(runner); int[] vertexs = a.getVertex(); // Info Values TODO: convert to a map?! // 0 number of vertices // 1 number of edges // 2 Density (E)/(V*(V-1)) AtomicDouble[] values = new AtomicDouble[3]; for (int i = 0; i < values.length; i++) { values[i] = new AtomicDouble(); }/*from w w w. j a v a2s .c om*/ values[0].set(vertexs.length); Thread[] workers = new Thread[runner]; for (int i = 0; i < runner; i++) { workers[i] = new Thread(new GraphInfo(a, vertexs, values, latch, i, runner)); workers[i].setName("" + i); workers[i].start(); } try { latch.await(); } catch (InterruptedException e) { logger.debug(e); } values[0].set(vertexs.length); values[2].set((values[1].get()) / (values[0].get() * (values[0].get() - 1))); logger.info(((System.currentTimeMillis() - time) / 1000d) + "s"); return values; }
From source file:org.apache.druid.indexing.common.Counters.java
public double increment(String key, double val) { return doubleCounters.computeIfAbsent(key, k -> new AtomicDouble()).addAndGet(val); }
From source file:zipkin.finagle.ReporterMetricsAdapter.java
static AtomicDouble gaugeFor(StatsReceiver stats, String scope) { final AtomicDouble result = new AtomicDouble(); StatsReceivers.addGauge(stats, new Callable<Float>() { @Override/*from w w w . ja v a2 s . c o m*/ public Float call() throws Exception { return result.floatValue(); } }, scope); return result; }
From source file:io.watchcat.node.metrics.LoadAverage.java
public LoadAverage() { numberOfCoresPrimaryCommand = new ShellCommand("/bin/grep -c ^processor /proc/cpuinfo"); numberOfCoresSecondaryCommand = new ShellCommand("/usr/bin/nproc"); loadAverageCommand = new ShellCommand("/bin/cat /proc/loadavg | /usr/bin/awk '{print $1\",\"$2\",\"$3}'"); numberOfCpuCores = new AtomicReference<Integer>(); oneMinuteAverage = new AtomicDouble(); fiveMinuteAverage = new AtomicDouble(); fifteenMinuteAverage = new AtomicDouble(); run();/*from w w w . ja v a2s.c o m*/ }
From source file:de.blizzy.rust.lootconfig.LootConfigDump.java
private void run() throws IOException { LootConfig config = loadConfig(configFile); Table<LootContainer, Category, Multiset<Float>> dropChances = HashBasedTable.create(); Collection<LootContainer> lootContainers = config.LootContainers.values(); config.Categories.values().stream().filter(Category::hasItemsOrBlueprints).forEach(category -> { lootContainers.forEach(lootContainer -> { Multiset<Float> categoryInContainerDropChances = getItemCategoryDropChances(category, lootContainer);/*www. j av a 2s . c o m*/ if (!categoryInContainerDropChances.isEmpty()) { dropChances.put(lootContainer, category, categoryInContainerDropChances); } }); }); dropChances.rowKeySet().stream() .filter(lootContainer -> SHOW_DMLOOT || !lootContainer.name.contains("dmloot")) .sorted((lootContainer1, lootContainer2) -> Collator.getInstance().compare(lootContainer1.name, lootContainer2.name)) .forEach(lootContainer -> { System.out.printf("%s (blueprint fragments: %s)", lootContainer, lootContainer.DistributeFragments ? "yes" : "no").println(); Map<Category, Multiset<Float>> lootContainerDropChances = dropChances.row(lootContainer); AtomicDouble lootContainerDropChancesSum = new AtomicDouble(); AtomicInteger categoriesCount = new AtomicInteger(); lootContainerDropChances.entrySet().stream().sorted(this::compareByChances).limit(7) .forEach(categoryDropChancesEntry -> { Category category = categoryDropChancesEntry.getKey(); Multiset<Float> categoryDropChances = categoryDropChancesEntry.getValue(); float categoryDropChancesSum = sum(categoryDropChances); lootContainerDropChancesSum.addAndGet(categoryDropChancesSum); System.out.printf(" %s %s%s%s", formatPercent(categoryDropChancesSum), category, (category.Items.size() > 0) ? " (" + formatItems(category) + ")" : "", (category.Blueprints.size() > 0) ? " [" + formatBlueprints(category) + "]" : "") .println(); categoriesCount.incrementAndGet(); }); if (categoriesCount.get() < lootContainerDropChances.size()) { System.out.printf(" %s other (%d)", formatPercent(1f - (float) lootContainerDropChancesSum.get()), lootContainerDropChances.size() - categoriesCount.get()).println(); } }); }
From source file:edu.umich.si.inteco.minuku.streamgenerator.LocationStreamGenerator.java
public LocationStreamGenerator(Context applicationContext) { super(applicationContext); this.mStream = new LocationStream(Constants.LOCATION_QUEUE_SIZE); this.mDAO = MinukuDAOManager.getInstance().getDaoFor(LocationDataRecord.class); this.latitude = new AtomicDouble(); this.longitude = new AtomicDouble(); this.register(); }
From source file:de.craftolution.craftoplugin4.services.playerstorage.DatabaseStoredPlayer.java
DatabaseStoredPlayer(final int id, final UUID uniqueId) { this.id = id; this.uniqueId = uniqueId; this.playtime = new AtomicReference<>(); this.playtime.set(Duration.ZERO); this.money = new AtomicDouble(); this.muted = new AtomicBoolean(); this.frozen = new AtomicBoolean(); this.vanished = new AtomicBoolean(); }
From source file:org.apache.solr.cloud.autoscaling.SearchRateTrigger.java
@Override public void run() { AutoScaling.TriggerEventProcessor processor = processorRef.get(); if (processor == null) { return;/*from w w w .jav a2s . c om*/ } Map<String, Map<String, List<ReplicaInfo>>> collectionRates = new HashMap<>(); Map<String, AtomicDouble> nodeRates = new HashMap<>(); for (String node : cloudManager.getClusterStateProvider().getLiveNodes()) { Map<String, ReplicaInfo> metricTags = new HashMap<>(); // coll, shard, replica Map<String, Map<String, List<ReplicaInfo>>> infos = cloudManager.getNodeStateProvider() .getReplicaInfo(node, Collections.emptyList()); infos.forEach((coll, shards) -> { shards.forEach((sh, replicas) -> { replicas.forEach(replica -> { // we have to translate to the metrics registry name, which uses "_replica_nN" as suffix String replicaName = Utils.parseMetricsReplicaName(coll, replica.getCore()); if (replicaName == null) { // should never happen??? replicaName = replica.getName(); // which is actually coreNode name... } String registry = SolrCoreMetricManager.createRegistryName(true, coll, sh, replicaName, null); String tag = "metrics:" + registry + ":QUERY." + handler + ".requestTimes:1minRate"; metricTags.put(tag, replica); }); }); }); Map<String, Object> rates = cloudManager.getNodeStateProvider().getNodeValues(node, metricTags.keySet()); rates.forEach((tag, rate) -> { ReplicaInfo info = metricTags.get(tag); if (info == null) { log.warn("Missing replica info for response tag " + tag); } else { Map<String, List<ReplicaInfo>> perCollection = collectionRates .computeIfAbsent(info.getCollection(), s -> new HashMap<>()); List<ReplicaInfo> perShard = perCollection.computeIfAbsent(info.getShard(), s -> new ArrayList<>()); info.getVariables().put(AutoScalingParams.RATE, rate); perShard.add(info); AtomicDouble perNode = nodeRates.computeIfAbsent(node, s -> new AtomicDouble()); perNode.addAndGet((Double) rate); } }); } long now = timeSource.getTime(); // check for exceeded rates and filter out those with less than waitFor from previous events Map<String, Double> hotNodes = nodeRates.entrySet().stream() .filter(entry -> node.equals(Policy.ANY) || node.equals(entry.getKey())) .filter(entry -> waitForElapsed(entry.getKey(), now, lastNodeEvent)) .filter(entry -> entry.getValue().get() > rate) .collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue().get())); Map<String, Map<String, Double>> hotShards = new HashMap<>(); List<ReplicaInfo> hotReplicas = new ArrayList<>(); collectionRates.forEach((coll, shardRates) -> { shardRates.forEach((sh, replicaRates) -> { double shardRate = replicaRates.stream().map(r -> { if (waitForElapsed(r.getCollection() + "." + r.getCore(), now, lastReplicaEvent) && ((Double) r.getVariable(AutoScalingParams.RATE) > rate)) { hotReplicas.add(r); } return r; }).mapToDouble(r -> (Double) r.getVariable(AutoScalingParams.RATE)).sum(); if (waitForElapsed(coll + "." + sh, now, lastShardEvent) && (shardRate > rate) && (collection.equals(Policy.ANY) || collection.equals(coll)) && (shard.equals(Policy.ANY) || shard.equals(sh))) { hotShards.computeIfAbsent(coll, s -> new HashMap<>()).put(sh, shardRate); } }); }); Map<String, Double> hotCollections = new HashMap<>(); collectionRates.forEach((coll, shardRates) -> { double total = shardRates.entrySet().stream().mapToDouble(e -> e.getValue().stream() .mapToDouble(r -> (Double) r.getVariable(AutoScalingParams.RATE)).sum()).sum(); if (waitForElapsed(coll, now, lastCollectionEvent) && (total > rate) && (collection.equals(Policy.ANY) || collection.equals(coll))) { hotCollections.put(coll, total); } }); if (hotCollections.isEmpty() && hotShards.isEmpty() && hotReplicas.isEmpty() && hotNodes.isEmpty()) { return; } // generate event // find the earliest time when a condition was exceeded final AtomicLong eventTime = new AtomicLong(now); hotCollections.forEach((c, r) -> { long time = lastCollectionEvent.get(c); if (eventTime.get() > time) { eventTime.set(time); } }); hotShards.forEach((c, shards) -> { shards.forEach((s, r) -> { long time = lastShardEvent.get(c + "." + s); if (eventTime.get() > time) { eventTime.set(time); } }); }); hotReplicas.forEach(r -> { long time = lastReplicaEvent.get(r.getCollection() + "." + r.getCore()); if (eventTime.get() > time) { eventTime.set(time); } }); hotNodes.forEach((n, r) -> { long time = lastNodeEvent.get(n); if (eventTime.get() > time) { eventTime.set(time); } }); if (processor.process(new SearchRateEvent(getName(), eventTime.get(), hotNodes, hotCollections, hotShards, hotReplicas))) { // update lastEvent times hotNodes.keySet().forEach(node -> lastNodeEvent.put(node, now)); hotCollections.keySet().forEach(coll -> lastCollectionEvent.put(coll, now)); hotShards.entrySet().forEach( e -> e.getValue().forEach((sh, rate) -> lastShardEvent.put(e.getKey() + "." + sh, now))); hotReplicas.forEach(r -> lastReplicaEvent.put(r.getCollection() + "." + r.getCore(), now)); } }