Search in sources :

Example 71 with MessageImpl

use of com.swiftmq.jms.MessageImpl 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;
    long to = timeout;
    do {
        wasDuplicate = false;
        wasInvalidConnectionId = false;
        if (!consumerStarted)
            fillCache();
        do {
            if (messageCache.getSize() == 0) {
                if (block) {
                    receiverWaiting = true;
                    if (timeout == 0) {
                        UninterruptableWaiter.doWait(this);
                        if (cancelled)
                            return null;
                    } else {
                        long startWait = System.currentTimeMillis();
                        UninterruptableWaiter.doWait(this, to);
                        to -= System.currentTimeMillis() - startWait;
                        if (to <= 0)
                            return null;
                    }
                } else {
                    if (fillCachePending && receiveNoWaitFirstCall) {
                        UninterruptableWaiter.doWait(this, 1000);
                    }
                }
            }
        } 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 72 with MessageImpl

use of com.swiftmq.jms.MessageImpl 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)

Example 73 with MessageImpl

use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.

the class StreamLibDeployer method sendReply.

private void sendReply(QueueImpl replyTo, boolean rc) throws JMSException {
    QueueSender sender = ctx.queueManager.createQueueSender(replyTo.getQueueName(), (ActiveLogin) null);
    QueuePushTransaction pushTx = sender.createTransaction();
    MessageImpl reply = new MessageImpl();
    reply.setBooleanProperty("success", rc);
    reply.setJMSDestination(replyTo);
    pushTx.putMessage(reply);
    pushTx.commit();
    sender.close();
}
Also used : BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 74 with MessageImpl

use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.

the class QueueWireTapInput method start.

@Override
public void start() throws Exception {
    if (selector != null) {
        messageSelector = new MessageSelector(selector);
        messageSelector.compile();
    }
    queue = new ArrayBlockingQueue<MessageImpl>(bufferSize);
    AbstractQueue queue = ctx.ctx.queueManager.getQueueForInternalUse(destinationName);
    if (queue == null)
        throw new Exception("Queue '" + destinationName + "' is undefined!");
    queue.addWireTapSubscriber(name, this);
    started = true;
}
Also used : AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) MessageSelector(com.swiftmq.ms.MessageSelector) MessageImpl(com.swiftmq.jms.MessageImpl) EntityRemoveException(com.swiftmq.mgmt.EntityRemoveException)

Example 75 with MessageImpl

use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.

the class QueueMemory method reload.

@Override
public void reload() throws Exception {
    List content = getContent();
    for (int i = 0; i < content.size(); i++) {
        MessageIndex messageIndex = (MessageIndex) content.get(i);
        MessageImpl message = abstractQueue.getMessageByIndex(messageIndex).getMessage();
        if (!shared || message.propertyExists(KEY) && message.getStringProperty(KEY).equals(name)) {
            String key = message.getJMSMessageID();
            long storeTime = message.getJMSTimestamp();
            messageStore.add(key, new KeyEntry(key, messageIndex, storeTime));
            addToIndexes(key, ctx.messageBuilder.wrap(message));
        }
    }
}
Also used : GapList(org.magicwerk.brownies.collections.GapList) MessageImpl(com.swiftmq.jms.MessageImpl)

Aggregations

MessageImpl (com.swiftmq.jms.MessageImpl)106 JMSException (javax.jms.JMSException)42 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)33 InvalidSelectorException (javax.jms.InvalidSelectorException)31 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)28 QueueImpl (com.swiftmq.jms.QueueImpl)21 DataByteArrayInputStream (com.swiftmq.tools.util.DataByteArrayInputStream)20 TopicImpl (com.swiftmq.jms.TopicImpl)17 MessageEntry (com.swiftmq.swiftlet.queue.MessageEntry)15 MessageIndex (com.swiftmq.swiftlet.queue.MessageIndex)15 RingBuffer (com.swiftmq.tools.collection.RingBuffer)14 InvalidDestinationException (javax.jms.InvalidDestinationException)14 List (java.util.List)13 EntityList (com.swiftmq.mgmt.EntityList)10 Message (javax.jms.Message)10 XidImpl (com.swiftmq.jms.XidImpl)6 DataByteArrayOutputStream (com.swiftmq.tools.util.DataByteArrayOutputStream)6 MessageSelector (com.swiftmq.ms.MessageSelector)5 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)4 ArrayList (java.util.ArrayList)4