Search in sources :

Example 21 with MessageIndex

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

the class SourceMessageProcessor method transformMessage.

private Delivery transformMessage(MessageEntry messageEntry) throws JMSException {
    try {
        MessageImpl message = sourceLink.isQueue ? messageEntry.getMessage() : copyMessage(messageEntry.getMessage());
        MessageIndex messageIndex = messageEntry.getMessageIndex();
        OutboundTransformer transformer = sourceLink.getTransformer();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/transformMessage, transformer=" + transformer);
        if (transformer == null)
            throw new JMSException("No outbound message transformer found!");
        Delivery delivery = new Delivery(sourceLink, message, messageIndex);
        transformer.transform(delivery);
        return delivery;
    } catch (Exception e) {
        e.printStackTrace();
        throw new JMSException(e.toString());
    }
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex) OutboundTransformer(com.swiftmq.impl.amqp.amqp.v01_00_00.transformer.OutboundTransformer) JMSException(javax.jms.JMSException) MessageImpl(com.swiftmq.jms.MessageImpl) JMSException(javax.jms.JMSException)

Example 22 with MessageIndex

use of com.swiftmq.swiftlet.queue.MessageIndex 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);
    }
    if (ctx.ackMode == javax.jms.Session.CLIENT_ACKNOWLEDGE) {
        Map ackConsumers = new HashMap();
        for (Iterator iter = deliveredList.iterator(); iter.hasNext(); ) {
            MessageDeliveredRequest request = (MessageDeliveredRequest) iter.next();
            Consumer consumer = (Consumer) consumerList.get(request.getQueueConsumerId());
            MessageIndex actIndex = request.getMessageIndex();
            QueuePullTransaction t = consumer.getTransaction();
            ConsumerAckEntry ackEntry = (ConsumerAckEntry) ackConsumers.get(consumer);
            if (ackEntry == null) {
                ackEntry = new ConsumerAckEntry(t);
                ackConsumers.put(consumer, ackEntry);
            }
            ackEntry.ackList.add(actIndex);
        }
        deliveredList.clear();
        boolean callbackRegistered = false;
        MultiAckJoin join = new MultiAckJoin(reply);
        for (Iterator iter = ackConsumers.entrySet().iterator(); iter.hasNext(); ) {
            Map.Entry entry = (Map.Entry) iter.next();
            Consumer consumer = (Consumer) entry.getKey();
            ConsumerAckEntry ackEntry = (ConsumerAckEntry) entry.getValue();
            try {
                join.incNumberCallbacks();
                ackEntry.transaction.acknowledgeMessages(ackEntry.ackList, new MultiAckCallback(join, consumer, ackEntry.ackList.size()));
                callbackRegistered = true;
            } catch (QueueTransactionClosedException e) {
            }
        }
        join.setBlocked(false);
        if (!callbackRegistered && reply != null)
            reply.send();
    } else {
        MessageIndex ackIndex = req.getMessageIndex();
        Consumer consumer = (Consumer) consumerList.get(req.getQueueConsumerId());
        ackSingleMessage(reply, ackIndex, consumer);
    }
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex) QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction)

Example 23 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();
    if (request.getConnectionId() != mySession.myConnection.getConnectionId()) {
        if (MessageTracker.enabled) {
            MessageTracker.getInstance().track(request.getMessageEntry().getMessage(), new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, invalid connectionId (" + request.getConnectionId() + " vs " + mySession.myConnection.getConnectionId() + ")");
        }
        return;
    }
    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);
    String id = null;
    boolean duplicate = false;
    if (recordLog) {
        id = SessionImpl.buildId(uniqueConsumerId, msg);
        duplicate = mySession.myConnection.isDuplicateMessageDetection() && mySession.isDuplicate(id);
    }
    if (MessageTracker.enabled) {
        MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, duplicate=" + duplicate);
    }
    if (reportDelivered)
        reportDelivered(msg, false);
    try {
        if (!duplicate) {
            if (recordLog && mySession.myConnection.isDuplicateMessageDetection())
                mySession.addCurrentTxLog(id);
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, onMessage...");
            }
            mySession.withinOnMessage = true;
            mySession.onMessageMessage = msg;
            mySession.onMessageConsumer = this;
            mySession.setTxCancelled(false);
            messageListener.onMessage(msg);
            mySession.onMessageMessage = null;
            mySession.onMessageConsumer = null;
            mySession.withinOnMessage = false;
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, onMessage ok");
            }
            if (mySession.isTxCancelled() || mySession.acknowledgeMode == Session.CLIENT_ACKNOWLEDGE && msg.isCancelled()) {
                if (MessageTracker.enabled) {
                    MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "tx was cancelled, return!");
                }
                wasRecovered = false;
                return;
            }
        }
    } catch (RuntimeException e) {
        if (MessageTracker.enabled) {
            MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, exception=" + 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 {
                if (MessageTracker.enabled) {
                    MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, ack");
                }
                boolean cancelled = acknowledgeMessage(msgIndex, false);
                if (MessageTracker.enabled) {
                    MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, ack, cancelled=" + cancelled);
                }
            } 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 24 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();
    if (request.getConnectionId() != mySession.myConnection.getConnectionId()) {
        if (MessageTracker.enabled) {
            MessageTracker.getInstance().track(request.getMessageEntry().getMessage(), new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, invalid connectionId (" + request.getConnectionId() + " vs " + mySession.myConnection.getConnectionId() + ")");
        }
        return;
    }
    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);
    String id = null;
    boolean duplicate = false;
    if (recordLog) {
        id = SessionImpl.buildId(uniqueConsumerId, msg);
        duplicate = mySession.myConnection.isDuplicateMessageDetection() && mySession.isDuplicate(id);
    }
    if (MessageTracker.enabled) {
        MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, duplicate=" + duplicate);
    }
    if (reportDelivered)
        reportDelivered(msg, false);
    try {
        if (!duplicate) {
            if (recordLog && mySession.myConnection.isDuplicateMessageDetection())
                mySession.addCurrentTxLog(id);
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, onMessage...");
            }
            mySession.withinOnMessage = true;
            mySession.onMessageMessage = msg;
            mySession.setTxCancelled(false);
            messageListener.onMessage(msg);
            mySession.onMessageMessage = null;
            mySession.withinOnMessage = false;
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, onMessage ok");
            }
            if (mySession.isTxCancelled() || mySession.acknowledgeMode == Session.CLIENT_ACKNOWLEDGE && msg.isCancelled()) {
                if (MessageTracker.enabled) {
                    MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "tx was cancelled, return!");
                }
                wasRecovered = false;
                return;
            }
        }
    } catch (RuntimeException e) {
        if (MessageTracker.enabled) {
            MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, exception=" + 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 {
                if (MessageTracker.enabled) {
                    MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, ack");
                }
                boolean cancelled = acknowledgeMessage(msgIndex, false);
                if (MessageTracker.enabled) {
                    MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, ack, cancelled=" + cancelled);
                }
            } 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 25 with MessageIndex

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

the class MessageConsumerImpl method reportDelivered.

private void reportDelivered(Message message, boolean duplicate) {
    try {
        MessageIndex messageIndex = ((MessageImpl) message).getMessageIndex();
        requestRegistry.request(new MessageDeliveredRequest(this, mySession.dispatchId, serverQueueConsumerId, messageIndex, duplicate));
    } catch (Exception e) {
    }
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex) MessageImpl(com.swiftmq.jms.MessageImpl)

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