HazelcastInstanceProxy proxy = (HazelcastInstanceProxy) createHazelcastInstance();
Field originalField = HazelcastInstanceProxy.class.getDeclaredField("original");
originalField.setAccessible(true);
HazelcastInstanceImpl hz = (HazelcastInstanceImpl) originalField.get(proxy);
NodeEngine nodeEngine = hz.node.nodeEngine;
ExecutionService es = nodeEngine.getExecutionService();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(2);
final ExecutorService executorService = Executors.newSingleThreadExecutor();
try {
Future future = executorService.submit(new Callable<String>() {
@Override
public String call() {
try {
latch1.await(30, TimeUnit.SECONDS);
return "success";
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
final AtomicReference reference1 = new AtomicReference();
final AtomicReference reference2 = new AtomicReference();
final ICompletableFuture completableFuture = es.asCompletableFuture(future);
completableFuture.andThen(new ExecutionCallback() {
@Override
public void onResponse(Object response) {
reference1.set(response);
latch2.countDown();