Example usage for com.google.common.util.concurrent AtomicLongMap create

List of usage examples for com.google.common.util.concurrent AtomicLongMap create

Introduction

In this page you can find the example usage for com.google.common.util.concurrent AtomicLongMap create.

Prototype

public static <K> AtomicLongMap<K> create() 

Source Link

Document

Creates an AtomicLongMap .

Usage

From source file:core.MultiConcurrentLinkedPriorityQueueDRR.java

public MultiConcurrentLinkedPriorityQueueDRR(List<Integer> weights) {
    shutdown = false;// w w  w  . j  ava2 s .c  o  m
    qcount = weights.size();
    for (Integer x : weights)
        weightSum += x;
    this.weights = weights;
    r = new Random();
    queues = new ArrayList<ConcurrentLinkedQueue<E>>();
    DC = AtomicLongMap.create();
    for (int i = 0; i < qcount; i++) {
        queues.add(new ConcurrentLinkedQueue<E>());
        DC.put(i, 0);
    }

    Runnable runnable = new Runnable() {
        public void run() {
            while (!shutdown) {
                schedule();
            }
        }
    };
    scheduler = new Thread(runnable, "REQUEST-SCHEDULER");
    scheduler.start();
}

From source file:org.zenoss.app.consumer.metric.impl.MetricsQueue.java

MetricsQueue() {
    this.queue = new LinkedBlockingQueue<>();
    this.perClientBacklog = AtomicLongMap.create();
    this.totalErrorsMetric = Metrics.newCounter(errorsMetricName());
    this.totalInFlightMetric = Metrics.newCounter(inFlightMetricName());
    this.totalClientCountMetric = Metrics.newGauge(clientCountMetricName(), new Gauge<Long>() {
        @Override//w  ww . ja v  a 2  s .c  o  m
        public Long value() {
            return clientCount();
        }
    });
    this.totalIncomingMetric = registerIncoming();
    this.totalOutGoingMetric = registerOutgoing();
    this.totalReceivedMetric = registerReceived();
    this.totalRejectedMetric = registerRejected();
    this.totalLostMetric = registerLost();
    this.totalHighCollisionMetric = registerHighCollision();
    this.totalLowCollisionMetric = registerLowCollision();
    this.totalClientCollisionMetric = registerClientCollision();
    this.totalBroadcastHighCollisionMetric = registerBroadcastHighCollision();
    this.totalBroadcastLowCollisionMetric = registerBroadcastLowCollision();
    this.totalSentClientCollisionMetric = registerSentClientCollision();
    this.recentClientIds = CacheBuilder.newBuilder().expireAfterAccess(60, TimeUnit.SECONDS)
            .build(CacheLoader.from(YEPYEP));
}

From source file:ch.ethz.bsse.cf.utils.Utils.java

public static void parseBAM(String location) {
    File bam = new File(location);
    int size = 0;
    int length = 0;
    try (SAMFileReader sfr = new SAMFileReader(bam)) {
        AbstractBAMFileIndex index = (AbstractBAMFileIndex) sfr.getIndex();
        int nRefs = index.getNumberOfReferences();
        for (int i = 0; i < nRefs; i++) {
            BAMIndexMetaData meta = index.getMetaData(i);
            size += meta.getAlignedRecordCount();
            if (length < sfr.getFileHeader().getSequence(i).getSequenceLength()) {
                length = sfr.getFileHeader().getSequence(i).getSequenceLength();
            }//from  ww w  .ja  va 2  s . c  o m
        }
    }
    for (int i = 0; i < length; i++) {
        Globals.DELETION_MAP.put(i, AtomicLongMap.create());
    }
    StatusUpdate.getINSTANCE().printForce("Read count\t\t" + size);
    try (SAMFileReader sfr = new SAMFileReader(bam)) {
        if (Globals.SINGLE_CORE) {
            StatusUpdate.getINSTANCE().println("Computing\t\t");
            int i = 0;
            for (SAMRecord r : sfr) {
                if (i++ % 1000 == 0) {
                    StatusUpdate.getINSTANCE()
                            .print("Computing\t\t" + Math.round(((double) i * 100) / size) + "%");
                }
                SFRComputing.single(r);
            }
            StatusUpdate.getINSTANCE().printForce("Computing\t\t100%");
        } else {
            StatusUpdate.getINSTANCE().println("Loading BAM");

            List<List<SAMRecord>> records = new LinkedList();
            List<SAMRecord> tmp = new LinkedList<>();
            SAMRecordIterator it = sfr.iterator();
            for (int x = 0, y = 0; x < size; x += STEP_SIZE) {
                records.clear();
                tmp.clear();
                y = x + STEP_SIZE < size ? x + STEP_SIZE : size - 1;
                StatusUpdate.getINSTANCE()
                        .print("Loading BAM\t\t" + Math.round(((double) y * 100) / size) + "%");
                final int max = y - x < 100 ? 100
                        : (int) Math.ceil((y - x) / Runtime.getRuntime().availableProcessors());
                int c = 0;
                do {
                    if (++c % max == 0) {
                        records.add(tmp);
                        tmp = new LinkedList<>();
                    }
                    if (it.hasNext()) {
                        tmp.add(it.next());
                    } else {
                        records.add(tmp);
                        break;
                    }
                } while (c < y - x);
                records.add(tmp);
                Parallel.ForEach(records, new LoopBody<List<SAMRecord>>() {
                    @Override
                    public void run(List<SAMRecord> l) {

                        for (SAMRecord r : l) {
                            SFRComputing.single(r);
                        }
                    }
                });
            }
            StatusUpdate.getINSTANCE().printForce("Loading BAM\t\t100%\n");
        }
    }
}

