Search in sources :

Example 11 with MessageSelector

use of com.swiftmq.ms.MessageSelector in project swiftmq-ce by iitsoftware.

the class Viewer method createCollector.

private ViewCollector createCollector(String queueName, String selectorString, int from) throws Exception {
    if (!ctx.queueManager.isQueueDefined(queueName))
        throw new Exception("Unknown queue: " + queueName);
    MessageSelector selector = null;
    if (selectorString != null) {
        selector = new MessageSelector(selectorString);
        selector.compile();
    }
    return new ViewCollector(ctx.queueManager.getQueueForInternalUse(queueName), from, selector, MAX_RESULT);
}
Also used : MessageSelector(com.swiftmq.ms.MessageSelector) MessageEOFException(javax.jms.MessageEOFException)

Example 12 with MessageSelector

use of com.swiftmq.ms.MessageSelector in project swiftmq-ce by iitsoftware.

the class QueueMoverJob method start.

public void start(Properties properties, JobTerminationListener jobTerminationListener) throws JobException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " ...");
    this.properties = properties;
    int cnt = 0;
    String queueName = properties.getProperty("Source Queue");
    if (!queueName.startsWith("tpc$")) {
        MessageSelector selector = null;
        String s = properties.getProperty("Message Selector");
        if (s != null) {
            selector = new MessageSelector(s);
            try {
                selector.compile();
            } catch (InvalidSelectorException e) {
                throw new JobException(e.toString(), e, false);
            }
        }
        try {
            receiver = ctx.queueManager.createQueueReceiver(queueName, null, selector);
            pullTx = receiver.createTransaction(false);
            targetQueue = new QueueImpl(properties.getProperty("Target Queue"));
            sender = ctx.queueManager.createQueueSender(targetQueue.getQueueName(), null);
            pushTx = sender.createTransaction();
        } catch (Exception e) {
            throw new JobException(e.toString(), e, false);
        }
        if (stopCalled) {
            terminate();
            return;
        }
        try {
            MessageEntry entry = null;
            while ((entry = pullTx.getMessage(0, selector)) != null) {
                MessageImpl msg = entry.getMessage();
                msg.setJMSDestination(targetQueue);
                msg.setSourceRouter(null);
                msg.setDestRouter(null);
                pushTx.putMessage(msg);
                cnt++;
                pushTx.commit();
                pullTx.commit();
                if (stopCalled) {
                    terminate();
                    return;
                }
                pullTx = receiver.createTransaction(false);
                pushTx = sender.createTransaction();
            }
        } catch (Exception e) {
            terminate();
            throw new JobException(e.toString(), e, false);
        }
    }
    terminate();
    jobTerminationListener.jobTerminated(cnt + " Messages moved");
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " done, cnt=" + cnt);
}
Also used : JobException(com.swiftmq.swiftlet.scheduler.JobException) InvalidSelectorException(javax.jms.InvalidSelectorException) MessageSelector(com.swiftmq.ms.MessageSelector) MessageImpl(com.swiftmq.jms.MessageImpl) QueueImpl(com.swiftmq.jms.QueueImpl) InvalidSelectorException(javax.jms.InvalidSelectorException) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Example 13 with MessageSelector

use of com.swiftmq.ms.MessageSelector in project swiftmq-ce by iitsoftware.

the class QueuePurgerJob method start.

public void start(Properties properties, JobTerminationListener jobTerminationListener) throws JobException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " ...");
    this.properties = properties;
    int cnt = 0;
    String queueName = properties.getProperty("Queue Name");
    if (!queueName.startsWith("tpc$")) {
        MessageSelector selector = null;
        String s = properties.getProperty("Message Selector");
        if (s != null) {
            selector = new MessageSelector(s);
            try {
                selector.compile();
            } catch (InvalidSelectorException e) {
                throw new JobException(e.toString(), e, false);
            }
        }
        try {
            receiver = ctx.queueManager.createQueueReceiver(queueName, null, selector);
            transaction = receiver.createTransaction(false);
        } catch (Exception e) {
            throw new JobException(e.toString(), e, false);
        }
        if (stopCalled) {
            terminate();
            return;
        }
        try {
            while (transaction.getMessage(0, selector) != null) {
                cnt++;
                transaction.commit();
                if (stopCalled) {
                    terminate();
                    return;
                }
                transaction = receiver.createTransaction(false);
            }
        } catch (Exception e) {
            terminate();
            throw new JobException(e.toString(), e, false);
        }
    }
    terminate();
    jobTerminationListener.jobTerminated(cnt + " Messages purged");
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " done, cnt=" + cnt);
}
Also used : JobException(com.swiftmq.swiftlet.scheduler.JobException) InvalidSelectorException(javax.jms.InvalidSelectorException) MessageSelector(com.swiftmq.ms.MessageSelector) InvalidSelectorException(javax.jms.InvalidSelectorException) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Example 14 with MessageSelector

use of com.swiftmq.ms.MessageSelector in project swiftmq-ce by iitsoftware.

the class BrowserManager method createBrowser.

