Example usage for java.util.concurrent.atomic AtomicLong get

List of usage examples for java.util.concurrent.atomic AtomicLong get

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicLong get.

Prototype

public final long get() 

Source Link

Document

Returns the current value, with memory effects as specified by VarHandle#getVolatile .

Usage

From source file:org.apache.activemq.store.kahadb.KahaDBMessageStoreSizeStatTest.java

/**
 * Test that the the counter restores size and works after restart and more
 * messages are published/* ww w. ja  v  a 2  s  .  c  o m*/
 *
 * @throws Exception
 */
@Test(timeout = 60000)
public void testMessageSizeAfterRestartAndPublish() throws Exception {
    AtomicLong publishedMessageSize = new AtomicLong();
    Destination dest = publishTestQueueMessages(200, publishedMessageSize);

    // verify the count and size
    verifyStats(dest, 200, publishedMessageSize.get());

    // stop, restart broker and publish more messages
    stopBroker();
    this.setUpBroker(false);
    dest = publishTestQueueMessages(200, publishedMessageSize);

    // verify the count and size
    verifyStats(dest, 400, publishedMessageSize.get());

}

From source file:nl.knaw.huc.di.tag.model.graph.DotFactory.java

public String toDot(TAGDocument document, final String label) {
    layerColor.clear();//from  w w w. j a  va2s.c  om
    StringBuilder dotBuilder = new StringBuilder("digraph TextGraph{\n")
            .append("  node [font=\"helvetica\";style=\"filled\";fillcolor=\"white\"]\n")
            .append("  d [shape=doublecircle;label=\"\"]\n").append("  subgraph{\n");
    document.getTextNodeStream().map(this::toTextNodeLine).forEach(dotBuilder::append);

    dotBuilder.append("    rank=same\n");

    textGraph = document.getDTO().textGraph;
    AtomicLong prevNode = new AtomicLong(-1);
    textGraph.getTextNodeIdStream().forEach(id -> {
        if (prevNode.get() != -1) {
            dotBuilder.append(toNextEdgeLine(prevNode.get(), id));
        }
        prevNode.set(id);
    });

    dotBuilder.append("  }\n");

    document.getMarkupStream().map(this::toMarkupNodeLine).forEach(dotBuilder::append);

    document.getMarkupStream().map(this::toMarkupContinuationLine).forEach(dotBuilder::append);

    document.getMarkupStream().map(TAGMarkup::getDbId)
            .flatMap(id -> textGraph.getOutgoingEdges(id).stream().filter(LayerEdge.class::isInstance)
                    .map(LayerEdge.class::cast))
            .map(e -> toOutgoingEdgeLine(e, textGraph)).forEach(dotBuilder::append);

    textGraph.getOutgoingEdges(textGraph.documentNode).stream().flatMap(e -> textGraph.getTargets(e).stream())
            .map(root -> "  d->m" + root + " [arrowhead=none]\n").forEach(dotBuilder::append);

    String graphLabel = escape(label);
    if (!graphLabel.isEmpty()) {
        dotBuilder.append("  label=<<font color=\"brown\" point-size=\"8\"><i>").append(graphLabel)
                .append("</i></font>>\n");
    }

    dotBuilder.append("}");
    return dotBuilder.toString();
}

From source file:org.mycore.common.xml.MCRXMLFunctions.java

/**
 * Method returns the amount of space consumed by the files contained in the
 * derivate container. The returned string is already formatted meaning it
 * has already the optimal measurement unit attached (e.g. 142 MB, ).
 *
 * @param derivateId/*from   ww  w  . java  2s  .  co  m*/
 *            the derivate id for which the size should be returned
 * @return the size as formatted string
 */
public static String getSize(String derivateId) throws IOException {
    MCRPath rootPath = MCRPath.getPath(derivateId, "/");
    final AtomicLong size = new AtomicLong();
    Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            size.addAndGet(attrs.size());
            return super.visitFile(file, attrs);
        }

    });
    return MCRUtils.getSizeFormatted(size.get());
}

From source file:org.mule.module.pgp.DecryptStreamTransformer.java

/**
 * {@inheritDoc}//from ww w . ja v a2 s  . com
 */
public boolean write(OutputStream out, AtomicLong bytesRequested) throws Exception {
    int len = 0;
    byte[] buf = new byte[1 << 16];
    boolean wroteSomething = false;

    while (bytesRequested.get() + offset > bytesWrote && (len = uncStream.read(buf)) > 0) {
        out.write(buf, 0, len);
        bytesWrote = bytesWrote + len;
        wroteSomething = true;
    }

    if (wroteSomething && len <= 0) {
        uncStream.close();
        if (compressedStream != null) {
            compressedStream.close();
        }
        clearStream.close();
        return true;
    }

    return false;
}

