Search in sources :

Example 1 with MessageSelector

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

the class HeapMemory method select.

@Override
public Memory select(String selector) throws Exception {
    MessageSelector sel = new MessageSelector(selector);
    sel.compile();
    Memory child = new HeapMemory(ctx);
    for (int i = 0; i < size(); i++) {
        Message message = at(i);
        if (message.isSelected(sel))
            child.add(message);
    }
    return child;
}
Also used : Message(com.swiftmq.impl.streams.comp.message.Message) MessageSelector(com.swiftmq.ms.MessageSelector)

Example 2 with MessageSelector

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

the class SessionImpl method createBrowser.

public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException {
    verifyState();
    if (type == TYPE_TOPIC_SESSION)
        throw new IllegalStateException("Operation not allowed on this session type");
    if (queue == null)
        throw new InvalidDestinationException("createBrowser, queue is null!");
    QueueBrowserImpl queueBrowser = null;
    CreateBrowserReply 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 = (CreateBrowserReply) requestRegistry.request(new CreateBrowserRequest(this, dispatchId, (QueueImpl) queue, ms));
    } catch (Exception e) {
        throw ExceptionConverter.convert(e);
    }
    if (reply.isOk()) {
        // create the browser
        queueBrowser = new QueueBrowserImpl(this, queue, messageSelector, dispatchId, reply.getQueueBrowserId(), requestRegistry);
        addQueueBrowserImpl(queueBrowser);
    } else {
        throw ExceptionConverter.convert(reply.getException());
    }
    return (queueBrowser);
}
Also used : IllegalStateException(javax.jms.IllegalStateException) MessageSelector(com.swiftmq.ms.MessageSelector) IllegalStateException(javax.jms.IllegalStateException)

Example 3 with MessageSelector

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

the class HeuristicHandler method removeHeuristic.

private void removeHeuristic(String id) throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/removeHeuristic, id=" + id);
    MessageSelector selector = new MessageSelector(PROP_SID + " = '" + id + "'");
    selector.compile();
    QueueReceiver receiver = ctx.queueManager.createQueueReceiver(HEURISTIC_QUEUE, null, selector);
    QueuePullTransaction t = receiver.createTransaction(false);
    MessageEntry entry = t.getMessage(0, selector);
    t.commit();
    receiver.close();
    if (entry == null)
        throw new Exception("Heuristic with ID '" + id + "' not found!");
}
Also used : MessageSelector(com.swiftmq.ms.MessageSelector) EntityRemoveException(com.swiftmq.mgmt.EntityRemoveException)

Example 4 with MessageSelector

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

the class MessageSenderJob method getMessage.

private MessageImpl getMessage() throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.schedulerSwiftlet.getName(), toString() + "/getMessage ...");
    MessageSelector selector = new MessageSelector(ctx.PROP_SCHED_ID + " = '" + id + "'");
    selector.compile();
    QueueReceiver receiver = ctx.queueManager.createQueueReceiver(ctx.INTERNAL_QUEUE, null, selector);
    QueuePullTransaction t = receiver.createTransaction(false);
    MessageEntry entry = t.getMessage(0, selector);
    t.rollback();
    receiver.close();
    if (entry == null)
        throw new Exception("Schedule with ID '" + id + "' not found!");
    MessageImpl msg = copyMessage(entry.getMessage());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.schedulerSwiftlet.getName(), toString() + "/getMessage done");
    return msg;
}
Also used : MessageSelector(com.swiftmq.ms.MessageSelector) MessageImpl(com.swiftmq.jms.MessageImpl) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Example 5 with MessageSelector

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

the class SourceLink method verifyLocalAddress.

