Search in sources :

Example 21 with QueuePullTransaction

use of com.swiftmq.swiftlet.queue.QueuePullTransaction in project swiftmq-ce by iitsoftware.

the class Session method visit.

public void visit(MessageDeliveredRequest req) {
    if (closed || recoveryInProgress)
        return;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitMessageDeliveredRequest");
    try {
        Consumer consumer = (Consumer) consumerList.get(req.getQueueConsumerId());
        QueuePullTransaction rt = (QueuePullTransaction) consumer.getReadTransaction();
        // Duplicates are immediately deleted
        if (req.isDuplicate()) {
            QueuePullTransaction t = (QueuePullTransaction) consumer.createDuplicateTransaction();
            t.moveToTransaction(req.getMessageIndex(), rt);
            t.commit();
        } else {
            QueuePullTransaction t = (QueuePullTransaction) consumer.getTransaction();
            t.moveToTransaction(req.getMessageIndex(), rt);
        }
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitMessageDeliveredRequest, exception=" + e);
    }
}
Also used : QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction)

Example 22 with QueuePullTransaction

use of com.swiftmq.swiftlet.queue.QueuePullTransaction in project swiftmq-ce by iitsoftware.

the class Session method visit.

public void visit(MessageDeliveredRequest req) {
    if (closed || recoveryInProgress)
        return;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitMessageDeliveredRequest");
    try {
        Consumer consumer = (Consumer) consumerList.get(req.getQueueConsumerId());
        QueuePullTransaction rt = (QueuePullTransaction) consumer.getReadTransaction();
        // Duplicates are immediately deleted
        if (req.isDuplicate()) {
            QueuePullTransaction t = (QueuePullTransaction) consumer.createDuplicateTransaction();
            t.moveToTransaction(req.getMessageIndex(), rt);
            t.commit();
        } else {
            QueuePullTransaction t = (QueuePullTransaction) consumer.getTransaction();
            t.moveToTransaction(req.getMessageIndex(), rt);
        }
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitMessageDeliveredRequest, exception=" + e);
    }
}
Also used : QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction)

Example 23 with QueuePullTransaction

use of com.swiftmq.swiftlet.queue.QueuePullTransaction in project swiftmq-ce by iitsoftware.

the class NontransactedSession method visitAcknowledgeMessageRequest.

public void visitAcknowledgeMessageRequest(AcknowledgeMessageRequest req) {
    if (closed)
        return;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitAcknowledgeMessageRequest");
    AcknowledgeMessageReply reply = null;
    if (req.isReplyRequired()) {
        reply = (AcknowledgeMessageReply) req.createReply();
        reply.setOk(true);
    }
    try {
        MessageIndex ackIndex = req.getMessageIndex();
        if (ctx.ackMode == javax.jms.Session.CLIENT_ACKNOWLEDGE) {
            boolean found = false;
            Iterator iter = deliveredList.iterator();
            while (iter.hasNext()) {
                MessageDeliveredRequest request = (MessageDeliveredRequest) iter.next();
                Consumer consumer = (Consumer) consumerList.get(request.getQueueConsumerId());
                MessageIndex actIndex = request.getMessageIndex();
                QueuePullTransaction t = (QueuePullTransaction) consumer.getTransaction();
                try {
                    if (!t.isClosed())
                        t.acknowledgeMessage(actIndex);
                } catch (Exception e) {
                // temp queue might be deleted in the mean time
                }
                iter.remove();
            }
        } else {
            Consumer consumer = (Consumer) consumerList.get(req.getQueueConsumerId());
            QueuePullTransaction t = (QueuePullTransaction) consumer.getReadTransaction();
            try {
                if (!t.isClosed())
                    t.acknowledgeMessage(ackIndex);
            } catch (Exception e) {
            // temp queue might be deleted in the mean time
            }
        }
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitAcknowledgeMessageRequest, exception: " + e);
        if (reply != null) {
            reply.setOk(false);
            reply.setException(new javax.jms.JMSException(e.toString()));
        }
    }
    if (reply != null)
        reply.send();
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex) Iterator(java.util.Iterator) QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction)

Example 24 with QueuePullTransaction

use of com.swiftmq.swiftlet.queue.QueuePullTransaction in project swiftmq-ce by iitsoftware.

the class Session method visitStartConsumerRequest.

