Search in sources :

Example 16 with MessageSelector

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

the class SessionImpl method createDurableSubscriber.

public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal) throws JMSException {
    verifyState();
    if (topic == null)
        throw new InvalidDestinationException("createDurableSubscriber, topic is null!");
    if (name == null)
        throw new NullPointerException("createDurableSubscriber, name is null!");
    if (myConnection.getClientID() == null)
        throw new IllegalStateException("unable to create durable subscriber, no client ID has been set");
    try {
        SwiftUtilities.verifyDurableName(name);
    } catch (Exception e) {
        throw new JMSException(e.getMessage());
    }
    TopicSubscriberImpl ts = null;
    CreateDurableReply 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 = (CreateDurableReply) requestRegistry.request(new CreateDurableRequest(this, dispatchId, (TopicImpl) topic, ms, noLocal, name));
    } catch (Exception e) {
        throw ExceptionConverter.convert(e);
    }
    if (reply.isOk()) {
        int tsId = reply.getTopicSubscriberId();
        ts = new DurableTopicSubscriberImpl(transacted, acknowledgeMode, requestRegistry, topic, messageSelector, this, noLocal, name);
        ts.setServerQueueConsumerId(tsId);
        ts.setDoAck(!transacted && acknowledgeMode != Session.CLIENT_ACKNOWLEDGE);
        addMessageConsumerImpl(ts);
    } else {
        throw ExceptionConverter.convert(reply.getException());
    }
    return (ts);
}
Also used : IllegalStateException(javax.jms.IllegalStateException) IllegalStateException(javax.jms.IllegalStateException) MessageSelector(com.swiftmq.ms.MessageSelector)

Example 17 with MessageSelector

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

the class SessionImpl method createSubscriber.

public TopicSubscriber createSubscriber(Topic topic, String messageSelector, boolean noLocal) throws JMSException {
    verifyState();
    if (topic == null)
        throw new InvalidDestinationException("createSubscriber, topic is null!");
    if (topic instanceof TemporaryTopicImpl && !((TemporaryTopicImpl) topic).isCreatingSession(this))
        throw new JMSException("A receiver on a TemporaryTopic can only be created from the session the temporary topic was created from");
    TopicSubscriberImpl ts = null;
    CreateSubscriberReply 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 = (CreateSubscriberReply) requestRegistry.request(new CreateSubscriberRequest(this, dispatchId, (TopicImpl) topic, ms, noLocal, true));
    } catch (Exception e) {
        throw ExceptionConverter.convert(e);
    }
    if (reply.isOk()) {
        int tsId = reply.getTopicSubscriberId();
        ts = new TopicSubscriberImpl(transacted, acknowledgeMode, requestRegistry, topic, messageSelector, this, noLocal);
        ts.setServerQueueConsumerId(tsId);
        ts.setDoAck(false);
        ts.setRecordLog(false);
        addMessageConsumerImpl(ts);
    } else {
        throw ExceptionConverter.convert(reply.getException());
    }
    return (ts);
}
Also used : MessageSelector(com.swiftmq.ms.MessageSelector) IllegalStateException(javax.jms.IllegalStateException)

Example 18 with MessageSelector

use of com.swiftmq.ms.MessageSelector 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 19 with MessageSelector

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

the class TopicInput method start.

@Override
public void start() throws Exception {
    if (started)
        return;
    if (!ctx.ctx.topicManager.isTopicDefined(destinationName))
        ctx.ctx.topicManager.createTopic(destinationName);
    MessageSelector ms = null;
    if (selector != null) {
        ms = new MessageSelector(selector);
        ms.compile();
    }
    if (durable) {
        ActiveLogin dlogin = ctx.ctx.authenticationSwiftlet.createActiveLogin(clientId, "DURABLE");
        dlogin.setClientId(clientId);
        TopicImpl topic = ctx.ctx.topicManager.verifyTopic(new TopicImpl(destinationName));
        queueName = ctx.ctx.topicManager.subscribeDurable(durableName, topic, ms, false, dlogin);
    } else {
        queueName = ctx.ctx.queueManager.createTemporaryQueue();
        subscriberId = ctx.ctx.topicManager.subscribe(destinationName, ms, false, queueName, true);
    }
    QueueReceiver receiver = ctx.ctx.queueManager.createQueueReceiver(queueName, (ActiveLogin) null, null);
    messageProcessor = new QueueMessageProcessor(ctx, this, receiver, null);
    messageProcessor.restart();
    started = true;
}
Also used : ActiveLogin(com.swiftmq.swiftlet.auth.ActiveLogin) QueueReceiver(com.swiftmq.swiftlet.queue.QueueReceiver) MessageSelector(com.swiftmq.ms.MessageSelector) TopicImpl(com.swiftmq.jms.TopicImpl) QueueMessageProcessor(com.swiftmq.impl.streams.processor.QueueMessageProcessor)

Example 20 with MessageSelector

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

the class HeapMemory method remove.

@Override
public Memory remove(String selector) throws Exception {
    MessageSelector sel = new MessageSelector(selector);
    sel.compile();
    List<Entry> list = all();
    for (int i = 0; i < list.size(); i++) {
        Entry entry = list.get(i);
        if (entry.message.isSelected(sel))
            removeByKey(entry.key);
    }
    return this;
}
Also used : MessageSelector(com.swiftmq.ms.MessageSelector)

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