Java Code Examples for java.util.concurrent.atomic.AtomicLong.getAndIncrement()

The following are Jave code examples for showing how to use getAndIncrement() of the java.util.concurrent.atomic.AtomicLong class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DBus   File: PagedBatchDataFetchingBolt.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
private void sendMessageToKafka(String key, DbusMessage dbusMessage, AtomicLong sendCnt, AtomicLong recvCnt, AtomicBoolean isError) throws Exception{
    if(stringProducer == null) {
        throw new Exception("producer is null, can't send to kafka!");
    }

    ProducerRecord record = new ProducerRecord<>(resultTopic, key, dbusMessage.toString());
    sendCnt.getAndIncrement();
    stringProducer.send(record, new Callback() {
        public void onCompletion(RecordMetadata metadata, Exception e) {
            if (e != null) {
                e.printStackTrace();
                isError.set(true);
            }else{
                recvCnt.getAndIncrement();
            }
        }
    });
}
 
Example 2
Project: RxJava3-preview   File: QueueDrainHelperTest.java   View Source Code Vote up 6 votes
@Test
public void postCompleteWithRequest() {
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
    AtomicLong state = new AtomicLong();
    BooleanSupplier isCancelled = new BooleanSupplier() {
        @Override
        public boolean getAsBoolean() throws Exception {
            return false;
        }
    };

    ts.onSubscribe(new BooleanSubscription());
    queue.offer(1);
    state.getAndIncrement();

    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);

    ts.assertResult(1);
}
 
Example 3
Project: RxJava3-preview   File: QueueDrainHelperTest.java   View Source Code Vote up 6 votes
@Test
public void postCompleteCancelled() {
    final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
    AtomicLong state = new AtomicLong();
    BooleanSupplier isCancelled = new BooleanSupplier() {
        @Override
        public boolean getAsBoolean() throws Exception {
            return ts.isCancelled();
        }
    };

    ts.onSubscribe(new BooleanSubscription());
    queue.offer(1);
    state.getAndIncrement();
    ts.cancel();

    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);

    ts.assertEmpty();
}
 
Example 4
Project: RxJava3-preview   File: QueueDrainHelperTest.java   View Source Code Vote up 6 votes
@Test
public void postCompleteCancelledAfterOne() {
    final TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            cancel();
        }
    };
    ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
    AtomicLong state = new AtomicLong();
    BooleanSupplier isCancelled = new BooleanSupplier() {
        @Override
        public boolean getAsBoolean() throws Exception {
            return ts.isCancelled();
        }
    };

    ts.onSubscribe(new BooleanSubscription());
    queue.offer(1);
    state.getAndIncrement();

    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);

    ts.assertValue(1).assertNoErrors().assertNotComplete();
}
 
Example 5
Project: boohee_v5.6   File: OnSubscribeCombineLatest.java   View Source Code Vote up 6 votes
void tick() {
    AtomicLong localCounter = this.counter;
    if (localCounter.getAndIncrement() == 0) {
        int emitted = 0;
        do {
            if (this.requested.get() > 0) {
                Object o = this.buffer.poll();
                if (o != null) {
                    if (this.buffer.isCompleted(o)) {
                        this.child.onCompleted();
                    } else {
                        this.buffer.accept(o, this.child);
                        emitted++;
                        this.requested.decrementAndGet();
                    }
                }
            }
        } while (localCounter.decrementAndGet() > 0);
        if (emitted > 0) {
            for (MultiSourceRequestableSubscriber<T, R> s : this.subscribers) {
                s.requestUpTo((long) emitted);
            }
        }
    }
}
 
Example 6
Project: monarch   File: AbstractTierStoreWriter.java   View Source Code Vote up 5 votes
/**
 * Get the next sequence number for the specified path that includes: table-name, partition/bucket
 * id, time-partition-id
 *
 * @param path the unique path against which the sequence id is maintained
 * @return the next available sequence id
 */
protected long getNextSeqNo(final String path) {
  synchronized (bucketSeqNoMap) {
    AtomicLong mapValue = bucketSeqNoMap.get(path);
    if (mapValue != null) {
      return mapValue.getAndIncrement();
    }
    bucketSeqNoMap.put(path, new AtomicLong(1));
    return 0;
  }
}
 
Example 7
Project: monarch   File: ORCExternalStoreWriter.java   View Source Code Vote up 5 votes
/**
 * Get the next sequence number for the specified path that includes: table-name, partition/bucket
 * id, time-partition-id
 *
 * @param path the unique path against which the sequence id is maintained
 * @return the next available sequence id
 */
public long getNextSeqNo(final String path) {
  synchronized (bucketSeqNoMap) {
    AtomicLong mapValue = bucketSeqNoMap.get(path);
    if (mapValue != null) {
      return mapValue.getAndIncrement();
    }
    bucketSeqNoMap.put(path, new AtomicLong(1));
    return 0;
  }
}
 
Example 8
Project: monarch   File: WriteAheadLog.java   View Source Code Vote up 5 votes
/**
 * Get next sequence number
 * 
 * @return next sequence number.
 */
public long getNextSeqNo(String tableName, int partitionId) {
  synchronized (bucketSeqNoMap) {
    AtomicLong mapValue = bucketSeqNoMap.get(tableName + "_" + partitionId);
    if (mapValue != null) {
      return mapValue.getAndIncrement();
    }
    bucketSeqNoMap.put(tableName + "_" + partitionId, new AtomicLong(1));
    return 0;
  }
}
 
Example 9
Project: jdk8u-jdk   File: LongAdderDemo.java   View Source Code Vote up 5 votes
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    AtomicLong a = adder;
    for (int i = 0; i < incs; ++i)
        a.getAndIncrement();
    result = a.get();
    phaser.arrive();
}
 
Example 10
Project: openjdk-jdk10   File: LongAdderDemo.java   View Source Code Vote up 5 votes
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    AtomicLong a = adder;
    for (int i = 0; i < incs; ++i)
        a.getAndIncrement();
    result = a.get();
    phaser.arrive();
}