use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class TransactionalMapKeySetMessageTask method innerCall.
@Override
protected Object innerCall() throws Exception {
final TransactionContext context = endpoint.getTransactionContext(parameters.txnId);
final TransactionalMap map = context.getMap(parameters.name);
Set keySet = map.keySet();
List<Data> list = new ArrayList<Data>(keySet.size());
for (Object o : keySet) {
list.add(serializationService.toData(o));
}
return list;
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class TransactionalMapPutIfAbsentMessageTask method innerCall.
@Override
protected Object innerCall() throws Exception {
final TransactionContext context = endpoint.getTransactionContext(parameters.txnId);
final TransactionalMap map = context.getMap(parameters.name);
Object response = map.putIfAbsent(parameters.key, parameters.value);
return serializationService.toData(response);
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class TransactionalMapRemoveIfSameMessageTask method innerCall.
@Override
protected Object innerCall() throws Exception {
final TransactionContext context = endpoint.getTransactionContext(parameters.txnId);
final TransactionalMap map = context.getMap(parameters.name);
return map.remove(parameters.key, parameters.value);
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class ClientTxnMapTest method testGetForUpdate.
@Test
public void testGetForUpdate() throws TransactionException {
final String mapName = randomString();
final String key = "key";
final int initialValue = 111;
final int value = 888;
final CountDownLatch getKeyForUpdateLatch = new CountDownLatch(1);
final CountDownLatch afterTryPutResult = new CountDownLatch(1);
final IMap<String, Integer> map = client.getMap(mapName);
map.put(key, initialValue);
final AtomicBoolean tryPutResult = new AtomicBoolean(true);
Runnable incrementor = new Runnable() {
public void run() {
try {
getKeyForUpdateLatch.await(30, TimeUnit.SECONDS);
boolean result = map.tryPut(key, value, 0, TimeUnit.SECONDS);
tryPutResult.set(result);
afterTryPutResult.countDown();
} catch (InterruptedException e) {
}
}
};
new Thread(incrementor).start();
client.executeTransaction(new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
try {
final TransactionalMap<String, Integer> txMap = context.getMap(mapName);
txMap.getForUpdate(key);
getKeyForUpdateLatch.countDown();
afterTryPutResult.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
}
return true;
}
});
assertFalse(tryPutResult.get());
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class ClientTxnMapTest method testTnxMapContainsKey.
@Test
public void testTnxMapContainsKey() throws Exception {
final String mapName = randomString();
IMap map = client.getMap(mapName);
map.put("key1", "value1");
final TransactionContext context = client.newTransactionContext();
context.beginTransaction();
final TransactionalMap txMap = context.getMap(mapName);
txMap.put("key2", "value2");
assertTrue(txMap.containsKey("key1"));
assertTrue(txMap.containsKey("key2"));
assertFalse(txMap.containsKey("key3"));
context.commitTransaction();
}
Aggregations