Search in sources :

Example 46 with XidImpl

use of com.swiftmq.jms.XidImpl in project swiftmq-client by iitsoftware.

the class XAResourceImpl method toSwiftMQXid.

private XidImpl toSwiftMQXid(Xid xid) {
    XidImpl rXid = null;
    if (xid instanceof com.swiftmq.jms.XidImpl)
        rXid = (XidImpl) xid;
    else {
        rXid = (XidImpl) xidMapping.get(xid);
        if (rXid == null) {
            rXid = new XidImpl(xid);
            xidMapping.put(xid, rXid);
        }
    }
    if (logWriter != null)
        log(toString() + "/toSwiftMQXid, xid=" + xid + ", rXid=" + rXid);
    return rXid;
}
Also used : XidImpl(com.swiftmq.jms.XidImpl)

Example 47 with XidImpl

use of com.swiftmq.jms.XidImpl in project swiftmq-client by iitsoftware.

the class XAResourceImpl method rollback.

public synchronized void rollback(Xid xid) throws XAException {
    if (logWriter != null)
        log(toString() + "/rollback, xid=" + xid);
    XidImpl sxid = toSwiftMQXid(xid);
    xidMapping.remove(xid);
    XAResRollbackReply reply = null;
    try {
        int connectionId = session.getSessionImpl().getMyConnection().getConnectionId();
        session.getSessionImpl().startRecoverConsumers();
        session.getAndClearCurrentTransaction();
        List recoveryList = null;
        if (endRequestInDoubt())
            recoveryList = XARecoverRegistry.getInstance().getRequestList(sxid);
        Request request = new XAResRollbackRequest(this, session.getDispatchId(), sxid, false, recoveryList, session.getSessionImpl().getRecoveryEpoche());
        request.setConnectionId(connectionId);
        reply = (XAResRollbackReply) session.request(request);
    } catch (Exception e) {
        if (completionListener != null)
            completionListener.transactionAborted(sxid);
        XAException ex = new XAException(e.toString());
        ex.errorCode = XAException.XAER_RMFAIL;
        throw ex;
    }
    if (reply.isOk()) {
        session.getSessionImpl().endRecoverConsumersXA();
        try {
            session.getSessionImpl().closeDelayedProducers();
        } catch (JMSException e) {
            e.printStackTrace();
        }
        if (completionListener != null)
            completionListener.transactionAborted(sxid);
        XARecoverRegistry.getInstance().clear(sxid);
    } else {
        if (completionListener != null)
            completionListener.transactionAborted(sxid);
        XAException ex = new XAException(reply.getException().getMessage());
        if (reply.getErrorCode() != 0)
            ex.errorCode = reply.getErrorCode();
        else
            ex.errorCode = XAException.XAER_RMFAIL;
        throw ex;
    }
}
Also used : XAException(javax.transaction.xa.XAException) XidImpl(com.swiftmq.jms.XidImpl) Request(com.swiftmq.tools.requestreply.Request) List(java.util.List) JMSException(javax.jms.JMSException) ValidationException(com.swiftmq.tools.requestreply.ValidationException) JMSException(javax.jms.JMSException) XAException(javax.transaction.xa.XAException)

Example 48 with XidImpl

use of com.swiftmq.jms.XidImpl in project swiftmq-client by iitsoftware.

the class XAResStartRequest method readContent.

public void readContent(DataInput in) throws IOException {
    super.readContent(in);
    xid = new XidImpl();
    xid.readContent(in);
    flags = in.readInt();
}
Also used : XidImpl(com.swiftmq.jms.XidImpl)

Example 49 with XidImpl

use of com.swiftmq.jms.XidImpl in project swiftmq-ce by iitsoftware.

the class XAResourceManagerSwiftletImpl method startup.

