use of com.hazelcast.transaction.impl.xa.SerializableXID in project hazelcast by hazelcast.
the class HazelcastXATest method testRecovery.
@Test
public void testRecovery() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(4);
HazelcastInstance instance1 = factory.newHazelcastInstance();
HazelcastInstance instance2 = factory.newHazelcastInstance();
HazelcastInstance instance3 = factory.newHazelcastInstance();
HazelcastXAResource xaResource = instance1.getXAResource();
Xid myXid = new SerializableXID(42, "globalTransactionId".getBytes(), "branchQualifier".getBytes());
xaResource.start(myXid, 0);
TransactionContext context1 = xaResource.getTransactionContext();
TransactionalMap<Object, Object> map = context1.getMap("map");
map.put("key", "value");
xaResource.prepare(myXid);
instance1.shutdown();
instance1 = factory.newHazelcastInstance();
xaResource = instance1.getXAResource();
Xid[] recovered = xaResource.recover(0);
for (Xid xid : recovered) {
xaResource.commit(xid, false);
}
assertEquals("value", instance2.getMap("map").get("key"));
}
use of com.hazelcast.transaction.impl.xa.SerializableXID in project hazelcast by hazelcast.
the class XAResourceProxy method recover.
@Override
public Xid[] recover(int flag) throws XAException {
ClientMessage request = XATransactionCollectTransactionsCodec.encodeRequest();
ClientMessage response = invoke(request);
Collection<Data> list = XATransactionCollectTransactionsCodec.decodeResponse(response).response;
SerializableXID[] xidArray = new SerializableXID[list.size()];
SerializationService serializationService = getContext().getSerializationService();
int index = 0;
for (Data xidData : list) {
xidArray[index++] = serializationService.toObject(xidData);
}
return xidArray;
}
Aggregations