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

The following examples show how to use java.util.concurrent.atomic.AtomicLong#getAndIncrement() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hazelcast-simulator   File: Registry.java    License: Apache License 2.0 6 votes vote down vote up
public synchronized List<TestData> addTests(TestSuite testSuite) {
    List<TestData> result = new ArrayList<>(testSuite.size());
    for (TestCase testCase : testSuite.getTestCaseList()) {
        String id = testCase.getId();
        AtomicLong count = ids.get(id);
        if (count == null) {
            ids.put(id, new AtomicLong(1));
        } else {
            id = id + "__" + count.getAndIncrement();
        }
        int testIndex = testIndexGenerator.incrementAndGet();
        testCase.setId(id);

        TestData test = new TestData(testIndex, testCase, testSuite);
        result.add(test);
        tests.put(id, test);
    }
    return result;
}
 
Example 2
Source Project: DBus   File: PullHandler.java    License: Apache License 2.0 6 votes vote down vote up
public void sendMessageToKafka(String resultTopic, 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, (metadata, e) -> {
        if (e != null) {
            logger.error("Send Message to kafka exception!", e);
            isError.set(true);
        } else {
            recvCnt.getAndIncrement();
        }
    });
}
 
Example 3
Source Project: mewbase   File: HBaseEventSink.java    License: MIT License 6 votes vote down vote up
@Override
public Long publishSync(String channelName, BsonObject event) {
    try {
        final Table table = ensureTable(channelName);
        final AtomicLong l = seqNums.computeIfAbsent(channelName, s -> new AtomicLong());
        final Put put = new Put( Bytes.toBytes( l.get() ) );
        final byte [] bytes = BsonCodec.bsonObjectToBsonBytes(event);
        put.addColumn(colFamily,qualifier,bytes);
        table.put(put);
        return l.getAndIncrement();
    } catch (Exception exp) {
        log.error("Failed to publish event",exp);
        return EventSink.SADLY_NO_CONCEPT_OF_A_MESSAGE_NUMBER;
    }

}
 
Example 4
@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 5
@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 6
@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 7
Source Project: nifi   File: UpdateRowsWriter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates and transfers a new flow file whose contents are the JSON-serialized value of the specified event, and the sequence ID attribute set
 *
 * @param session   A reference to a ProcessSession from which the flow file(s) will be created and transferred
 * @param eventInfo An event whose value will become the contents of the flow file
 * @return The next available CDC sequence ID for use by the CDC processor
 */
@Override
public long writeEvent(final ProcessSession session, String transitUri, final UpdateRowsEventInfo eventInfo, final long currentSequenceId, Relationship relationship) {
    final AtomicLong seqId = new AtomicLong(currentSequenceId);
    for (Map.Entry<Serializable[], Serializable[]> row : eventInfo.getRows()) {

        FlowFile flowFile = session.create();
        flowFile = session.write(flowFile, outputStream -> {

            super.startJson(outputStream, eventInfo);
            super.writeJson(eventInfo);

            final BitSet bitSet = eventInfo.getIncludedColumns();
            writeRow(eventInfo, row, bitSet);

            super.endJson();
        });

        flowFile = session.putAllAttributes(flowFile, getCommonAttributes(seqId.get(), eventInfo));
        session.transfer(flowFile, relationship);
        session.getProvenanceReporter().receive(flowFile, transitUri);
        seqId.getAndIncrement();
    }
    return seqId.get();
}
 
Example 8
Source Project: nifi   File: DeleteRowsWriter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates and transfers a new flow file whose contents are the JSON-serialized value of the specified event, and the sequence ID attribute set
 *
 * @param session   A reference to a ProcessSession from which the flow file(s) will be created and transferred
 * @param eventInfo An event whose value will become the contents of the flow file
 * @return The next available CDC sequence ID for use by the CDC processor
 */
