use of com.hazelcast.cp.IAtomicLong in project hazelcast by hazelcast.
the class DurableRetrieveResultTest method testSingleExecution_WhenMigratedAfterCompletion_WhenOwnerMemberKilled.
@Test
public void testSingleExecution_WhenMigratedAfterCompletion_WhenOwnerMemberKilled() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance[] instances = factory.newInstances(smallInstanceConfig());
HazelcastInstance first = instances[0];
HazelcastInstance second = instances[1];
waitAllForSafeState(instances);
String key = generateKeyOwnedBy(first);
String runCounterName = "runCount";
IAtomicLong runCount = second.getCPSubsystem().getAtomicLong(runCounterName);
String name = randomString();
DurableExecutorService executorService = first.getDurableExecutorService(name);
IncrementAtomicLongRunnable task = new IncrementAtomicLongRunnable(runCounterName);
DurableExecutorServiceFuture<?> future = executorService.submitToKeyOwner(task, key);
// Wait for it to finish
future.get();
// Avoid race between PutResult & SHUTDOWN
sleepSeconds(3);
first.getLifecycleService().terminate();
executorService = second.getDurableExecutorService(name);
Future<Object> newFuture = executorService.retrieveResult(future.getTaskId());
// Make sure its completed
newFuture.get();
assertEquals(1, runCount.get());
}
use of com.hazelcast.cp.IAtomicLong in project hazelcast by hazelcast.
the class DurableSmallClusterTest method submitToSeveralNodes_runnable.
@Test
public void submitToSeveralNodes_runnable() throws Exception {
for (HazelcastInstance instance : instances) {
DurableExecutorService service = instance.getDurableExecutorService("testExecuteMultipleNode");
int rand = new Random().nextInt(100);
Future<Integer> future = service.submit(new IncrementAtomicLongRunnable("count"), rand);
assertEquals(Integer.valueOf(rand), future.get());
}
IAtomicLong count = instances[0].getCPSubsystem().getAtomicLong("count");
assertEquals(instances.length, count.get());
}
use of com.hazelcast.cp.IAtomicLong in project hazelcast by hazelcast.
the class RestCPSubsystemTest method test_forceDestroyDefaultCPGroup.
@Test
public void test_forceDestroyDefaultCPGroup() throws IOException {
HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
Hazelcast.newHazelcastInstance(config);
Hazelcast.newHazelcastInstance(config);
IAtomicLong long1 = instance1.getCPSubsystem().getAtomicLong("long1");
ConnectionResponse response = new HTTPCommunicator(instance1).forceDestroyCPGroup(DEFAULT_GROUP_NAME, clusterName, null);
assertEquals(200, response.responseCode);
exception.expect(CPGroupDestroyedException.class);
long1.set(5);
}
use of com.hazelcast.cp.IAtomicLong in project Payara by payara.
the class ClusterScopedInterceptor method preDestroy.
@PreDestroy
Object preDestroy(InvocationContext invocationContext) throws Exception {
Class<?> beanClass = invocationContext.getTarget().getClass().getSuperclass();
Clustered clusteredAnnotation = getAnnotation(beanManager, beanClass);
clusteredLookup.setClusteredSessionKeyIfNotSet(beanClass, clusteredAnnotation);
IAtomicLong count = clusteredLookup.getClusteredUsageCount();
if (count.decrementAndGet() <= 0) {
clusteredLookup.destroy();
} else if (!clusteredAnnotation.callPreDestoyOnDetach()) {
return null;
}
return invocationContext.proceed();
}
use of com.hazelcast.cp.IAtomicLong in project chuidiang-ejemplos by chuidiang.
the class AtomicExample method main.
public static void main(String[] args) throws FileNotFoundException, InterruptedException {
Config config = new Config();
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
IAtomicLong atomicLong = hazelcastInstance.getCPSubsystem().getAtomicLong("soy productor");
boolean cambiado = atomicLong.compareAndSet(0, 1);
if (cambiado) {
produce(hazelcastInstance);
} else {
consume(hazelcastInstance);
}
}
Aggregations