Search in sources :

Example 1 with MessageEntry

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

the class SMQPUtil method read.

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

Example 2 with MessageEntry

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

the class SourceMessageProcessor method getTransformedMessages.

public Delivery[] getTransformedMessages() throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/getTransformedMessages ...");
    MessageEntry[] buffer = getBulkBuffer();
    Delivery[] deliveries = new Delivery[numberMessages];
    for (int i = 0; i < numberMessages; i++) {
        MessageEntry messageEntry = buffer[i];
        Delivery delivery = outboundTransformer.transform(messageEntry.getMessage());
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/getTransformedMessages, delivery=" + delivery);
        delivery.setRedelivered(messageEntry.getMessageIndex().getDeliveryCount() > 1);
        delivery.setMessageIndex(messageEntry.getMessageIndex());
        deliveries[i] = delivery;
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/getTransformedMessages, deliveries.length=" + deliveries.length);
    return deliveries;
}
Also used : MessageEntry(com.swiftmq.swiftlet.queue.MessageEntry)

Example 3 with MessageEntry

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

the class ConnectionConsumerImpl method processRequest.

public void processRequest(AsyncMessageDeliveryRequest request, boolean hasNext) {
    if (resetInProgress || deliveryQueue.isCurrentCallInvalid()) {
        if (MessageTracker.enabled) {
            MessageTracker.getInstance().track(((AsyncMessageDeliveryRequest) request).getMessageEntry().getMessage(), new String[] { myConnection.toString(), toString() }, "processRequest, resetInProgress || currentCallInvalid, return");
        }
        return;
    }
    if (request.getConnectionId() != myConnection.getConnectionId()) {
        if (MessageTracker.enabled) {
            MessageTracker.getInstance().track(((AsyncMessageDeliveryRequest) request).getMessageEntry().getMessage(), new String[] { myConnection.toString(), toString() }, "processRequest, invalid connectionId (" + request.getConnectionId() + " vs " + myConnection.getConnectionId() + ")");
        }
        return;
    }
    try {
        if (currentServerSession == null) {
            currentServerSession = serverSessionPool.getServerSession();
            if (currentServerSession.getSession() instanceof XASessionImpl)
                currentSession = ((XASessionImpl) currentServerSession.getSession()).session;
            else
                currentSession = (SessionImpl) currentServerSession.getSession();
            nCurrent = 0;
            if (!currentSession.isShadowConsumerCreated())
                currentSession.createShadowConsumer(getQueueName());
            currentSession.setConnectionConsumer(this);
            if (resetInProgress || deliveryQueue.isCurrentCallInvalid()) {
                if (MessageTracker.enabled) {
                    MessageTracker.getInstance().track(((AsyncMessageDeliveryRequest) request).getMessageEntry().getMessage(), new String[] { myConnection.toString(), toString() }, "processRequest, resetInProgress || currentCallInvalid, return (2)");
                }
                return;
            }
        }
        if (MessageTracker.enabled) {
            MessageTracker.getInstance().track(((AsyncMessageDeliveryRequest) request).getMessageEntry().getMessage(), new String[] { myConnection.toString(), toString() }, "processRequest, " + request.getConnectionId() + " / " + myConnection.getConnectionId());
        }
        MessageEntry me = request.getMessageEntry();
        checkInProgress(me.getMessage());
        if (resetInProgress || deliveryQueue.isCurrentCallInvalid()) {
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track(((AsyncMessageDeliveryRequest) request).getMessageEntry().getMessage(), new String[] { myConnection.toString(), toString() }, "processRequest, resetInProgress || currentCallInvalid, return (3)");
            }
            return;
        }
        me.setConnectionId(request.getConnectionId());
        currentSession.addMessageChunk(me);
        nCurrent++;
        if (nCurrent == maxMessages || !hasNext) {
            currentServerSession.start();
            currentServerSession = null;
            currentSession = null;
            nCurrent = 0;
        }
    } catch (Exception e) {
        e.printStackTrace();
    // TODO: Handle it some way like InvalidateConsumerRequest!!!
    }
    if (request.isRequiresRestart())
        fillCache();
}
Also used : MessageEntry(com.swiftmq.swiftlet.queue.MessageEntry) AsyncMessageDeliveryRequest(com.swiftmq.jms.smqp.v630.AsyncMessageDeliveryRequest) JMSException(javax.jms.JMSException)

Example 4 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;
    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);
                    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 5 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.setTxCancelled(false);
            messageListener.onMessage(msg);
            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