public void visitStartConsumerRequest(StartConsumerRequest req) {
    if (closed)
        return;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitStartConsumerRequest");
    int qcId = req.getQueueConsumerId();
    Consumer consumer = (Consumer) consumerList.get(qcId);
    if (consumer == null)
        return;
    int clientDispatchId = req.getClientDispatchId();
    int clientListenerId = req.getClientListenerId();
    try {
        MessageProcessor mp = consumer.getMessageProcessor();
        if (mp == null) {
            mp = new AsyncMessageProcessor(this, ctx, consumer, req.getConsumerCacheSize(), recoveryEpoche);
            consumer.setMessageListener(clientDispatchId, clientListenerId, mp);
        }
        QueuePullTransaction t = consumer.getReadTransaction();
        if (t != null && !t.isClosed())
            t.registerMessageProcessor(mp);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MessageProcessor(com.swiftmq.swiftlet.queue.MessageProcessor) QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction)

Example 25 with QueuePullTransaction

use of com.swiftmq.swiftlet.queue.QueuePullTransaction in project swiftmq-ce by iitsoftware.

the class XADeliveryStage method close.

public void close() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close ...");
    super.close();
    closed = true;
    if (notificationList.size() > 0) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, final notify ...");
        for (Iterator iter = notificationList.entrySet().iterator(); iter.hasNext(); ) {
            Map.Entry entry = (Map.Entry) iter.next();
            DeliveryRequest dr = (DeliveryRequest) entry.getValue();
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, final notify: " + dr);
            dr.callback.delivered(dr);
        }
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, final notify done");
        notificationList.clear();
    }
    if (outboundTransactions.size() > 0) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared outbound tx to XAResourceManager ...");
        for (Iterator iter = outboundTransactions.entrySet().iterator(); iter.hasNext(); ) {
            try {
                Map.Entry entry = (Map.Entry) iter.next();
                XidImpl xid = (XidImpl) entry.getKey();
                XAContext xac = ctx.xaResourceManagerSwiftlet.createXAContext(xid);
                int id = xac.register(toString());
                QueuePullTransaction t = (QueuePullTransaction) entry.getValue();
                xac.addTransaction(id, t.getQueueName(), t);
                xac.unregister(id, false);
                xac.setPrepared(true);
            } catch (XAContextException e) {
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared outbound tx to XAResourceManager, exception: " + e);
            }
        }
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared outbound tx to XAResourceManager done");
        outboundTransactions.clear();
    }
    if (inboundTransactions.size() > 0) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared inbound tx to XAResourceManager ...");
        for (Iterator iter = inboundTransactions.entrySet().iterator(); iter.hasNext(); ) {
            ((Tx) ((Map.Entry) iter.next()).getValue()).handOver();
        }
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared inbound tx to XAResourceManager done");
    }
    for (Iterator iter = producers.entrySet().iterator(); iter.hasNext(); ) {
        QueueSender sender = (QueueSender) ((Map.Entry) iter.next()).getValue();
        try {
            sender.close();
        } catch (Exception e) {
        }
    }
    producers.clear();
    for (Iterator iter = consumers.entrySet().iterator(); iter.hasNext(); ) {
        QueueReceiver receiver = (QueueReceiver) ((Map.Entry) iter.next()).getValue();
        try {
            receiver.close();
        } catch (Exception e) {
        }
    }
    consumers.clear();
    if (throttleQueue != null)
        throttleQueue.close();
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.START_STAGE_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.SEND_ROUTE_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.DELIVERY_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.ROUTE_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.ADJUST_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.TRANSACTION_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.COMMIT_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.COMMIT_REPREQ, null);
}
Also used : XAContext(com.swiftmq.swiftlet.xa.XAContext) XidImpl(com.swiftmq.jms.XidImpl) QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction) JMSException(javax.jms.JMSException) XAContextException(com.swiftmq.swiftlet.xa.XAContextException) QueueSender(com.swiftmq.swiftlet.queue.QueueSender) QueueReceiver(com.swiftmq.swiftlet.queue.QueueReceiver) XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

Aggregations

QueuePullTransaction (com.swiftmq.swiftlet.queue.QueuePullTransaction)26 MessageIndex (com.swiftmq.swiftlet.queue.MessageIndex)7 Iterator (java.util.Iterator)6 QueueReceiver (com.swiftmq.swiftlet.queue.QueueReceiver)5 XidImpl (com.swiftmq.jms.XidImpl)4 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)4 JMSException (javax.jms.JMSException)4 MessageImpl (com.swiftmq.jms.MessageImpl)3 MessageProcessor (com.swiftmq.swiftlet.queue.MessageProcessor)3 QueueSender (com.swiftmq.swiftlet.queue.QueueSender)2 XAContext (com.swiftmq.swiftlet.xa.XAContext)2 Request (com.swiftmq.tools.requestreply.Request)2 InvalidDestinationException (javax.jms.InvalidDestinationException)2 POSendMessage (com.swiftmq.impl.mqtt.po.POSendMessage)1 MqttQoS (com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttQoS)1 TopicImpl (com.swiftmq.jms.TopicImpl)1 MessageSelector (com.swiftmq.ms.MessageSelector)1 MessageEntry (com.swiftmq.swiftlet.queue.MessageEntry)1 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)1 XStream (com.thoughtworks.xstream.XStream)1