From source file:org.elasticsearch.action.termvectors.TermVectorsFilter.java

public TermVectorsFilter(Fields termVectorsByField, Fields topLevelFields, Set<String> selectedFields,
        @Nullable AggregatedDfs dfs) {//from  ww  w .  j av  a 2s. c om
    this.fields = termVectorsByField;
    this.topLevelFields = topLevelFields;
    this.selectedFields = selectedFields;

    this.dfs = dfs;
    this.scoreTerms = new HashMap<>();
    this.sizes = AtomicLongMap.create();
    this.similarity = new DefaultSimilarity();
}

From source file:org.apache.hadoop.hbase.replication.regionserver.DumpReplicationQueues.java

public DumpReplicationQueues() {
    deadRegionServers = new ArrayList<String>();
    deletedQueues = new ArrayList<String>();
    peersQueueSize = AtomicLongMap.create();
    totalSizeOfWALs = 0;/* w  ww  .  j ava2s .c  om*/
    numWalsNotFound = 0;
}

From source file:ch.ethz.bsse.cf.utils.SFRComputing.java

public static void add(int position, byte base, Map<Integer, AtomicLongMap> alignmentMap) {
    try {//from w  ww.  java2  s  .c  o m
        if (!alignmentMap.containsKey(position)) {
            alignmentMap.put(position, AtomicLongMap.create());
        }
        alignmentMap.get(position).incrementAndGet(base);
    } catch (IllegalArgumentException e) {
        System.out.println(e);
    }
}

From source file:com.cloudera.oryx.app.mllib.rdf.RDFUpdate.java

/**
 * @param trainPointData data to run down trees
 * @param model random decision forest model to count on
 * @return map of predictor index to the number of training examples that reached a
 *  node whose decision is based on that feature. The index is among predictors, not all
 *  features, since there are fewer predictors than features. That is, the index will
 *  match the one used in the {@link RandomForestModel}.
 *//*from  w w w .j  a  va 2 s.c om*/
private static Map<Integer, Long> predictorExampleCounts(JavaRDD<LabeledPoint> trainPointData,
        final RandomForestModel model) {
    return trainPointData.mapPartitions(new FlatMapFunction<Iterator<LabeledPoint>, AtomicLongMap<Integer>>() {
        @Override
        public Iterable<AtomicLongMap<Integer>> call(Iterator<LabeledPoint> data) {
            AtomicLongMap<Integer> featureIndexCount = AtomicLongMap.create();
            while (data.hasNext()) {
                LabeledPoint datum = data.next();
                double[] featureVector = datum.features().toArray();
                for (DecisionTreeModel tree : model.trees()) {
                    org.apache.spark.mllib.tree.model.Node node = tree.topNode();
                    // This logic cloned from Node.predict:
                    while (!node.isLeaf()) {
                        Split split = node.split().get();
                        int featureIndex = split.feature();
                        // Count feature
                        featureIndexCount.incrementAndGet(featureIndex);
                        node = nextNode(featureVector, node, split, featureIndex);
                    }
                }
            }
            return Collections.singleton(featureIndexCount);
        }
    }).reduce(new Function2<AtomicLongMap<Integer>, AtomicLongMap<Integer>, AtomicLongMap<Integer>>() {
        @Override
        public AtomicLongMap<Integer> call(AtomicLongMap<Integer> a, AtomicLongMap<Integer> b) {
            return merge(a, b);
        }
    }).asMap();
}

From source file:org.mondemand.Client.java

/**
 * Given context&Stats map, increment according to context and key/value
 * @param context context// ww  w  .  java 2s .  c  o  m
 * @param keyType key
 * @param value value
 * @throws MondemandException
 */
public void increment(ContextList context, String keyType, long value) throws MondemandException {
    if (!isKeyValid(keyType)) {
        throw new MondemandException("key is invalid: " + keyType);
    }

    // Note: add could be lost due to a race condition but no
    //       synchronization is required.
    AtomicLongMap<String> stats = contextStats.get(context);
    if (stats == null) {
        AtomicLongMap<String> newStats = AtomicLongMap.create();
        stats = contextStats.putIfAbsent(context, newStats);
        if (stats == null) {
            stats = newStats;
        }
    }
    stats.addAndGet(keyType, value);
}