Search in sources :

Example 21 with MessageEntry

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

the class ViewCollector method next.

public ViewEntry next() throws Exception {
    ViewEntry viewEntry = null;
    MessageEntry messageEntry = null;
    for (int i = index; i < collected.size(); i++) {
        messageEntry = abstractQueue.getMessageByIndex(collected.get(i));
        if (messageEntry != null) {
            viewEntry = new ViewEntry(messageEntry, from + i);
            index = i + 1;
            break;
        }
    }
    return viewEntry;
}
Also used : MessageEntry(com.swiftmq.swiftlet.queue.MessageEntry)

Example 22 with MessageEntry

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

the class BrowserManager method fetchBrowserMessage.

public void fetchBrowserMessage(FetchBrowserMessageRequest request) {
    FetchBrowserMessageReply reply = (FetchBrowserMessageReply) request.createReply();
    int browserId = request.getQueueBrowserId();
    try {
        com.swiftmq.swiftlet.queue.QueueBrowser browser = (com.swiftmq.swiftlet.queue.QueueBrowser) queueBrowsers.get(browserId);
        if (request.isResetRequired())
            browser.resetBrowser();
        browser.setLastMessageIndex(request.getLastMessageIndex());
        MessageEntry me = (MessageEntry) browser.getNextMessage();
        reply.setOk(true);
        reply.setMessageEntry(me);
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": get next message failed: " + e.getMessage());
        reply.setOk(false);
        reply.setException(e);
    }
    reply.send();
}
Also used : MessageEntry(com.swiftmq.swiftlet.queue.MessageEntry) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException)

Example 23 with MessageEntry

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

the class MessageConsumerImpl method receiveMessage.

synchronized Message receiveMessage(boolean block, long timeout) throws JMSException {
    verifyState();
    if (messageListener != null) {
        throw new JMSException("receive not allowed while a message listener has been set");
    }
    boolean wasDuplicate = false;
    boolean wasInvalidConnectionId = false;
    MessageImpl msg = null;
    String id = null;
    do {
        wasDuplicate = false;
        wasInvalidConnectionId = false;
        if (!consumerStarted)
            fillCache();
        do {
            if (messageCache.getSize() == 0) {
                if (block) {
                    receiverWaiting = true;
                    if (timeout == 0) {
                        UninterruptableWaiter.doWait(this);
                    } else {
                        long to = timeout;
                        do {
                            long startWait = System.currentTimeMillis();
                            UninterruptableWaiter.doWait(this, to);
                            long delta = System.currentTimeMillis() - startWait;
                            to -= delta;
                        } while (to > 0 && messageCache.getSize() == 0 && fillCachePending && !cancelled && !isClosed());
                    }
                } else {
                    if (fillCachePending && receiveNoWaitFirstCall) {
                        receiverWaiting = true;
                        UninterruptableWaiter.doWait(this, 1000);
                    }
                }
                if (cancelled)
                    return null;
            }
        } while (mySession.resetInProgress);
        receiverWaiting = false;
        if (messageCache.getSize() == 0 || isClosed())
            return null;
        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() }, "receiveMessage, invalid connectionId (" + request.getConnectionId() + " vs " + mySession.myConnection.getConnectionId() + ")");
            }
            wasInvalidConnectionId = true;
        } else {
            MessageEntry messageEntry = request.getMessageEntry();
            msg = messageEntry.getMessage();
            messageEntry.moveMessageAttributes();
            msg.setMessageConsumerImpl(this);
            msg.reset();
            msg.setReadOnly(true);
            msg.setUseThreadContextCL(useThreadContextCL);
            if (request.isRequiresRestart())
                fillCache();
            if (recordLog) {
                id = SessionImpl.buildId(uniqueConsumerId, msg);
                wasDuplicate = mySession.myConnection.isDuplicateMessageDetection() && mySession.isDuplicate(id);
            }
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "receivedMessage, duplicate=" + wasDuplicate);
            }
            if (reportDelivered)
                reportDelivered(msg, false);
            if (doAck) {
                try {
                    if (MessageTracker.enabled) {
                        MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "receivedMessage, ack...");
                    }
                    boolean cancelled = acknowledgeMessage(msg.getMessageIndex(), false);
                    if (MessageTracker.enabled) {
                        MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "receivedMessage, ack, cancelled=" + cancelled);
                    }
                } catch (JMSException e) {
                }
            }
            if (wasDuplicate) {
                msg = null;
            }
        }
    } while (wasDuplicate || wasInvalidConnectionId);
    if (recordLog && mySession.myConnection.isDuplicateMessageDetection())
        mySession.addCurrentTxLog(id);
    return msg;
}
Also used : MessageEntry(com.swiftmq.swiftlet.queue.MessageEntry) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 24 with MessageEntry

use of com.swiftmq.swiftlet.queue.MessageEntry 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 25 with MessageEntry

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

Aggregations

MessageEntry (com.swiftmq.swiftlet.queue.MessageEntry)44 MessageImpl (com.swiftmq.jms.MessageImpl)15 JMSException (javax.jms.JMSException)11 MessageIndex (com.swiftmq.swiftlet.queue.MessageIndex)7 InvalidDestinationException (javax.jms.InvalidDestinationException)7 InvalidSelectorException (javax.jms.InvalidSelectorException)7 StoreEntry (com.swiftmq.swiftlet.store.StoreEntry)2 AsyncMessageDeliveryRequest (com.swiftmq.jms.smqp.v600.AsyncMessageDeliveryRequest)1 AsyncMessageDeliveryRequest (com.swiftmq.jms.smqp.v610.AsyncMessageDeliveryRequest)1 AsyncMessageDeliveryRequest (com.swiftmq.jms.smqp.v630.AsyncMessageDeliveryRequest)1 AsyncMessageDeliveryRequest (com.swiftmq.jms.smqp.v750.AsyncMessageDeliveryRequest)1 MessageSelector (com.swiftmq.ms.MessageSelector)1 QueuePullTransaction (com.swiftmq.swiftlet.queue.QueuePullTransaction)1 QueueReceiver (com.swiftmq.swiftlet.queue.QueueReceiver)1 XStream (com.thoughtworks.xstream.XStream)1 Dom4JDriver (com.thoughtworks.xstream.io.xml.Dom4JDriver)1 File (java.io.File)1