From source file:org.apache.activemq.store.kahadb.MultiKahaDBMessageStoreSizeStatTest.java

/**
 * Test that the the counter restores size and works after restart and more
 * messages are published//from   w w  w  .  j a v  a  2 s. c om
 *
 * @throws Exception
 */
@Test(timeout = 60000)
public void testMessageSizeAfterRestartAndPublish() throws Exception {
    AtomicLong publishedMessageSize = new AtomicLong();

    Destination dest = publishTestQueueMessages(200, publishedMessageSize);

    // verify the count and size
    verifyStats(dest, 200, publishedMessageSize.get());

    // stop, restart broker and publish more messages
    stopBroker();
    this.setUpBroker(false);
    dest = publishTestQueueMessages(200, publishedMessageSize);

    // verify the count and size
    verifyStats(dest, 400, publishedMessageSize.get());

}

From source file:org.apache.bookkeeper.common.util.TestBackoff.java

@Test
public void testDecorrelatedJittered() throws Exception {
    long startMs = ThreadLocalRandom.current().nextLong(1L, 1000L);
    long maxMs = ThreadLocalRandom.current().nextLong(startMs, startMs * 2);
    Stream<Long> backoffs = Backoff.decorrelatedJittered(startMs, maxMs).limit(10);
    Iterator<Long> backoffIter = backoffs.iterator();
    assertTrue(backoffIter.hasNext());//w ww .  j  a  v  a  2  s . co  m
    assertEquals(startMs, backoffIter.next().longValue());
    AtomicLong prevMs = new AtomicLong(startMs);
    backoffIter.forEachRemaining(backoffMs -> {
        assertTrue(backoffMs >= startMs);
        assertTrue(backoffMs <= prevMs.get() * 3);
        assertTrue(backoffMs <= maxMs);
        prevMs.set(backoffMs);
    });
}

From source file:org.apache.bookkeeper.common.util.TestBackoff.java

@Test
public void testDecorrelatedJitteredPolicy() throws Exception {
    long startMs = ThreadLocalRandom.current().nextLong(1L, 1000L);
    long maxMs = ThreadLocalRandom.current().nextLong(startMs, startMs * 2);
    Stream<Long> backoffs = Backoff.Jitter.of(DECORRELATED, startMs, maxMs, 10).toBackoffs();
    Iterator<Long> backoffIter = backoffs.iterator();
    assertTrue(backoffIter.hasNext());//  ww w.  j  ava 2  s  .c o  m
    assertEquals(startMs, backoffIter.next().longValue());
    AtomicLong prevMs = new AtomicLong(startMs);
    backoffIter.forEachRemaining(backoffMs -> {
        assertTrue(backoffMs >= startMs);
        assertTrue(backoffMs <= prevMs.get() * 3);
        assertTrue(backoffMs <= maxMs);
        prevMs.set(backoffMs);
    });
}

From source file:com.aol.advertising.qiao.management.metrics.StatisticsStore.java

@Override
@ManagedOperation(description = "Get the specific metric")
@ManagedOperationParameters({//from   w  ww  .ja  va  2s  . co m
        @ManagedOperationParameter(name = "Metric identifier", description = "The type of metric for value retrieval, e.g. input, output, processed, etc.") })
public long getMetric(String key) {
    AtomicLong v = stats.get(key);
    if (v == null)
        return 0;

    return v.get();
}

From source file:com.mirth.connect.donkey.server.channel.Statistics.java

public boolean isEmpty() {
    if (!stats.isEmpty()) {
        for (Map<Integer, Map<Status, AtomicLong>> channelMap : stats.values()) {
            for (Map<Status, AtomicLong> statusMap : channelMap.values()) {
                for (AtomicLong diff : statusMap.values()) {
                    if (diff.get() != 0) {
                        return false;
                    }//from w  ww.  j  av a2  s.  c o m
                }
            }
        }
    }

    return true;
}

From source file:com.taobao.adfs.util.Utilities.java

public static void greaterAndSet(long value, AtomicLong atomicValue) {
    synchronized (atomicValue) {
        if (value > atomicValue.get())
            atomicValue.set(value);/* w w  w  .ja v a  2s  . c om*/
    }
}