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;
}
}
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;
}
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;
}
}
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));
}
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));
}
Aggregations