Search in sources :

Example 1 with InputBuffer

use of com.arjuna.ats.arjuna.state.InputBuffer in project narayana by jbosstm.

the class HornetqJournalStore method start.

public void start() throws Exception {
    journal.start();
    List<RecordInfo> committedRecords = new LinkedList<RecordInfo>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<PreparedTransactionInfo>();
    TransactionFailureCallback failureCallback = new TransactionFailureCallback() {

        public void failedTransaction(long l, List<RecordInfo> recordInfos, List<RecordInfo> recordInfos1) {
            tsLogger.i18NLogger.warn_journal_load_error();
        }
    };
    JournalLoadInformation journalLoadInformation = journal.load(committedRecords, preparedTransactions, failureCallback);
    maxID.set(journalLoadInformation.getMaxID());
    if (!preparedTransactions.isEmpty()) {
        tsLogger.i18NLogger.warn_journal_load_error();
    }
    for (RecordInfo record : committedRecords) {
        InputBuffer inputBuffer = new InputBuffer(record.data);
        Uid uid = UidHelper.unpackFrom(inputBuffer);
        String typeName = inputBuffer.unpackString();
        getContentForType(typeName).put(uid, record);
    // don't unpack the rest yet, we may never need it. read_committed does it on demand.
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) JournalLoadInformation(org.apache.activemq.artemis.core.journal.JournalLoadInformation) Uid(com.arjuna.ats.arjuna.common.Uid) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) InputBuffer(com.arjuna.ats.arjuna.state.InputBuffer) LinkedList(java.util.LinkedList) List(java.util.List) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) LinkedList(java.util.LinkedList)

Example 2 with InputBuffer

use of com.arjuna.ats.arjuna.state.InputBuffer in project narayana by jbosstm.

the class IOStateUnitTest method testIOObjectState.

@Test
public void testIOObjectState() throws Exception {
    OutputObjectState oos = new OutputObjectState(new Uid(), "");
    oos.packBoolean(true);
    oos.packByte((byte) 0);
    oos.packChar('a');
    oos.packDouble(1.0);
    oos.packFloat((float) 1.0);
    oos.packInt(1);
    oos.packLong(1234);
    oos.packShort((short) 10);
    oos.packString("test");
    assertTrue(oos.valid());
    PrintWriter pw = new PrintWriter(new StringWriter());
    oos.print(pw);
    assertTrue(oos.length() != 0);
    assertTrue(oos.notempty());
    assertTrue(oos.stateUid() != Uid.nullUid());
    assertTrue(oos.buffer() != null);
    assertTrue(oos.size() > 0);
    assertTrue(oos.type() != null);
    OutputObjectState temp = new OutputObjectState(oos);
    assertTrue(temp.toString() != null);
    InputObjectState ios = new InputObjectState(oos);
    assertTrue(ios.buffer() != null);
    assertTrue(ios.length() > 0);
    assertTrue(ios.notempty());
    assertTrue(ios.size() > 0);
    assertTrue(ios.stateUid() != Uid.nullUid());
    assertTrue(ios.valid());
    ios.print(pw);
    InputObjectState is = new InputObjectState(ios);
    assertTrue(is.toString() != null);
    assertTrue(ios.unpackBoolean());
    assertEquals(ios.unpackByte(), (byte) 0);
    assertEquals(ios.unpackChar(), 'a');
    assertTrue(ios.unpackDouble() == 1.0);
    assertTrue(ios.unpackFloat() == (float) 1.0);
    assertEquals(ios.unpackInt(), 1);
    assertEquals(ios.unpackLong(), 1234);
    assertEquals(ios.unpackShort(), (short) 10);
    assertEquals(ios.unpackString(), "test");
    InputObjectState c = new InputObjectState();
    OutputObjectState buff = new OutputObjectState();
    OutputObjectState o = new OutputObjectState();
    Uid u = new Uid();
    buff.packString("foobar");
    UidHelper.packInto(u, buff);
    buff.packInto(o);
    InputBuffer ibuff = new InputBuffer(o.buffer());
    c.copy(ios);
    ios.unpackFrom(ibuff);
    ios.copyFrom(new OutputObjectState());
    assertTrue(ios.toString() != null);
    oos.reset();
    oos.rewrite();
    oos.packInto(new OutputObjectState());
    oos.copy(new OutputObjectState());
    assertTrue(oos.toString() != null);
    temp = new OutputObjectState(new Uid(), "", null);
    assertFalse(temp.valid());
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) StringWriter(java.io.StringWriter) InputBuffer(com.arjuna.ats.arjuna.state.InputBuffer) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with InputBuffer

