Search in sources :

Example 1 with TransactionStatusConnector

use of com.arjuna.ats.internal.arjuna.recovery.TransactionStatusConnector in project narayana by jbosstm.

the class TransactionStatusConnectionManager method updateTSMI.

/**
 * Examine the Object Store for any new TrasactionStatusManagerItem
 * objects, and add to local hash table.
 */
public void updateTSMI() {
    boolean tsmis = false;
    InputObjectState uids = new InputObjectState();
    Vector tsmiVector = new Vector();
    try {
        tsmis = _recoveryStore.allObjUids(_typeName, uids);
    } catch (ObjectStoreException ex) {
        tsLogger.i18NLogger.warn_recovery_TransactionStatusConnectionManager_2(ex);
    }
    if (tsmis) {
        Uid theUid = null;
        boolean moreUids = true;
        while (moreUids) {
            try {
                theUid = UidHelper.unpackFrom(uids);
                if (theUid.equals(Uid.nullUid())) {
                    moreUids = false;
                } else {
                    Uid newUid = new Uid(theUid);
                    if (tsLogger.logger.isDebugEnabled()) {
                        tsLogger.logger.debug("found process uid " + newUid);
                    }
                    tsmiVector.addElement(newUid);
                }
            } catch (Exception ex) {
                moreUids = false;
            }
        }
    }
    // for each TransactionStatusManager found, if their is
    // not an entry in the local hash table for it then add it.
    Enumeration tsmiEnum = tsmiVector.elements();
    while (tsmiEnum.hasMoreElements()) {
        Uid currentUid = (Uid) tsmiEnum.nextElement();
        String process_id = currentUid.getHexPid();
        if (!_tscTable.containsKey(process_id)) {
            TransactionStatusConnector tsc = new TransactionStatusConnector(process_id, currentUid);
            if (tsc.isDead()) {
                tsc.delete();
                tsc = null;
            } else {
                _tscTable.put(process_id, tsc);
            }
            if (tsLogger.logger.isDebugEnabled()) {
                tsLogger.logger.debug("added TransactionStatusConnector to table for process uid " + process_id);
            }
        }
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) Uid(com.arjuna.ats.arjuna.common.Uid) Enumeration(java.util.Enumeration) TransactionStatusConnector(com.arjuna.ats.internal.arjuna.recovery.TransactionStatusConnector) Vector(java.util.Vector) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 2 with TransactionStatusConnector

use of com.arjuna.ats.internal.arjuna.recovery.TransactionStatusConnector in project narayana by jbosstm.

the class TransactionStatusConnectionManager method getRemoteTransactionStatus.

/**
 * Use the TransactionStatusConnector to remotly query a transaction manager to get the tx status.
 *
 * @param process_id the process identifier
 * @param transactionType the type of the transaction
 * @param tranUid the Uid of the transaction
 * @return the remote transaction status
 */
private int getRemoteTransactionStatus(String process_id, String transactionType, Uid tranUid) {
    int status = ActionStatus.INVALID;
    if (!_tscTable.containsKey(process_id)) {
        updateTSMI();
    }
    if (_tscTable.containsKey(process_id)) {
        TransactionStatusConnector tsc = (TransactionStatusConnector) _tscTable.get(process_id);
        if (tsc.isDead()) {
            _tscTable.remove(process_id);
            tsc.delete();
            tsc = null;
        } else {
            status = tsc.getTransactionStatus(transactionType, tranUid);
        }
    }
    return status;
}
Also used : TransactionStatusConnector(com.arjuna.ats.internal.arjuna.recovery.TransactionStatusConnector)

Example 3 with TransactionStatusConnector

use of com.arjuna.ats.internal.arjuna.recovery.TransactionStatusConnector in project narayana by jbosstm.

the class ActionTestClient method doWork.

public void doWork(InputStream is, OutputStream os) throws IOException {
    System.err.println("starting to work");
    _in = new BufferedReader(new InputStreamReader(is));
    _out = new PrintWriter(new OutputStreamWriter(os));
    try {
        String pidUidStr = _in.readLine();
        Uid pidUid = new Uid(pidUidStr);
        String pidStr = _in.readLine();
        if (pidUid.equals(Uid.nullUid())) {
            System.err.println("Test Failed");
        } else {
            _tsc = new TransactionStatusConnector(pidStr, pidUid);
            test1();
            test2();
            test3();
            System.err.println("tests passed: " + _tests_passed + "  tests failed: " + _tests_failed);
        }
    } catch (Exception ex) {
        System.err.println(" FAILED " + ex);
    } finally {
        synchronized (this) {
            finished = true;
            notify();
        }
    }
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputStreamReader(java.io.InputStreamReader) TransactionStatusConnector(com.arjuna.ats.internal.arjuna.recovery.TransactionStatusConnector) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 4 with TransactionStatusConnector

use of com.arjuna.ats.internal.arjuna.recovery.TransactionStatusConnector in project narayana by jbosstm.

the class TransactionStatusConnectorTest method test1.

/**
 * Test which checks that a transaction status connector can be
 * created and transaction statuses can be retrieved using a simple
 * test service.
 */
private static void test1() {
    try {
        TransactionStatusConnector testTransactionStatusConnector = new TransactionStatusConnector(_pidStr, _pidUid);
        _test_service._test_status = Integer.toString(_test_status_1);
        int test_status1 = testTransactionStatusConnector.getTransactionStatus(_test_tran_type_1, _test_uid_1);
        _rx_tran_type_1 = _test_service._rx_tran_type;
        _rx_uid_str_1 = _test_service._rx_uid_str;
        _test_service._test_status = Integer.toString(_test_status_2);
        int test_status2 = testTransactionStatusConnector.getTransactionStatus(_test_tran_type_2, _test_uid_2);
        _rx_tran_type_2 = _test_service._rx_tran_type;
        _rx_uid_str_2 = _test_service._rx_uid_str;
        _test_service._test_status = Integer.toString(_test_status_3);
        int test_status3 = testTransactionStatusConnector.getTransactionStatus(_test_tran_type_3, _test_uid_3);
        _rx_tran_type_3 = _test_service._rx_tran_type;
        _rx_uid_str_3 = _test_service._rx_uid_str;
        _test_service._test_status = Integer.toString(_test_status_4);
        int test_status4 = testTransactionStatusConnector.getTransactionStatus(_test_tran_type_4, _test_uid_4);
        _rx_tran_type_4 = _test_service._rx_tran_type;
        _rx_uid_str_4 = _test_service._rx_uid_str;
        if ((test_status1 == _test_status_1) && (test_status2 == _test_status_2) && (test_status3 == _test_status_3) && (test_status4 == _test_status_4) && (_rx_tran_type_1.equals(_test_tran_type_1)) && (_rx_tran_type_2.equals(_test_tran_type_2)) && (_rx_tran_type_3.equals(_test_tran_type_3)) && (_rx_tran_type_4.equals(_test_tran_type_4)) && (_rx_uid_str_1.equals(_test_uid_1.toString())) && (_rx_uid_str_2.equals(_test_uid_2.toString())) && (_rx_uid_str_3.equals(_test_uid_3.toString())) && (_rx_uid_str_4.equals(_test_uid_4.toString()))) {
            System.out.println(_unit_test + "test1: passed");
            _tests_passed++;
        } else {
            System.out.println(_unit_test + "test1: failed");
            _tests_failed++;
        }
        _listener.stopListener();
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println(_unit_test + " test1 " + ex);
        _tests_failed++;
    }
}
Also used : TransactionStatusConnector(com.arjuna.ats.internal.arjuna.recovery.TransactionStatusConnector) IOException(java.io.IOException) SocketException(java.net.SocketException)

Aggregations

TransactionStatusConnector (com.arjuna.ats.internal.arjuna.recovery.TransactionStatusConnector)4 Uid (com.arjuna.ats.arjuna.common.Uid)2 IOException (java.io.IOException)2 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 SocketException (java.net.SocketException)1 Enumeration (java.util.Enumeration)1 Vector (java.util.Vector)1