use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method submitRunnableToKeyOwner.
@Test
public void submitRunnableToKeyOwner() throws Exception {
IExecutorService service = client.getExecutorService(randomString());
String mapName = randomString();
Runnable runnable = new MapPutRunnable(mapName);
final CountDownLatch responseLatch = new CountDownLatch(1);
service.submitToKeyOwner(runnable, "key", new ExecutionCallback() {
public void onResponse(Object response) {
responseLatch.countDown();
}
public void onFailure(Throwable t) {
}
});
IMap map = client.getMap(mapName);
assertOpenEventually("responseLatch", responseLatch);
assertEquals(1, map.size());
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method submitCallable_withExecutionCallback.
@Test
public void submitCallable_withExecutionCallback() {
IExecutorService service = client.getExecutorService(randomString());
final CountDownLatch responseLatch = new CountDownLatch(1);
String msg = randomString();
Callable runnable = new AppendCallable(msg);
MemberSelector selector = new SelectAllMembers();
final AtomicReference<Object> result = new AtomicReference<Object>();
service.submit(runnable, selector, new ExecutionCallback() {
public void onResponse(Object response) {
result.set(response);
responseLatch.countDown();
}
public void onFailure(Throwable t) {
}
});
assertOpenEventually("responseLatch", responseLatch);
assertEquals(msg + AppendCallable.APPENDAGE, result.get());
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method submitRunnableToMember_withExecutionCallback.
@Test
public void submitRunnableToMember_withExecutionCallback() {
IExecutorService service = client.getExecutorService(randomString());
String mapName = randomString();
Runnable runnable = new MapPutRunnable(mapName);
Member member = server.getCluster().getLocalMember();
final CountDownLatch responseLatch = new CountDownLatch(1);
service.submitToMember(runnable, member, new ExecutionCallback() {
public void onResponse(Object response) {
responseLatch.countDown();
}
public void onFailure(Throwable t) {
}
});
Map map = client.getMap(mapName);
assertOpenEventually("responseLatch", responseLatch);
assertEquals(1, map.size());
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class ClientMapTest method testSubmitToKeyWithCallback.
@Test
public void testSubmitToKeyWithCallback() throws Exception {
IMap<Integer, Integer> map = createMap();
map.put(1, 1);
final AtomicInteger result = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(1);
ExecutionCallback<Integer> executionCallback = new ExecutionCallback<Integer>() {
@Override
public void onResponse(Integer response) {
result.set(response);
latch.countDown();
}
@Override
public void onFailure(Throwable t) {
}
};
map.submitToKey(1, new IncrementerEntryProcessor(), executionCallback);
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertEquals(2, result.get());
int actual = map.get(1);
assertEquals(2, actual);
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class FinalizeRemoteTransactionOperation method run.
@Override
public void run() throws Exception {
XAService xaService = getService();
final List<XATransaction> list = xaService.removeTransactions(xid);
if (list == null) {
sendResponse(getNodeEngine().toData(XAException.XAER_NOTA));
return;
}
final int size = list.size();
final ExecutionCallback callback = new ExecutionCallback() {
AtomicInteger counter = new AtomicInteger();
@Override
public void onResponse(Object response) {
sendResponseIfComplete();
}
@Override
public void onFailure(Throwable t) {
// TODO log the error
sendResponseIfComplete();
}
void sendResponseIfComplete() {
if (size == counter.incrementAndGet()) {
sendResponse(null);
}
}
};
for (XATransaction xaTransaction : list) {
finalizeTransaction(xaTransaction, callback);
}
}
Aggregations