Search in sources :

Example 36 with MessageEntry

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

the class CacheImpl method put.

public void put(StoreId storeId, MessageImpl message) throws Exception {
    long msgSize = message.getMessageLength();
    storeId.setMsgSize(msgSize);
    if (cacheTable.size() < maxMessages && currentBytes + msgSize < maxBytes) {
        cacheTable.put(storeId, new MessageEntry(storeId, message));
        currentBytes += msgSize;
    } else {
        // rollback, it is!)
        if (!storeId.isPersistent() && cacheTable.get(storeId) == null) {
            StoreEntry se = new StoreEntry();
            se.priority = storeId.getPriority();
            se.deliveryCount = storeId.getDeliveryCount();
            se.expirationTime = storeId.getExpirationTime();
            se.message = message;
            swapStore.insert(se);
            se.message = null;
            storeId.setPersistentKey(se);
        }
    }
}
Also used : StoreEntry(com.swiftmq.swiftlet.store.StoreEntry) MessageEntry(com.swiftmq.swiftlet.queue.MessageEntry)

Example 37 with MessageEntry

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

the class CacheImpl method get.

public MessageEntry get(StoreId storeId) throws Exception {
    MessageEntry me = (MessageEntry) cacheTable.get(storeId);
    if (me == null) {
        me = new MessageEntry();
        me.setMessageIndex(storeId);
        if (storeId.isPersistent())
            me.setMessage(((StoreEntry) pStore.get(((StoreEntry) storeId.getPersistentKey()).key)).message);
        else
            me.setMessage(((StoreEntry) swapStore.get(((StoreEntry) storeId.getPersistentKey()).key)).message);
        storeId.setMsgSize(me.getMessage().getMessageLength());
    }
    return me;
}
Also used : StoreEntry(com.swiftmq.swiftlet.store.StoreEntry) MessageEntry(com.swiftmq.swiftlet.queue.MessageEntry)

Example 38 with MessageEntry

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

the class Exporter method execute.

public String[] execute(String[] context, Entity entity, String[] cmd) {
    if (cmd.length < 3)
        return new String[] { TreeCommands.ERROR, "Invalid command, please try '" + TreeCommands.EXPORT + " <queuename> <localdir> [-remove] [-xml] [-selector <selector>]" };
    int nMsgs = 0;
    try {
        String queueName = cmd[1];
        String localDir = cmd[2];
        boolean delete = false;
        boolean xml = false;
        String selector = null;
        if (cmd.length > 3) {
            StringBuffer selBuffer = null;
            for (int i = 3; i < cmd.length; i++) {
                if (selBuffer != null) {
                    if (selBuffer.length() > 0)
                        selBuffer.append(' ');
                    selBuffer.append(cmd[i]);
                } else if (cmd[i].equals("-delete"))
                    delete = true;
                else if (cmd[i].equals("-xml"))
                    xml = true;
                else if (cmd[i].equals("-selector"))
                    selBuffer = new StringBuffer();
                else
                    throw new Exception("Invalid option: " + cmd[i]);
            }
            if (selBuffer != null)
                selector = selBuffer.toString();
        }
        XStream xStream = null;
        File outputDir = new File(localDir);
        if (!outputDir.exists()) {
            if (!outputDir.mkdir())
                throw new Exception("Unable to create output directory: " + localDir);
        }
        if (xml) {
            xStream = new XStream(new Dom4JDriver());
            xStream.allowTypesByWildcard(new String[] { ".*" });
        }
        MessageSelector msel = null;
        if (selector != null) {
            msel = new MessageSelector(selector);
            msel.compile();
        }
        QueueReceiver receiver = ctx.queueManager.createQueueReceiver(queueName, null, msel);
        QueuePullTransaction pullTx = receiver.createTransaction(false);
        try {
            MessageEntry entry = null;
            while ((entry = pullTx.getMessage(0, msel)) != null) {
                MessageImpl msg = delete ? entry.getMessage() : copyMessage(entry.getMessage());
                msg.clearSwiftMQAllProps();
                store(queueName, xStream, outputDir, nMsgs++, msg);
                if (delete) {
                    pullTx.commit();
                    pullTx = receiver.createTransaction(false);
                }
            }
        } finally {
            try {
                pullTx.rollback();
            } catch (Exception e) {
            }
            try {
                receiver.close();
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
        return new String[] { TreeCommands.ERROR, e.getMessage() };
    }
    return new String[] { TreeCommands.INFO, nMsgs + " messages exported." };
}
Also used : XStream(com.thoughtworks.xstream.XStream) Dom4JDriver(com.thoughtworks.xstream.io.xml.Dom4JDriver) QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction) QueueReceiver(com.swiftmq.swiftlet.queue.QueueReceiver) MessageEntry(com.swiftmq.swiftlet.queue.MessageEntry) MessageSelector(com.swiftmq.ms.MessageSelector) File(java.io.File) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 39 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.v610.AsyncMessageDeliveryRequest) JMSException(javax.jms.JMSException)

Example 40 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)

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