protected void startup(Configuration configuration) throws SwiftletException {
    ctx = new SwiftletContext(this, configuration);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup...");
    try {
        ctx.heuristicHandler.loadHeuristics();
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "exception during loadHeuristics: " + e.toString());
        ctx.logSwiftlet.logError(getName(), "exception during loadHeuristics: " + e.toString());
    }
    try {
        buildPreparedTransactions();
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "exception during buildPreparedTransactions: " + e.toString());
        ctx.logSwiftlet.logError(getName(), "exception during buildPreparedTransactions: " + e.toString());
    }
    if (contexts.size() > 0) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), contexts.size() + " prepared transactions found");
        ctx.logSwiftlet.logWarning(getName(), contexts.size() + " prepared transactions found!");
        System.out.println("+++ WARNING! " + contexts.size() + " prepared transactions found!");
        System.out.println("+++          HA/Routing XA transactions are automatically recovered.");
        System.out.println("+++          You may also use Explorer/CLI for heuristic commit or rollback.");
    }
    Property prop = configuration.getProperty("scan-interval");
    scanInterval = ((Long) prop.getValue()).longValue();
    ctx.timerSwiftlet.addTimerListener(scanInterval, this);
    prop.setPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            ctx.timerSwiftlet.removeTimerListener(XAResourceManagerSwiftletImpl.this);
            scanInterval = ((Long) newValue).longValue();
            ctx.timerSwiftlet.addTimerListener(scanInterval, XAResourceManagerSwiftletImpl.this);
        }
    });
    prop = configuration.getProperty("default-transaction-timeout");
    defaultTxTimeout = ((Long) prop.getValue()).longValue();
    long timeout = getTransactionTimeout();
    if (timeout > 0)
        ctx.timerSwiftlet.addTimerListener(timeout, txTimer);
    prop.setPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            long timeout = getTransactionTimeout();
            if (timeout > 0)
                ctx.timerSwiftlet.removeTimerListener(txTimer);
            defaultTxTimeout = ((Long) newValue).longValue();
            timeout = getTransactionTimeout();
            if (timeout > 0)
                ctx.timerSwiftlet.addTimerListener(timeout, txTimer);
        }
    });
    CommandRegistry commandRegistry = ctx.preparedUsageList.getCommandRegistry();
    CommandExecutor commitExecutor = new CommandExecutor() {

        public String[] execute(String[] context, Entity entity, String[] cmd) {
            if (cmd.length != 2)
                return new String[] { TreeCommands.ERROR, "Invalid command, please try 'commit <id>'" };
            Entity e = ctx.preparedUsageList.getEntity(cmd[1]);
            if (e == null)
                return new String[] { TreeCommands.ERROR, "Unknown Entity: " + cmd[1] };
            XAContext xac = (XAContext) contexts.get(e.getDynamicObject());
            XidImpl xid = xac.getXid();
            try {
                xac.commit(false);
                if (!xid.isRouting())
                    ctx.heuristicHandler.addHeuristic(xid, true);
            } catch (Exception e1) {
                return new String[] { TreeCommands.ERROR, "Exception during commit: " + e1 };
            }
            removeXAContext(xid);
            return null;
        }
    };
    Command commitCommand = new Command("commit", "commit <id>", "Commit", true, commitExecutor, true, true);
    commandRegistry.addCommand(commitCommand);
    CommandExecutor rollbackExecutor = new CommandExecutor() {

        public String[] execute(String[] context, Entity entity, String[] cmd) {
            if (cmd.length != 2)
                return new String[] { TreeCommands.ERROR, "Invalid command, please try 'rollback <id>'" };
            Entity e = ctx.preparedUsageList.getEntity(cmd[1]);
            if (e == null)
                return new String[] { TreeCommands.ERROR, "Unknown Entity: " + cmd[1] };
            XAContext xac = (XAContext) contexts.get(e.getDynamicObject());
            XidImpl xid = xac.getXid();
            try {
                xac.rollback();
                if (!xid.isRouting())
                    ctx.heuristicHandler.addHeuristic(xid, false);
            } catch (Exception e1) {
                return new String[] { TreeCommands.ERROR, "Exception during rollback: " + e1 };
            }
            removeXAContext(xid);
            return null;
        }
    };
    Command rollbackCommand = new Command("rollback", "rollback <id>", "Rollback", true, rollbackExecutor, true, true);
    commandRegistry.addCommand(rollbackCommand);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup...done");
}
Also used : XAContext(com.swiftmq.swiftlet.xa.XAContext) XidImpl(com.swiftmq.jms.XidImpl) SwiftletException(com.swiftmq.swiftlet.SwiftletException) XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

Example 50 with XidImpl

use of com.swiftmq.jms.XidImpl in project swiftmq-ce by iitsoftware.

the class XAResourceManagerSwiftletImpl method buildPreparedTransactions.

private void buildPreparedTransactions() throws Exception {
    List prepareRecordList = ctx.storeSwiftlet.getPrepareLogRecords();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "buildPreparedTransactions, recordList: " + prepareRecordList);
    if (prepareRecordList != null && prepareRecordList.size() > 0) {
        for (int i = 0; i < prepareRecordList.size(); i++) {
            PrepareLogRecord record = (PrepareLogRecord) prepareRecordList.get(i);
            AbstractQueue queue = getPreparedQueue(record.getQueueName());
            if (queue != null) {
                XidImpl xid = record.getGlobalTxId();
                Object localTxId = queue.buildPreparedTransaction(record);
                XALiveContextImpl xac = (XALiveContextImpl) contexts.get(xid);
                if (xac == null) {
                    xac = new XALiveContextImpl(ctx, xid, true);
                    xac.setRecovered(true);
                    xac.registerUsageList();
                    contexts.put(xid, xac);
                }
                xac._addTransaction(queue, localTxId);
            }
        }
    }
}
Also used : PrepareLogRecord(com.swiftmq.swiftlet.store.PrepareLogRecord) AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) XidImpl(com.swiftmq.jms.XidImpl)

Aggregations

XidImpl (com.swiftmq.jms.XidImpl)85 XAException (javax.transaction.xa.XAException)37 JMSException (javax.jms.JMSException)28 ValidationException (com.swiftmq.tools.requestreply.ValidationException)22 Request (com.swiftmq.tools.requestreply.Request)16 List (java.util.List)12 ArrayList (java.util.ArrayList)10 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)9 MessageImpl (com.swiftmq.jms.MessageImpl)6 XAContext (com.swiftmq.swiftlet.xa.XAContext)5 QueuePullTransaction (com.swiftmq.swiftlet.queue.QueuePullTransaction)4 QueueReceiver (com.swiftmq.swiftlet.queue.QueueReceiver)4 QueueSender (com.swiftmq.swiftlet.queue.QueueSender)4 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)2 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)2 Comparator (java.util.Comparator)2 CommitRequest (com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest)1 CommitRequest (com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest)1 QueueImpl (com.swiftmq.jms.QueueImpl)1 Entity (com.swiftmq.mgmt.Entity)1