public void verifyLocalAddress() throws AuthenticationException, QueueException, TopicException, InvalidSelectorException {
    if (!dynamic) {
        // This is for the case of reconnecting to a Durable Subscriber without specifying a Source in the attach frame.
        if (localAddress == null) {
            String topicName = ctx.topicManager.getDurableTopicName(getName(), mySessionHandler.getVersionedConnection().getActiveLogin());
            if (topicName != null)
                localAddress = new AddressString(topicName);
            durability = TerminusDurability.CONFIGURATION;
        }
        super.verifyLocalAddress();
    }
    if (receiver == null) {
        MessageSelector msel = null;
        if (messageSelector != null) {
            msel = new MessageSelector(messageSelector);
            msel.compile();
        }
        if (dynamic) {
            expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
            durability = TerminusDurability.NONE;
            // sndSettleMode = SenderSettleMode.SETTLED.getValue();       // SETTLED is only possible with temp queues because bulk mode in message proc do not delete from persistent store
            queueName = ctx.queueManager.createTemporaryQueue();
            receiver = ctx.queueManager.createQueueReceiver(queueName, mySessionHandler.getVersionedConnection().getActiveLogin(), msel);
        } else {
            if (isQueue) {
                expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
                durability = TerminusDurability.CONFIGURATION;
                // sndSettleMode = SenderSettleMode.UNSETTLED.getValue();
                receiver = ctx.queueManager.createQueueReceiver(getLocalAddress().getValueString(), mySessionHandler.getVersionedConnection().getActiveLogin(), msel);
            } else {
                if (durability.getValue() == TerminusDurability.CONFIGURATION.getValue() || durability.getValue() == TerminusDurability.UNSETTLED_STATE.getValue()) {
                    if (!expiryPolicy.getValue().equals(TerminusExpiryPolicy.LINK_DETACH.getValue()))
                        expiryPolicy = TerminusExpiryPolicy.NEVER;
                    durability = TerminusDurability.CONFIGURATION;
                    // sndSettleMode = SenderSettleMode.UNSETTLED.getValue();
                    queueName = ctx.topicManager.subscribeDurable(name, (TopicImpl) getLocalDestination(), msel, noLocal, mySessionHandler.getVersionedConnection().getActiveLogin());
                } else {
                    expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
                    queueName = ctx.queueManager.createTemporaryQueue();
                    // sndSettleMode = SenderSettleMode.SETTLED.getValue(); // SETTLED is only possible with temp queues because bulk mode in message proc do not delete from persistent store
                    subscriberId = ctx.topicManager.subscribe((TopicImpl) localDestination, msel, noLocal, queueName, mySessionHandler.getVersionedConnection().getActiveLogin());
                }
                receiver = ctx.queueManager.createQueueReceiver(queueName, mySessionHandler.getVersionedConnection().getActiveLogin(), null);
            }
        }
    }
    if (remoteUnsettled != null) {
        final AbstractQueue aq = ctx.queueManager.getQueueForInternalUse(receiver.getQueueName());
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, abstractQueue=" + aq);
        DataByteArrayInputStream dbis = new DataByteArrayInputStream();
        for (Iterator iter = remoteUnsettled.entrySet().iterator(); iter.hasNext(); ) {
            Map.Entry entry = (Map.Entry) iter.next();
            AMQPBinary deliveryTag = (AMQPBinary) entry.getKey();
            DeliveryStateIF deliveryStateIF = null;
            try {
                deliveryStateIF = DeliveryStateFactory.create((AMQPList) entry.getValue());
            } catch (Exception e) {
                throw new QueueException("Unable to create delivery tag");
            }
            final MessageIndex messageIndex = new MessageIndex();
            dbis.setBuffer(deliveryTag.getValue());
            try {
                messageIndex.readContent(dbis);
            } catch (IOException e) {
                throw new QueueException("Unable to convert delivery tag into a message index");
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", deliveryStateIF=" + deliveryStateIF);
            if (deliveryStateIF != null) {
                deliveryStateIF.accept(new DeliveryStateVisitorAdapter() {

                    public void visit(Accepted accepted) {
                        try {
                            if (aq != null) {
                                MessageIndex indexEntry = aq.getIndexEntry(messageIndex);
                                if (indexEntry != null) {
                                    aq.removeMessageByIndex(indexEntry);
                                    if (ctx.traceSpace.enabled)
                                        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + indexEntry + ", removed");
                                } else {
                                    if (ctx.traceSpace.enabled)
                                        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", NOT FOUND!");
                                }
                            }
                        } catch (QueueException e) {
                            e.printStackTrace();
                            if (ctx.traceSpace.enabled)
                                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", exception=" + e);
                        }
                    }
                });
            }
        }
    }
}
Also used : AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) IOException(java.io.IOException) DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream) IOException(java.io.IOException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) InvalidSelectorException(javax.jms.InvalidSelectorException) TopicException(com.swiftmq.swiftlet.topic.TopicException) Iterator(java.util.Iterator) MessageSelector(com.swiftmq.ms.MessageSelector) TopicImpl(com.swiftmq.jms.TopicImpl) HashMap(java.util.HashMap) Map(java.util.Map)

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