Search in sources :

Example 16 with QueuePullTransaction

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

the class NontransactedSession method visit.

public void visit(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 = 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 = 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(e);
        }
    }
    if (reply != null)
        reply.send();
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex) Iterator(java.util.Iterator) QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction)

Example 17 with QueuePullTransaction

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

the class Session method visitMessageDeliveredRequest.

public void visitMessageDeliveredRequest(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();
        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);
        e.printStackTrace();
    }
}
Also used : QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction)

Example 18 with QueuePullTransaction

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

the class Exporter method execute.

public String[] execute(String[] context, Entity entity, String[] cmd) {
    if (cmd.length < 3)
        return new String[] { TreeCommands.ERROR, "Invalid command, please try '" + TreeCommands.EXPORT + " <queuename> <localdir> [-remove] [-xml] [-selector <selector>]" };
    int nMsgs = 0;
    try {
        String queueName = cmd[1];
        String localDir = cmd[2];
        boolean delete = false;
        boolean xml = false;
        String selector = null;
        if (cmd.length > 3) {
            StringBuffer selBuffer = null;
            for (int i = 3; i < cmd.length; i++) {
                if (selBuffer != null) {
                    if (selBuffer.length() > 0)
                        selBuffer.append(' ');
                    selBuffer.append(cmd[i]);
                } else if (cmd[i].equals("-delete"))
                    delete = true;
                else if (cmd[i].equals("-xml"))
                    xml = true;
                else if (cmd[i].equals("-selector"))
                    selBuffer = new StringBuffer();
                else
                    throw new Exception("Invalid option: " + cmd[i]);
            }
            if (selBuffer != null)
                selector = selBuffer.toString();
        }
        XStream xStream = null;
        File outputDir = new File(localDir);
        if (!outputDir.exists()) {
            if (!outputDir.mkdir())
                throw new Exception("Unable to create output directory: " + localDir);
        }
        if (xml) {
            xStream = new XStream(new Dom4JDriver());
            xStream.allowTypesByWildcard(new String[] { ".*" });
        }
        MessageSelector msel = null;
        if (selector != null) {
            msel = new MessageSelector(selector);
            msel.compile();
        }
        QueueReceiver receiver = ctx.queueManager.createQueueReceiver(queueName, null, msel);
        QueuePullTransaction pullTx = receiver.createTransaction(false);
        try {
            MessageEntry entry = null;
            while ((entry = pullTx.getMessage(0, msel)) != null) {
                MessageImpl msg = delete ? entry.getMessage() : copyMessage(entry.getMessage());
                msg.clearSwiftMQAllProps();
                store(queueName, xStream, outputDir, nMsgs++, msg);
                if (delete) {
                    pullTx.commit();
                    pullTx = receiver.createTransaction(false);
                }
            }
        } finally {
            try {
                pullTx.rollback();
            } catch (Exception e) {
            }
            try {
                receiver.close();
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
        return new String[] { TreeCommands.ERROR, e.getMessage() };
    }
    return new String[] { TreeCommands.INFO, nMsgs + " messages exported." };
}
Also used : XStream(com.thoughtworks.xstream.XStream) Dom4JDriver(com.thoughtworks.xstream.io.xml.Dom4JDriver) QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction) QueueReceiver(com.swiftmq.swiftlet.queue.QueueReceiver) MessageEntry(com.swiftmq.swiftlet.queue.MessageEntry) MessageSelector(com.swiftmq.ms.MessageSelector) File(java.io.File) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 19 with QueuePullTransaction

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

the class Subscription method processMessage.

@Override
public void processMessage(MessageEntry messageEntry) {
    try {
        QueuePullTransaction tx = consumer.createTransaction();
        tx.moveToTransaction(messageEntry.getMessageIndex(), readTx);
        String jmsTopicName = ((TopicImpl) messageEntry.getMessage().getJMSDestination()).getTopicName();
        MqttQoS mqos = MqttQoS.valueOf(qos.value());
        if (messageEntry.getMessage().propertyExists(Producer.PROP_QOS)) {
            int pqos = messageEntry.getMessage().getIntProperty(Producer.PROP_QOS);
            int sqos = qos.value();
            if (sqos > pqos)
                mqos = MqttQoS.valueOf(pqos);
        }
        session.getMqttConnection().getConnectionQueue().enqueue(new POSendMessage(jmsTopicName, messageEntry.getMessage(), mqos, tx, this));
        incMsgsReceived(1);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : POSendMessage(com.swiftmq.impl.mqtt.po.POSendMessage) QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction) TopicImpl(com.swiftmq.jms.TopicImpl) MqttQoS(com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttQoS)

Example 20 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) InvalidDestinationException(javax.jms.InvalidDestinationException)

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