Search in sources :

Example 1 with AsyncAtomicLong

use of com.hazelcast.core.AsyncAtomicLong in project wso2-synapse by wso2.

the class SharedParamManager method asyncGetAndAddDistributedCounter.

/**
 * Asynchronously add given value to the distribute counter of caller context of given id. If it's not
 * distributed return local counter. This will return global value before add the provided counter
 *
 * @param id of the caller context
 * @param value to set to the global counter
 */
public static long asyncGetAndAddDistributedCounter(String id, long value) {
    if (log.isDebugEnabled()) {
        log.debug("ASYNC CREATING AND SETTING COUNTER WITH ID " + id);
    }
    id = ThrottleConstants.THROTTLE_SHARED_COUNTER_KEY + id;
    HazelcastInstance hazelcastInstance = getHazelcastInstance();
    if (hazelcastInstance != null) {
        AsyncAtomicLong asyncAtomicLong = (AsyncAtomicLong) hazelcastInstance.getAtomicLong(id);
        long currentGlobalCounter = asyncAtomicLong.get();
        asyncAtomicLong.asyncAddAndGet(value);
        return currentGlobalCounter;
    } else {
        Long currentCount = counters.get(id);
        if (currentCount == null) {
            currentCount = 0L;
        }
        long updatedCount = currentCount + value;
        counters.put(id, updatedCount);
        return currentCount;
    }
}
Also used : AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong)

Example 2 with AsyncAtomicLong

use of com.hazelcast.core.AsyncAtomicLong in project wso2-synapse by wso2.

the class HazelcastDistributedCounterManager method asyncGetAndAlterCounter.

@Override
public long asyncGetAndAlterCounter(String key, long value) {
    HazelcastInstance hazelcastInstance = getHazelcastInstance();
    AsyncAtomicLong asyncAtomicLong = (AsyncAtomicLong) hazelcastInstance.getAtomicLong(key);
    long currentGlobalCounter = asyncAtomicLong.get();
    asyncAtomicLong.asyncAlter(new HazelcastDistributedCounterManager.AddLocalCount(value));
    return currentGlobalCounter;
}
Also used : AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance)

Example 3 with AsyncAtomicLong

use of com.hazelcast.core.AsyncAtomicLong in project wso2-synapse by wso2.

the class SharedParamManager method asyncGetAndAlterDistributedCounter.

/**
 * Asynchronously add given value to the distribute counter of caller context of given id. If it's not
 * distributed return local counter. This will return global value before add the provided counter
 *
 * @param id of the caller context
 * @param value to set to the global counter
 */
public static long asyncGetAndAlterDistributedCounter(String id, long value) {
    HazelcastInstance hazelcastInstance = getHazelcastInstance();
    id = ThrottleConstants.THROTTLE_SHARED_COUNTER_KEY + id;
    if (hazelcastInstance != null) {
        AsyncAtomicLong asyncAtomicLong = (AsyncAtomicLong) hazelcastInstance.getAtomicLong(id);
        long currentGlobalCounter = asyncAtomicLong.get();
        asyncAtomicLong.asyncAlter(new AddLocalCount(value));
        return currentGlobalCounter;
    } else {
        Long currentCount = counters.get(id);
        if (currentCount == null) {
            currentCount = 0L;
        }
        long updatedCount = currentCount + value;
        counters.put(id, updatedCount);
        return currentCount;
    }
}
Also used : AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong)

Example 4 with AsyncAtomicLong

use of com.hazelcast.core.AsyncAtomicLong in project hazelcast-simulator by hazelcast.

the class AsyncAtomicLongTest method write.

@TimeStep
public void write(ThreadState state, Probe probe, @StartNanos long startNanos) {
    AsyncAtomicLong counter = state.getRandomCounter();
    state.increments++;
    ICompletableFuture<Long> future = counter.asyncIncrementAndGet();
    state.add(future);
    future.andThen(new LongExecutionCallback(probe, startNanos));
}
Also used : AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong) AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong) IAtomicLong(com.hazelcast.core.IAtomicLong) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 5 with AsyncAtomicLong

use of com.hazelcast.core.AsyncAtomicLong in project hazelcast-simulator by hazelcast.

the class AsyncAtomicLongTest method get.

@TimeStep(prob = -1)
public void get(ThreadState state, Probe probe, @StartNanos long startNanos) {
    AsyncAtomicLong counter = state.getRandomCounter();
    ICompletableFuture<Long> future = counter.asyncGet();
    state.add(future);
    future.andThen(new LongExecutionCallback(probe, startNanos));
}
Also used : AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong) AsyncAtomicLong(com.hazelcast.core.AsyncAtomicLong) IAtomicLong(com.hazelcast.core.IAtomicLong) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Aggregations

AsyncAtomicLong (com.hazelcast.core.AsyncAtomicLong)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 IAtomicLong (com.hazelcast.core.IAtomicLong)2 TimeStep (com.hazelcast.simulator.test.annotations.TimeStep)2