use of com.arjuna.ats.arjuna.state.InputBuffer in project narayana by jbosstm.

the class HornetqJournalStore method read_committed.

/**
 * Read the object's committed state.
 *
 * @param uid  The object to work on.
 * @param typeName The type of the object to work on.
 * @return the state of the object.
 * @throws ObjectStoreException if things go wrong.
 */
public InputObjectState read_committed(Uid uid, String typeName) throws ObjectStoreException {
    RecordInfo record = getContentForType(typeName).get(uid);
    if (record == null) {
        return null;
    }
    // not too much of an issue as log reads are done for recovery only.
    try {
        InputBuffer inputBuffer = new InputBuffer(record.data);
        UidHelper.unpackFrom(inputBuffer);
        inputBuffer.unpackString();
        return new InputObjectState(uid, typeName, inputBuffer.unpackBytes());
    } catch (Exception e) {
        throw new ObjectStoreException(e);
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) InputBuffer(com.arjuna.ats.arjuna.state.InputBuffer) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 4 with InputBuffer

use of com.arjuna.ats.arjuna.state.InputBuffer in project narayana by jbosstm.

the class ActionHierarchyUnitTest method test.

@Test
public void test() throws Exception {
    ActionHierarchy ah = new ActionHierarchy(5);
    Uid[] tx = new Uid[5];
    assertEquals(ah.getDeepestActionUid(), Uid.nullUid());
    for (int i = 0; i < tx.length; i++) {
        tx[i] = new Uid();
        ah.add(tx[i]);
    }
    assertEquals(ah.depth(), tx.length);
    assertEquals(ah.getActionUid(0), tx[0]);
    Uid deepest = new Uid();
    ah.add(deepest, ActionType.TOP_LEVEL);
    PrintWriter pw = new PrintWriter(System.err);
    ah.print(pw);
    assertEquals(ah.getDeepestActionUid(), deepest);
    ActionHierarchy cp = new ActionHierarchy(ah);
    assertTrue(cp.equals(ah));
    cp.copy(ah);
    ah.copy(ah);
    assertTrue(cp.equals(ah));
    OutputBuffer out = new OutputBuffer();
    cp.pack(out);
    InputBuffer in = new InputBuffer(out.buffer());
    ah.unpack(in);
    assertTrue(ah.equals(cp));
    assertTrue(ah.isAncestor(deepest));
    ah.forgetDeepest();
    assertTrue(ah.findCommonPrefix(cp) != 0);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputBuffer(com.arjuna.ats.arjuna.state.InputBuffer) ActionHierarchy(com.arjuna.ats.arjuna.coordinator.ActionHierarchy) OutputBuffer(com.arjuna.ats.arjuna.state.OutputBuffer) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 5 with InputBuffer

use of com.arjuna.ats.arjuna.state.InputBuffer in project narayana by jbosstm.

the class IOStateUnitTest method testIOObjectBuffer.

@Test
public void testIOObjectBuffer() throws Exception {
    PrintWriter pw = new PrintWriter(new StringWriter());
    OutputBuffer obuff = new OutputBuffer(1024);
    obuff.print(pw);
    assertTrue(obuff.toString() != null);
    OutputBuffer tobuff = new OutputBuffer(obuff);
    assertTrue(tobuff.valid());
    InputBuffer ibuff = new InputBuffer();
    ibuff.print(pw);
    InputBuffer tibuff = new InputBuffer(ibuff);
    assertEquals(tibuff.valid(), false);
}
Also used : StringWriter(java.io.StringWriter) InputBuffer(com.arjuna.ats.arjuna.state.InputBuffer) OutputBuffer(com.arjuna.ats.arjuna.state.OutputBuffer) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

InputBuffer (com.arjuna.ats.arjuna.state.InputBuffer)5 Uid (com.arjuna.ats.arjuna.common.Uid)3 PrintWriter (java.io.PrintWriter)3 Test (org.junit.Test)3 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)2 OutputBuffer (com.arjuna.ats.arjuna.state.OutputBuffer)2 StringWriter (java.io.StringWriter)2 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)2 ActionHierarchy (com.arjuna.ats.arjuna.coordinator.ActionHierarchy)1 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)1 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 JournalLoadInformation (org.apache.activemq.artemis.core.journal.JournalLoadInformation)1 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)1 TransactionFailureCallback (org.apache.activemq.artemis.core.journal.TransactionFailureCallback)1