Search in sources :

Example 11 with MessageIndex

use of com.swiftmq.swiftlet.queue.MessageIndex in project swiftmq-client by iitsoftware.

the class MessageConsumerImpl method invokeMessageListener.

private void invokeMessageListener() {
    if (isClosed())
        return;
    AsyncMessageDeliveryRequest request = (AsyncMessageDeliveryRequest) messageCache.remove();
    MessageEntry messageEntry = request.getMessageEntry();
    MessageImpl msg = messageEntry.getMessage();
    messageEntry.moveMessageAttributes();
    MessageIndex msgIndex = msg.getMessageIndex();
    msg.setMessageConsumerImpl(this);
    try {
        msg.reset();
    } catch (JMSException e) {
        e.printStackTrace();
    }
    msg.setReadOnly(true);
    msg.setUseThreadContextCL(useThreadContextCL);
    if (reportDelivered)
        reportDelivered(msg);
    try {
        messageListener.onMessage(msg);
    } catch (RuntimeException e) {
        System.err.println("ERROR! MessageListener throws RuntimeException, shutting down consumer!");
        e.printStackTrace();
        try {
            close(e.toString());
        } catch (JMSException e1) {
        }
        return;
    }
    if (!wasRecovered) {
        if (request.isRequiresRestart())
            fillCache();
        if (doAck) {
            try {
                acknowledgeMessage(msgIndex, false);
            } catch (JMSException e) {
            }
        }
    } else
        wasRecovered = false;
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex) MessageEntry(com.swiftmq.swiftlet.queue.MessageEntry) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 12 with MessageIndex

use of com.swiftmq.swiftlet.queue.MessageIndex in project swiftmq-client by iitsoftware.

the class MessageConsumerImpl method invokeMessageListener.

private void invokeMessageListener() {
    if (isClosed())
        return;
    AsyncMessageDeliveryRequest request = (AsyncMessageDeliveryRequest) messageCache.remove();
    MessageEntry messageEntry = request.getMessageEntry();
    MessageImpl msg = messageEntry.getMessage();
    messageEntry.moveMessageAttributes();
    MessageIndex msgIndex = msg.getMessageIndex();
    msg.setMessageConsumerImpl(this);
    try {
        msg.reset();
    } catch (JMSException e) {
        e.printStackTrace();
    }
    msg.setReadOnly(true);
    msg.setUseThreadContextCL(useThreadContextCL);
    if (reportDelivered)
        reportDelivered(msg);
    try {
        messageListener.onMessage(msg);
    } catch (RuntimeException e) {
        System.err.println("ERROR! MessageListener throws RuntimeException, shutting down consumer!");
        e.printStackTrace();
        try {
            close(e.toString());
        } catch (JMSException e1) {
        }
        return;
    }
    if (!wasRecovered) {
        if (request.isRequiresRestart())
            fillCache();
        if (doAck) {
            try {
                acknowledgeMessage(msgIndex, false);
            } catch (JMSException e) {
            }
        }
    } else
        wasRecovered = false;
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex) MessageEntry(com.swiftmq.swiftlet.queue.MessageEntry) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 13 with MessageIndex

use of com.swiftmq.swiftlet.queue.MessageIndex in project swiftmq-client by iitsoftware.

the class SMQPUtil method read.

static MessageIndex read(MessageIndex m, DataInput in) throws IOException {
    MessageIndex mi = new MessageIndex();
    mi.readContent(in);
    return mi;
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex)

Example 14 with MessageIndex

use of com.swiftmq.swiftlet.queue.MessageIndex in project swiftmq-client by iitsoftware.

the class SMQPUtil method read.

static MessageIndex read(MessageIndex m, DataInput in) throws IOException {
    MessageIndex mi = new MessageIndex();
    mi.readContent(in);
    return mi;
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex)

Example 15 with MessageIndex

use of com.swiftmq.swiftlet.queue.MessageIndex 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)

Aggregations

MessageIndex (com.swiftmq.swiftlet.queue.MessageIndex)35 MessageImpl (com.swiftmq.jms.MessageImpl)15 MessageEntry (com.swiftmq.swiftlet.queue.MessageEntry)7 QueuePullTransaction (com.swiftmq.swiftlet.queue.QueuePullTransaction)7 Iterator (java.util.Iterator)7 OutboundTransformer (com.swiftmq.impl.amqp.amqp.v01_00_00.transformer.OutboundTransformer)1 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)1 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)1 SortedSet (java.util.SortedSet)1 IllegalStateException (javax.jms.IllegalStateException)1 JMSException (javax.jms.JMSException)1