Search in sources :

Example 1 with DistributedAtomicLong

use of org.apache.curator.framework.recipes.atomic.DistributedAtomicLong in project vespa by vespa-engine.

the class CuratorCounterTest method testCounter.

@Test
public void testCounter() throws Exception {
    DistributedAtomicLong counter = new MockCurator().createAtomicCounter("/mycounter");
    counter.initialize(4l);
    assertEquals(4l, counter.get().postValue().longValue());
    assertEquals(5l, counter.increment().postValue().longValue());
}
Also used : DistributedAtomicLong(org.apache.curator.framework.recipes.atomic.DistributedAtomicLong) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Test(org.junit.Test)

Example 2 with DistributedAtomicLong

use of org.apache.curator.framework.recipes.atomic.DistributedAtomicLong in project oozie by apache.

the class ZKUUIDService method init.

@Override
public void init(Services services) throws ServiceException {
    super.init(services);
    try {
        zk = ZKUtils.register(this);
        PromotedToLock.Builder lockBuilder = PromotedToLock.builder().lockPath(getPromotedLock()).retryPolicy(getRetryPolicy()).timeout(Service.lockTimeout, TimeUnit.MILLISECONDS);
        atomicIdGenerator = new DistributedAtomicLong(zk.getClient(), ZK_SEQUENCE_PATH, getRetryPolicy(), lockBuilder.build());
    } catch (Exception ex) {
        throw new ServiceException(ErrorCode.E1700, ex.getMessage(), ex);
    }
}
Also used : DistributedAtomicLong(org.apache.curator.framework.recipes.atomic.DistributedAtomicLong) PromotedToLock(org.apache.curator.framework.recipes.atomic.PromotedToLock)

Aggregations

DistributedAtomicLong (org.apache.curator.framework.recipes.atomic.DistributedAtomicLong)2 MockCurator (com.yahoo.vespa.curator.mock.MockCurator)1 PromotedToLock (org.apache.curator.framework.recipes.atomic.PromotedToLock)1 Test (org.junit.Test)1