Example usage for org.apache.commons.lang3.mutable MutableLong longValue

List of usage examples for org.apache.commons.lang3.mutable MutableLong longValue

Introduction

In this page you can find the example usage for org.apache.commons.lang3.mutable MutableLong longValue.

Prototype

@Override
public long longValue() 

Source Link

Document

Returns the value of this MutableLong as a long.

Usage

From source file:org.apache.hadoop.hbase.coprocessor.example.WriteHeavyIncrementObserver.java

private long getUniqueTimestamp(byte[] row) {
    int slot = Bytes.hashCode(row) & mask;
    MutableLong lastTimestamp = lastTimestamps[slot];
    long now = System.currentTimeMillis();
    synchronized (lastTimestamp) {
        long pt = lastTimestamp.longValue() >> 10;
        if (now > pt) {
            lastTimestamp.setValue(now << 10);
        } else {/*from w  w  w.  java  2 s  .  c  om*/
            lastTimestamp.increment();
        }
        return lastTimestamp.longValue();
    }
}

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

public boolean canPush(Entry entry, Cell firstCellInEdit) throws IOException {
    String encodedNameAsString = Bytes.toString(entry.getKey().getEncodedRegionName());
    long seqId = entry.getKey().getSequenceId();
    Long canReplicateUnderSeqId = canPushUnder.getIfPresent(encodedNameAsString);
    if (canReplicateUnderSeqId != null) {
        if (seqId < canReplicateUnderSeqId.longValue()) {
            LOG.trace("{} is before the end barrier {}, pass", entry, canReplicateUnderSeqId);
            return true;
        }/*from w  w  w . j  a va2 s .  co  m*/
        LOG.debug("{} is beyond the previous end barrier {}, remove from cache", entry, canReplicateUnderSeqId);
        // we are already beyond the last safe point, remove
        canPushUnder.invalidate(encodedNameAsString);
    }
    // This is for the case where the region is currently opened on us, if the sequence id is
    // continuous then we are safe to replicate. If there is a breakpoint, then maybe the region
    // has been moved to another RS and then back, so we need to check the barrier.
    MutableLong previousPushedSeqId = pushed.getUnchecked(encodedNameAsString);
    if (seqId == previousPushedSeqId.longValue() + 1) {
        LOG.trace("The sequence id for {} is continuous, pass", entry);
        previousPushedSeqId.increment();
        return true;
    }
    return canPush(entry, CellUtil.cloneRow(firstCellInEdit));
}

From source file:org.javersion.util.PersistentHashSetTest.java

@Test
public void split_till_the_end() {
    PersistentHashSet<Integer> ints = new PersistentHashSet<Integer>().conjAll(integers());
    List<Spliterator<Integer>> spliterators = new ArrayList<>();
    spliterators.add(ints.spliterator());
    int size = 0;
    while (size != spliterators.size()) {
        size = spliterators.size();//from   ww w .jav a  2  s .c  o  m
        for (int i = size - 1; i >= 0; i--) {
            Spliterator<Integer> spliterator = spliterators.get(i);
            Spliterator<Integer> split = spliterator.trySplit();
            if (split != null) {
                spliterators.add(split);
            }
        }
    }
    final MutableLong sum = new MutableLong(0);
    for (Spliterator<Integer> spliterator : spliterators) {
        while (spliterator.tryAdvance(i -> sum.add(i)))
            ;
    }
    Assertions.assertThat(sum.longValue()).isEqualTo(ints.stream().map(Long::new).reduce(Long::sum).get());
}

From source file:org.jbpm.event.process.ProcessEventSupportTest.java

@Test
public void testDefaultParentProcessIdValueInProcessEventListener() throws Exception {
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();

    // create a simple package with one process to test the events
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId("org.drools.core.process.event");
    process.setName("Event Process");

    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);/*  w ww. j  a va2 s. c  om*/
    process.addNode(startNode);

    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(3);
    process.addNode(endNode);

    new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);

    final InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.drools.test");
    pkg.addProcess(process);
    List<KiePackage> pkgs = new ArrayList<KiePackage>();
    pkgs.add(pkg);
    kbase.addPackages(pkgs);

    KieSession session = kbase.newKieSession();
    final MutableLong parentProcessId = new MutableLong(0L);
    final ProcessEventListener processEventListener = new DefaultProcessEventListener() {

        public void afterProcessStarted(ProcessStartedEvent event) {
            parentProcessId.setValue(event.getProcessInstance().getParentProcessInstanceId());
        }

    };
    session.addEventListener(processEventListener);

    // execute the process
    session.startProcess("org.drools.core.process.event");
    assertEquals(parentProcessId.longValue(), -1L);

}