public void createBrowser(CreateBrowserRequest request) {
    CreateBrowserReply reply = (CreateBrowserReply) request.createReply();
    QueueImpl queue = request.getQueue();
    String messageSelector = request.getMessageSelector();
    MessageSelector msel = null;
    String queueName = null;
    try {
        queueName = queue.getQueueName();
    } catch (JMSException ignored) {
    }
    try {
        if (messageSelector != null) {
            msel = new MessageSelector(messageSelector);
            msel.compile();
        }
        if (!ctx.queueManager.isQueueRunning(queueName)) {
            ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": Invalid destination: " + queueName);
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Invalid destination: " + queue);
            reply.setOk(false);
            reply.setException(new InvalidDestinationException("Invalid destination: " + queueName));
        } else {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Creating browser with selector: " + msel);
            com.swiftmq.swiftlet.queue.QueueBrowser queueBrowser = ctx.queueManager.createQueueBrowser(queueName, ctx.activeLogin, msel);
            int idx = ArrayListTool.setFirstFreeOrExpand(queueBrowsers, queueBrowser);
            reply.setOk(true);
            reply.setQueueBrowserId(idx);
            if (browserEntityList != null) {
                Entity browserEntity = browserEntityList.createEntity();
                browserEntity.setName(queueName + "-" + idx);
                browserEntity.setDynamicObject(queueBrowser);
                browserEntity.createCommands();
                Property prop = browserEntity.getProperty("queue");
                prop.setValue(queueName);
                prop.setReadOnly(true);
                prop = browserEntity.getProperty("selector");
                if (msel != null) {
                    prop.setValue(msel.getConditionString());
                }
                prop.setReadOnly(true);
                browserEntityList.addEntity(browserEntity);
            }
        }
    } catch (InvalidSelectorException e) {
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": CreateBrowser has invalid Selector: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": CreateBrowser has invalid Selector: " + e);
        reply.setOk(false);
        reply.setException(e);
    } catch (Exception e) {
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": Exception during createQueueBrowser: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Exception during createQueueBrowser: " + e);
        reply.setOk(false);
        reply.setException(e);
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) QueueImpl(com.swiftmq.jms.QueueImpl) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) MessageSelector(com.swiftmq.ms.MessageSelector) Property(com.swiftmq.mgmt.Property)

Example 15 with MessageSelector

use of com.swiftmq.ms.MessageSelector in project swiftmq-client by iitsoftware.

the class SessionImpl method createReceiver.

public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException {
    verifyState();
    if (queue == null)
        throw new InvalidDestinationException("createReceiver, queue is null!");
    if (queue instanceof TemporaryQueueImpl && !((TemporaryQueueImpl) queue).isCreatungSession(this))
        throw new JMSException("A receiver on a TemporaryQueue can only be created from the session the temporary queue was created from");
    QueueReceiverImpl qr = null;
    CreateConsumerReply reply = null;
    try {
        String ms = messageSelector;
        if (messageSelector != null && messageSelector.trim().length() == 0)
            ms = null;
        if (ms != null) {
            MessageSelector msel = new MessageSelector(ms);
            msel.compile();
        }
        reply = (CreateConsumerReply) requestRegistry.request(new CreateConsumerRequest(this, dispatchId, (QueueImpl) queue, ms));
    } catch (Exception e) {
        throw ExceptionConverter.convert(e);
    }
    if (reply.isOk()) {
        int qcId = reply.getQueueConsumerId();
        qr = new QueueReceiverImpl(transacted, acknowledgeMode, requestRegistry, queue, messageSelector, this);
        qr.setServerQueueConsumerId(qcId);
        qr.setDoAck(!transacted && acknowledgeMode != Session.CLIENT_ACKNOWLEDGE);
        addMessageConsumerImpl(qr);
    } else {
        throw ExceptionConverter.convert(reply.getException());
    }
    return (qr);
}
Also used : MessageSelector(com.swiftmq.ms.MessageSelector) IllegalStateException(javax.jms.IllegalStateException)

Aggregations

MessageSelector (com.swiftmq.ms.MessageSelector)31 InvalidSelectorException (javax.jms.InvalidSelectorException)11 QueueImpl (com.swiftmq.jms.QueueImpl)9 InvalidDestinationException (javax.jms.InvalidDestinationException)8 JMSException (javax.jms.JMSException)8 Entity (com.swiftmq.mgmt.Entity)7 Property (com.swiftmq.mgmt.Property)7 MessageImpl (com.swiftmq.jms.MessageImpl)5 TopicImpl (com.swiftmq.jms.TopicImpl)4 IllegalStateException (javax.jms.IllegalStateException)4 QueueReceiver (com.swiftmq.swiftlet.queue.QueueReceiver)3 JobException (com.swiftmq.swiftlet.scheduler.JobException)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3 Message (com.swiftmq.impl.streams.comp.message.Message)2 QueueMessageProcessor (com.swiftmq.impl.streams.processor.QueueMessageProcessor)2 EntityRemoveException (com.swiftmq.mgmt.EntityRemoveException)2 ActiveLogin (com.swiftmq.swiftlet.auth.ActiveLogin)2 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)2 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)2