Package com.taobao.metamorphosis.server.transaction

Examples of com.taobao.metamorphosis.server.transaction.Transaction



    @Override
    public void beginTransaction(final SessionContext context, final TransactionId xid, final int seconds)
            throws Exception {
        Transaction transaction = null;
        if (xid.isXATransaction()) {
            this.statsManager.statsTxBegin(true, 1);
            transaction = null;
            synchronized (this.xaTransactions) {
                transaction = this.xaTransactions.get(xid);
View Full Code Here


    }


    @Override
    public int prepareTransaction(final SessionContext context, final TransactionId xid) throws Exception {
        final Transaction transaction = this.getTransaction(context, xid);
        return transaction.prepare();
    }
View Full Code Here

    @Override
    public void commitTransaction(final SessionContext context, final TransactionId xid, final boolean onePhase)
            throws Exception {
        this.statsManager.statsTxCommit(1);
        final Transaction transaction = this.getTransaction(context, xid);
        transaction.commit(onePhase);
    }
View Full Code Here


    @Override
    public void rollbackTransaction(final SessionContext context, final TransactionId xid) throws Exception {
        this.statsManager.statsTxRollback(1);
        final Transaction transaction = this.getTransaction(context, xid);
        transaction.rollback();
    }
View Full Code Here


    @Override
    public void processPutCommand(final PutCommand cmd, final SessionContext context, final PutCallback cb)
            throws Exception {
        Transaction transaction = null;
        if (cmd.getTransactionId() != null) {
            transaction = this.getTransaction(context, cmd.getTransactionId());
        }
        if (transaction != null) {
            transaction.setTransactionInUse();
            if (context.isInRecoverMode()) {
                // �ָ�ģʽ������Ҫ����
                if (cb != null) {
                    cb.putComplete(new BooleanCommand(HttpStatus.Forbidden, "The broker is in recover mode.", cmd
                        .getOpaque()));
View Full Code Here


    @Override
    public Transaction getTransaction(final SessionContext context, final TransactionId xid)
            throws MetamorphosisException, XAException {
        Transaction transaction = null;
        if (xid.isXATransaction()) {
            synchronized (this.xaTransactions) {
                transaction = this.xaTransactions.get(xid);
            }
        }
        else {
            transaction = context.getTransactions().get(xid);
        }

        if (transaction != null) {
            return transaction;
        }

        // �ж��Ƿ��˹��ύ���߻ع�����
        if (xid.isXATransaction()) {
            synchronized (this.xaHeuristicTransactions) {
                transaction = this.xaHeuristicTransactions.get(xid);
            }
            if (transaction != null) {
                switch (transaction.getState()) {
                case Transaction.HEURISTIC_COMMIT_STATE:
                    XAException e = new XAException("XA transaction '" + xid + "' has been heuristically committed.");
                    e.errorCode = XAException.XA_HEURCOM;
                    throw e;
                case Transaction.HEURISTIC_ROLLBACK_STATE:
                    e = new XAException("XA transaction '" + xid + "' has been heuristically rolled back.");
                    e.errorCode = XAException.XA_HEURRB;
                    throw e;
                case Transaction.HEURISTIC_COMPLETE_STATE:
                    e = new XAException("XA transaction '" + xid + "' has been heuristically completed.");
                    e.errorCode = XAException.XA_HEURHAZ;
                    throw e;
                default:
                    log.warn("Invalid transaction state in xaHeuristicTransactions:" + transaction.getState());
                    // Ӧ�ò�������������
                    break;
                }
            }
        }
View Full Code Here

    public void commitTransactionHeuristically(final String txKey, final boolean onePhase) throws Exception {
        final TransactionId xid = TransactionId.valueOf(txKey);
        if (xid.isNull() || !xid.isXATransaction()) {
            return;
        }
        final Transaction transaction = this.getTransaction(null, xid);
        if (transaction == null || !transaction.isPrepared()) {
            return;
        }
        this.commitTransaction(null, xid, onePhase);
        transaction.setState(Transaction.HEURISTIC_COMMIT_STATE);
        synchronized (this.xaHeuristicTransactions) {
            this.xaHeuristicTransactions.put(xid, (XATransaction) transaction);
        }
    }
View Full Code Here

    public void completeTransactionHeuristically(final String txKey) throws Exception {
        final TransactionId xid = TransactionId.valueOf(txKey);
        if (xid.isNull() || !xid.isXATransaction()) {
            return;
        }
        final Transaction transaction = this.getTransaction(null, xid);
        if (transaction == null || !transaction.isPrepared()) {
            return;
        }
        synchronized (this.xaTransactions) {
            this.xaTransactions.remove(xid);
        }
        transaction.setState(Transaction.HEURISTIC_COMPLETE_STATE);
        synchronized (this.xaHeuristicTransactions) {
            this.xaHeuristicTransactions.put(xid, (XATransaction) transaction);
        }
    }
View Full Code Here

    public void rollbackTransactionHeuristically(final String txKey) throws Exception {
        final TransactionId xid = TransactionId.valueOf(txKey);
        if (xid.isNull() || !xid.isXATransaction()) {
            return;
        }
        final Transaction transaction = this.getTransaction(null, xid);
        if (transaction == null || !transaction.isPrepared()) {
            return;
        }
        this.rollbackTransaction(null, xid);
        if (transaction != null) {
            transaction.setState(Transaction.HEURISTIC_ROLLBACK_STATE);
            synchronized (this.xaHeuristicTransactions) {
                this.xaHeuristicTransactions.put(xid, (XATransaction) transaction);
            }
        }
    }
View Full Code Here

    public void testBeginPutCommitOnePhase() throws Exception {
        final SessionContext context = new SessionContextImpl("test", this.conn);
        final TransactionId xid = new LocalTransactionId("test", 100);
        assertNull(context.getTransactions().get(xid));
        this.processor.beginTransaction(context, xid, 0);
        final Transaction tx = context.getTransactions().get(xid);
        assertNotNull(tx);
        assertSame(xid, tx.getTransactionId());
        this.replay();

        this.processor.processPutCommand(new PutCommand("topic1", 2, "hello".getBytes(), xid, 0, 1), context, null);
        final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertEquals(0, store.getSizeInBytes());

        // commit one phase
        this.processor.commitTransaction(context, xid, true);
        store.flush();
        assertEquals(Transaction.FINISHED_STATE, tx.getState());
        assertNull(context.getTransactions().get(xid));

        assertTrue(store.getSizeInBytes() > 0);
    }
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.server.transaction.Transaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.