Search in sources :

Example 16 with IgniteAtomicSequence

use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.

the class GridCachePartitionedAtomicSequenceMultiThreadedTest method testMixed1.

/** @throws Exception If failed. */
public void testMixed1() throws Exception {
    // Random sequence names.
    String seqName = UUID.randomUUID().toString();
    final IgniteAtomicSequence seq = grid(0).atomicSequence(seqName, 0L, true);
    runSequenceClosure(new GridInUnsafeClosure<IgniteAtomicSequence>() {

        @Override
        public void apply(IgniteAtomicSequence t) {
            t.incrementAndGet();
            t.getAndIncrement();
            t.incrementAndGet();
            t.getAndIncrement();
            t.getAndAdd(3);
            t.addAndGet(3);
        }
    }, seq, ITERATION_NUM, THREAD_NUM);
    assertEquals(10 * ITERATION_NUM * THREAD_NUM, seq.get());
}
Also used : IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence)

Example 17 with IgniteAtomicSequence

use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.

the class GridCachePartitionedAtomicSequenceMultiThreadedTest method testGetAndAdd.

/** @throws Exception If failed. */
public void testGetAndAdd() throws Exception {
    // Random sequence names.
    String seqName = UUID.randomUUID().toString();
    final IgniteAtomicSequence seq = grid(0).atomicSequence(seqName, 0L, true);
    runSequenceClosure(new GridInUnsafeClosure<IgniteAtomicSequence>() {

        @Override
        public void apply(IgniteAtomicSequence t) {
            t.getAndAdd(5);
        }
    }, seq, ITERATION_NUM, THREAD_NUM);
    assertEquals(5 * ITERATION_NUM * THREAD_NUM, seq.get());
}
Also used : IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence)

Example 18 with IgniteAtomicSequence

use of org.apache.ignite.IgniteAtomicSequence in project camel by apache.

the class IgniteIdGenEndpoint method createProducer.

@Override
public Producer createProducer() throws Exception {
    IgniteAtomicSequence atomicSeq = ignite().atomicSequence(name, initialValue, false);
    if (atomicSeq == null) {
        atomicSeq = ignite().atomicSequence(name, initialValue, true);
        LOG.info("Created AtomicSequence of ID Generator with name {}.", name);
    }
    if (batchSize != null) {
        atomicSeq.batchSize(batchSize);
    }
    return new IgniteIdGenProducer(this, atomicSeq);
}
Also used : IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence)

Example 19 with IgniteAtomicSequence

use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.

the class GridCacheMultiNodeDataStructureTest method sample.

/**
     *
     * @param g Grid.
     * @param cacheName Cache name.
     */
private static void sample(Ignite g, String cacheName) {
    IgniteAtomicLong atomicLong = g.atomicLong("keygen", 0, true);
    IgniteAtomicSequence seq = g.atomicSequence("keygen", 0, true);
    seq.incrementAndGet();
    seq.incrementAndGet();
    seq.incrementAndGet();
    seq.incrementAndGet();
    atomicLong.incrementAndGet();
    atomicLong.incrementAndGet();
    atomicLong.incrementAndGet();
    X.println(cacheName + ": Seq: " + seq.get() + " atomicLong " + atomicLong.get());
}
Also used : IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence)

Example 20 with IgniteAtomicSequence

use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.

the class GridCacheSequenceApiSelfAbstractTest method testPrepareSequence.

/**
     * @throws Exception If failed.
     */
public void testPrepareSequence() throws Exception {
    // Random sequence names.
    String locSeqName1 = UUID.randomUUID().toString();
    String locSeqName2 = UUID.randomUUID().toString();
    IgniteAtomicSequence locSeq1 = grid().atomicSequence(locSeqName1, 0, true);
    IgniteAtomicSequence locSeq2 = grid().atomicSequence(locSeqName2, 0, true);
    IgniteAtomicSequence locSeq3 = grid().atomicSequence(locSeqName1, 0, true);
    assertNotNull(locSeq1);
    assertNotNull(locSeq2);
    assertNotNull(locSeq3);
    assert locSeq1.equals(locSeq3);
    assert locSeq3.equals(locSeq1);
    assert !locSeq3.equals(locSeq2);
    removeSequence(locSeqName1);
    removeSequence(locSeqName2);
}
Also used : IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence)

Aggregations

IgniteAtomicSequence (org.apache.ignite.IgniteAtomicSequence)33 Ignite (org.apache.ignite.Ignite)8 IgniteAtomicLong (org.apache.ignite.IgniteAtomicLong)3 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)3 IgniteCountDownLatch (org.apache.ignite.IgniteCountDownLatch)2 IgniteException (org.apache.ignite.IgniteException)2 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 Callable (java.util.concurrent.Callable)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteAtomicReference (org.apache.ignite.IgniteAtomicReference)1 IgniteAtomicStamped (org.apache.ignite.IgniteAtomicStamped)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)1 IgniteLock (org.apache.ignite.IgniteLock)1