Search in sources :

Example 1 with SerializableXID

use of com.hazelcast.transaction.impl.xa.SerializableXID in project hazelcast by hazelcast.

the class XAResourceProxy method finalizeTransactionRemotely.

private void finalizeTransactionRemotely(Xid xid, boolean isCommit) {
    SerializableXID serializableXID = new SerializableXID(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier());
    SerializationService serializationService = getContext().getSerializationService();
    Data xidData = serializationService.toData(serializableXID);
    ClientMessage request = XATransactionFinalizeCodec.encodeRequest(serializableXID, isCommit);
    invoke(request, xidData);
}
Also used : SerializableXID(com.hazelcast.transaction.impl.xa.SerializableXID) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 2 with SerializableXID

use of com.hazelcast.transaction.impl.xa.SerializableXID in project hazelcast by hazelcast.

the class XAResourceProxy method clearRemoteTransactions.

private void clearRemoteTransactions(Xid xid) {
    SerializableXID serializableXID = new SerializableXID(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier());
    SerializationService serializationService = getContext().getSerializationService();
    Data xidData = serializationService.toData(serializableXID);
    ClientMessage request = XATransactionClearRemoteCodec.encodeRequest(serializableXID);
    invoke(request, xidData);
}
Also used : SerializableXID(com.hazelcast.transaction.impl.xa.SerializableXID) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 3 with SerializableXID

use of com.hazelcast.transaction.impl.xa.SerializableXID in project hazelcast by hazelcast.

the class ClientXATest method testRecovery.

@Test
public void testRecovery() throws Exception {
    HazelcastInstance instance = Hazelcast.newHazelcastInstance();
    Hazelcast.newHazelcastInstance();
    Hazelcast.newHazelcastInstance();
    HazelcastXAResource xaResource = instance.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);
    instance.shutdown();
    HazelcastInstance client = HazelcastClient.newHazelcastClient();
    HazelcastXAResource clientXaResource = client.getXAResource();
    Xid[] recovered = clientXaResource.recover(0);
    for (Xid xid : recovered) {
        clientXaResource.commit(xid, false);
    }
    assertEquals("value", client.getMap("map").get("key"));
}
Also used : Xid(javax.transaction.xa.Xid) SerializableXID(com.hazelcast.transaction.impl.xa.SerializableXID) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastXAResource(com.hazelcast.transaction.HazelcastXAResource) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 4 with SerializableXID

use of com.hazelcast.transaction.impl.xa.SerializableXID in project hazelcast by hazelcast.

the class CollectRemoteTransactionsOperation method run.

@Override
public void run() throws Exception {
    XAService xaService = getService();
    NodeEngine nodeEngine = getNodeEngine();
    Set<SerializableXID> xids = xaService.getPreparedXids();
    List<Data> xidSet = new ArrayList<Data>();
    for (SerializableXID xid : xids) {
        xidSet.add(nodeEngine.toData(xid));
    }
    this.xidSet = new SerializableList(xidSet);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) XAService(com.hazelcast.transaction.impl.xa.XAService) SerializableXID(com.hazelcast.transaction.impl.xa.SerializableXID) SerializableList(com.hazelcast.spi.impl.SerializableList) ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data)

Example 5 with SerializableXID

use of com.hazelcast.transaction.impl.xa.SerializableXID in project hazelcast by hazelcast.

the class HazelcastXATest method startTX.

private void startTX(final HazelcastInstance instance, final CountDownLatch nodeShutdownLatch) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                HazelcastXAResource xaResource = instance.getXAResource();
                Xid xid = new SerializableXID(42, "globalTransactionId".getBytes(), "branchQualifier".getBytes());
                xaResource.start(xid, XAResource.TMNOFLAGS);
                TransactionContext context = xaResource.getTransactionContext();
                final TransactionalMap<Object, Object> map = context.getMap("map");
                map.put("key", "value");
                xaResource.prepare(xid);
                instance.shutdown();
                nodeShutdownLatch.countDown();
            } catch (XAException e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : Xid(javax.transaction.xa.Xid) SerializableXID(com.hazelcast.transaction.impl.xa.SerializableXID) XAException(javax.transaction.xa.XAException) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastXAResource(com.hazelcast.transaction.HazelcastXAResource)

Aggregations

SerializableXID (com.hazelcast.transaction.impl.xa.SerializableXID)7 Data (com.hazelcast.nio.serialization.Data)4 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)3 TransactionContext (com.hazelcast.transaction.TransactionContext)3 Xid (javax.transaction.xa.Xid)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 Test (org.junit.Test)2 NodeEngine (com.hazelcast.spi.NodeEngine)1 SerializableList (com.hazelcast.spi.impl.SerializableList)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1 XAService (com.hazelcast.transaction.impl.xa.XAService)1 ArrayList (java.util.ArrayList)1 XAException (javax.transaction.xa.XAException)1