@Override
public long writeEvent(final ProcessSession session, String transitUri, final DeleteRowsEventInfo eventInfo, final long currentSequenceId, Relationship relationship) {
    final AtomicLong seqId = new AtomicLong(currentSequenceId);
    for (Serializable[] row : eventInfo.getRows()) {

        FlowFile flowFile = session.create();
        flowFile = session.write(flowFile, outputStream -> {

            super.startJson(outputStream, eventInfo);
            super.writeJson(eventInfo);

            final BitSet bitSet = eventInfo.getIncludedColumns();
            writeRow(eventInfo, row, bitSet);

            super.endJson();
        });

        flowFile = session.putAllAttributes(flowFile, getCommonAttributes(seqId.get(), eventInfo));
        session.transfer(flowFile, relationship);
        session.getProvenanceReporter().receive(flowFile, transitUri);
        seqId.getAndIncrement();
    }
    return seqId.get();
}
 
Example 9
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
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 11
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 12
Source Project: light-4j   File: MockConsulClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void checkPass(String serviceid, String token) {
    AtomicLong times = checkPassTimesMap.get(serviceid);
    if (times == null) {
        checkPassTimesMap.putIfAbsent(serviceid, new AtomicLong());
        times = checkPassTimesMap.get(serviceid);
    }
    times.getAndIncrement();

    serviceStatus.put(serviceid, true);
}
 
Example 13
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 14
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 15
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 16
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 17
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 18
Source Project: grpc-java   File: LoadStatsStoreImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void recordDroppedRequest(String category) {
  AtomicLong counter = dropCounters.get(category);
  if (counter == null) {
    counter = dropCounters.putIfAbsent(category, new AtomicLong());
    if (counter == null) {
      counter = dropCounters.get(category);
    }
  }
  counter.getAndIncrement();
}
 
Example 19
Source Project: datawave   File: SpringCDIExtension.java    License: Apache License 2.0 4 votes vote down vote up
protected String generateName() {
    AtomicLong counter = nameMap.putIfAbsent(targetType, new AtomicLong(0L));
    if (counter == null)
        counter = nameMap.get(targetType);
    return targetType + "#" + counter.getAndIncrement();
}
 
Example 20
Source Project: bazel-buildfarm   File: Extract.java    License: Apache License 2.0 4 votes vote down vote up
static void downloadActionContents(
    Path root, String instanceName, Set<Digest> actionDigests, Channel channel)
    throws IOException, InterruptedException {
  ByteStreamStub bsStub = ByteStreamGrpc.newStub(channel);

  ExecutorService service = newSingleThreadExecutor();
  ListeningScheduledExecutorService retryService =
      listeningDecorator(newSingleThreadScheduledExecutor());

  Set<Digest> visitedDigests = Sets.newHashSet();
  Set<Digest> visitedDirectories = Sets.newHashSet();

  AtomicLong outstandingOperations = new AtomicLong(0);

  for (Digest actionDigest : actionDigests) {
    ByteString content = getBlobIntoFile("action", instanceName, actionDigest, bsStub, root);
    Action action = Action.parseFrom(content);
    Digest commandDigest = action.getCommandDigest();
    if (!visitedDigests.contains(commandDigest)) {
      visitedDigests.add(commandDigest);
      outstandingOperations.getAndIncrement();
      service.execute(
          blobGetter(
              root, instanceName, commandDigest, bsStub, outstandingOperations, retryService));
    }
    Digest inputRootDigest = action.getInputRootDigest();
    if (!visitedDigests.contains(inputRootDigest)) {
      visitedDirectories.add(inputRootDigest);
      visitedDigests.add(inputRootDigest);
      outstandingOperations.getAndIncrement();
      service.execute(
          directoryGetter(
              root,
              instanceName,
              inputRootDigest,
              visitedDirectories,
              visitedDigests,
              bsStub,
              service,
              outstandingOperations,
              retryService));
    }
  }

  while (outstandingOperations.get() > 0) {
    System.out.println("Waiting on " + outstandingOperations.get() + " operations");
    TimeUnit.SECONDS.sleep(5);
  }

  service.shutdown();
  service.awaitTermination(1, TimeUnit.MINUTES);
  retryService.shutdown();
  retryService.awaitTermination(1, TimeUnit.MINUTES);
}