Search in sources :

Example 71 with XidImpl

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

the class XAResourceImpl method start.

public synchronized void start(Xid xid, int flags) throws XAException {
    if (logWriter != null)
        log(toString() + "/start, xid=" + xid + ", flags=" + flags);
    XidImpl sxid = toSwiftMQXid(xid);
    XAResStartReply reply = null;
    try {
        reply = (XAResStartReply) session.request(new XAResStartRequest(dispatchId, sxid, flags));
    } catch (Exception e) {
        XAException ex = new XAException(e.toString());
        ex.errorCode = XAException.XAER_RMFAIL;
        throw ex;
    }
    if (!reply.isOk()) {
        XAException ex = new XAException(reply.getException().getMessage());
        ex.errorCode = reply.getErrorCode();
        throw ex;
    } else {
        try {
            session.session.assignLastMessage();
        } catch (Exception e) {
            XAException ex = new XAException(reply.getException().getMessage());
            ex.errorCode = reply.getErrorCode();
            throw ex;
        }
    }
    if (completionListener != null)
        completionListener.transactionStarted(sxid, session);
}
Also used : XAException(javax.transaction.xa.XAException) XidImpl(com.swiftmq.jms.XidImpl) XAException(javax.transaction.xa.XAException)

Example 72 with XidImpl

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

the class XAResourceImpl method end.

public synchronized void end(Xid xid, int flags) throws XAException {
    XidImpl sxid = toSwiftMQXid(xid);
    XAResEndReply reply = null;
    try {
        reply = (XAResEndReply) session.request(new XAResEndRequest(dispatchId, sxid, flags));
    } catch (Exception e) {
        XAException ex = new XAException(e.toString());
        ex.errorCode = XAException.XA_RBINTEGRITY;
        throw ex;
    }
    if (!reply.isOk()) {
        XAException ex = new XAException(reply.getException().getMessage());
        ex.errorCode = reply.getErrorCode();
        throw ex;
    } else {
        Object[] content = session.getAndClearCurrentTransaction();
        if (content != null && content.length > 0)
            xidContent.put(sxid, content);
    }
}
Also used : XAException(javax.transaction.xa.XAException) XidImpl(com.swiftmq.jms.XidImpl) XAException(javax.transaction.xa.XAException)

Example 73 with XidImpl

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

the class XAResourceImpl method prepare.

public synchronized int prepare(Xid xid) throws XAException {
    XidImpl sxid = toSwiftMQXid(xid);
    XAResPrepareReply reply = null;
    try {
        reply = (XAResPrepareReply) session.request(new XAResPrepareRequest(dispatchId, sxid, (Object[]) xidContent.remove(sxid)));
    } catch (Exception e) {
        XAException ex = new XAException(e.toString());
        ex.errorCode = XAException.XA_RBINTEGRITY;
        throw ex;
    }
    if (!reply.isOk()) {
        XAException ex = new XAException(reply.getException().getMessage());
        ex.errorCode = reply.getErrorCode();
        throw ex;
    }
    return XA_OK;
}
Also used : XAException(javax.transaction.xa.XAException) XidImpl(com.swiftmq.jms.XidImpl) XAException(javax.transaction.xa.XAException)

Example 74 with XidImpl

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

the class XAResourceImpl method commit.

public synchronized void commit(Xid xid, boolean onePhase) throws XAException {
    XidImpl sxid = toSwiftMQXid(xid);
    xidMapping.remove(xid);
    XAResCommitReply reply = null;
    try {
        XAResCommitRequest req = new XAResCommitRequest(dispatchId, sxid, onePhase);
        if (onePhase)
            req.setMessages((Object[]) xidContent.remove(sxid));
        reply = (XAResCommitReply) session.request(req);
    } catch (Exception e) {
        XAException ex = new XAException(e.toString());
        ex.errorCode = XAException.XA_RBINTEGRITY;
        throw ex;
    }
    if (!reply.isOk()) {
        XAException ex = new XAException(reply.getException().getMessage());
        ex.errorCode = reply.getErrorCode();
        throw ex;
    } else {
        if (reply.getDelay() > 0) {
            try {
                Thread.sleep(reply.getDelay());
            } catch (Exception ignored) {
            }
        }
    }
}
Also used : XAException(javax.transaction.xa.XAException) XidImpl(com.swiftmq.jms.XidImpl) XAException(javax.transaction.xa.XAException)

Example 75 with XidImpl

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

the class XADeliveryStage method processTransactionRequest.

private void processTransactionRequest(TransactionRequest request) throws Exception {
    XidImpl xid = request.getXid();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + " ...");
    Tx tx = new Tx(xid);
    inboundTransactions.put(xid, tx);
    List messageList = request.getMessageList();
    for (int i = 0; i < messageList.size(); i++) {
        boolean msgValid = true;
        MessageImpl msg = (MessageImpl) messageList.get(i);
        String queueName = null;
        if (msg.getDestRouter().equals(ctx.routerName))
            queueName = msg.getDestQueue();
        else
            queueName = SchedulerRegistry.QUEUE_PREFIX + msg.getDestRouter();
        QueueSender sender = (QueueSender) producers.get(queueName);
        if (sender == null) {
            try {
                sender = ctx.queueManager.createQueueSender(queueName, null);
                producers.put(queueName, sender);
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", exception creating sender, queue=" + queueName);
                if (ctx.queueManager.isTemporaryQueue(queueName)) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", temp queue, forget it");
                    msgValid = false;
                } else {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", using unroutable queue");
                    sender = (QueueSender) producers.get(RoutingSwiftletImpl.UNROUTABLE_QUEUE);
                    msg.setStringProperty(MessageImpl.PROP_UNROUTABLE_REASON, e.toString());
                }
            }
        }
        if (msgValid) {
            try {
                QueuePushTransaction t = tx.getTransaction(queueName);
                if (t == null) {
                    t = sender.createTransaction();
                    tx.addTransaction(queueName, t);
                }
                t.putMessage(msg);
            } catch (Exception e) {
                try {
                    if (!sender.getQueueName().startsWith(RoutingSwiftletImpl.UNROUTABLE_QUEUE))
                        sender.close();
                } catch (Exception e1) {
                }
                producers.remove(queueName);
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", exception put message, queue=" + queueName);
                if (ctx.queueManager.isTemporaryQueue(queueName)) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", temp queue, forget it");
                } else {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", using unroutable queue");
                    sender = (QueueSender) producers.get(RoutingSwiftletImpl.UNROUTABLE_QUEUE);
                    msg.setStringProperty(MessageImpl.PROP_UNROUTABLE_REASON, e.toString());
                    QueuePushTransaction t = tx.getTransaction(RoutingSwiftletImpl.UNROUTABLE_QUEUE);
                    if (t == null) {
                        t = sender.createTransaction();
                        tx.addTransaction(RoutingSwiftletImpl.UNROUTABLE_QUEUE, t);
                    }
                    t.putMessage(msg);
                }
            }
        }
    }
    try {
        tx.prepare();
    } catch (Exception e) {
        tx.rollback();
        inboundTransactions.remove(xid);
        throw e;
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + " done");
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) XidImpl(com.swiftmq.jms.XidImpl) QueueSender(com.swiftmq.swiftlet.queue.QueueSender) MessageImpl(com.swiftmq.jms.MessageImpl) JMSException(javax.jms.JMSException) XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

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