Search in sources :

Example 11 with TopicImpl

use of com.swiftmq.jms.TopicImpl in project swiftmq-ce by iitsoftware.

the class TransactedTopicSession method visit.

public void visit(CreateSubscriberRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateSubscriberRequest");
    CreateSubscriberReply reply = (CreateSubscriberReply) req.createReply();
    try {
        ctx.activeLogin.getResourceLimitGroup().incConsumers();
    } catch (ResourceLimitException e) {
        reply.setOk(false);
        reply.setException(new JMSException(e.toString()));
        reply.send();
        return;
    }
    TopicImpl topic = req.getTopic();
    String messageSelector = req.getMessageSelector();
    boolean noLocal = req.isNoLocal();
    try {
        Entity subEntity = null;
        if (subscriberEntityList != null)
            subEntity = subscriberEntityList.createEntity();
        int consumerId = 0;
        TopicConsumer consumer = null;
        if (topic.getType() == DestinationFactory.TYPE_TOPIC) {
            consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
            consumer = new TopicConsumer(ctx, topic, messageSelector, noLocal);
            consumerList.set(consumerId, consumer);
            if (subEntity != null) {
                Property prop = subEntity.getProperty("topic");
                prop.setReadOnly(false);
                prop.setValue(topic.getTopicName());
                prop.setReadOnly(true);
                prop = subEntity.getProperty("boundto");
                prop.setReadOnly(false);
                prop.setValue(topic.getQueueName());
                prop.setReadOnly(true);
                subEntity.setDynamicObject(consumer);
            }
            if (subEntity != null)
                subEntity.setName(topic.getTopicName() + "-" + consumerId);
        } else {
            consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
            consumer = new TopicConsumer(ctx, topic, messageSelector, noLocal);
            consumerList.set(consumerId, consumer);
            if (subEntity != null)
                subEntity.setDynamicObject(consumer);
            if (subEntity != null) {
                subEntity.setName(topic.getQueueName() + "-" + consumerId);
                Property prop = subEntity.getProperty("temptopic");
                prop.setReadOnly(false);
                prop.setValue(new Boolean(true));
                prop.setReadOnly(true);
                prop = subEntity.getProperty("boundto");
                prop.setReadOnly(false);
                prop.setValue(topic.getQueueName());
                prop.setReadOnly(true);
            }
        }
        reply.setOk(true);
        reply.setTopicSubscriberId(consumerId);
        if (subEntity != null) {
            Property prop = subEntity.getProperty("nolocal");
            prop.setReadOnly(false);
            prop.setValue(new Boolean(noLocal));
            prop.setReadOnly(true);
            subEntity.createCommands();
            prop = subEntity.getProperty("selector");
            if (messageSelector != null) {
                prop.setValue(messageSelector);
            }
            prop.setReadOnly(true);
            subscriberEntityList.addEntity(subEntity);
        }
        consumer.createReadTransaction();
        // enlist it at the transaction manager
        transactionManager.addTransactionFactory(consumer);
    } catch (InvalidSelectorException e) {
        ctx.activeLogin.getResourceLimitGroup().decConsumers();
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/CreateSubscriber has invalid Selector: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/CreateSubscriber has invalid Selector: " + e);
        reply.setOk(false);
        reply.setException(e);
    } catch (Exception e1) {
        ctx.activeLogin.getResourceLimitGroup().decConsumers();
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/Exception during create subscriber: " + e1);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/Exception during create subscriber: " + e1);
        reply.setOk(false);
        reply.setException(e1);
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) InvalidSelectorException(javax.jms.InvalidSelectorException) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) TopicImpl(com.swiftmq.jms.TopicImpl) Property(com.swiftmq.mgmt.Property) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException)

Example 12 with TopicImpl

use of com.swiftmq.jms.TopicImpl in project swiftmq-ce by iitsoftware.

the class NontransactedTopicSession method visit.

public void visit(CreateSubscriberRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateSubscriberRequest");
    CreateSubscriberReply reply = (CreateSubscriberReply) req.createReply();
    try {
        ctx.activeLogin.getResourceLimitGroup().incConsumers();
    } catch (ResourceLimitException e) {
        reply.setOk(false);
        reply.setException(new JMSException(e.toString()));
        reply.send();
        return;
    }
    TopicImpl topic = req.getTopic();
    String messageSelector = req.getMessageSelector();
    boolean noLocal = req.isNoLocal();
    try {
        Entity subEntity = null;
        if (subscriberEntityList != null)
            subEntity = subscriberEntityList.createEntity();
        int consumerId = 0;
        TopicConsumer consumer = null;
        if (topic.getType() == DestinationFactory.TYPE_TOPIC) {
            consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
            consumer = new TopicConsumer(ctx, topic, messageSelector, noLocal);
            consumerList.set(consumerId, consumer);
            if (subEntity != null) {
                Property prop = subEntity.getProperty("topic");
                prop.setReadOnly(false);
                prop.setValue(topic.getTopicName());
                prop.setReadOnly(true);
                prop = subEntity.getProperty("boundto");
                prop.setReadOnly(false);
                prop.setValue(topic.getQueueName());
                prop.setReadOnly(true);
                subEntity.setDynamicObject(consumer);
            }
            if (subEntity != null)
                subEntity.setName(topic.getTopicName() + "-" + consumerId);
        } else {
            consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
            consumer = new TopicConsumer(ctx, topic, messageSelector, noLocal);
            consumerList.set(consumerId, consumer);
            if (subEntity != null)
                subEntity.setDynamicObject(consumer);
            if (subEntity != null) {
                subEntity.setName(topic.getQueueName() + "-" + consumerId);
                Property prop = subEntity.getProperty("temptopic");
                prop.setReadOnly(false);
                prop.setValue(new Boolean(true));
                prop.setReadOnly(true);
                prop = subEntity.getProperty("boundto");
                prop.setReadOnly(false);
                prop.setValue(topic.getQueueName());
                prop.setReadOnly(true);
            }
        }
        consumer.setAutoCommit(req.isAutoCommit());
        consumer.createReadTransaction();
        consumer.createTransaction();
        reply.setOk(true);
        reply.setTopicSubscriberId(consumerId);
        reply.setTmpQueueName((consumer).getQueueName());
        if (subEntity != null) {
            Property prop = subEntity.getProperty("nolocal");
            prop.setReadOnly(false);
            prop.setValue(new Boolean(noLocal));
            prop.setReadOnly(true);
            subEntity.createCommands();
            prop = subEntity.getProperty("selector");
            if (messageSelector != null) {
                prop.setValue(messageSelector);
            }
            prop.setReadOnly(true);
            subscriberEntityList.addEntity(subEntity);
        }
    } catch (InvalidSelectorException e) {
        ctx.activeLogin.getResourceLimitGroup().decConsumers();
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/CreateSubscriber has invalid Selector: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/CreateSubscriber has invalid Selector: " + e);
        reply.setOk(false);
        reply.setException(e);
    } catch (Exception e1) {
        ctx.activeLogin.getResourceLimitGroup().decConsumers();
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/Exception during create subscriber: " + e1);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/Exception during create subscriber: " + e1);
        reply.setOk(false);
        reply.setException(e1);
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) InvalidSelectorException(javax.jms.InvalidSelectorException) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) TopicImpl(com.swiftmq.jms.TopicImpl) Property(com.swiftmq.mgmt.Property) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException)

Example 13 with TopicImpl

use of com.swiftmq.jms.TopicImpl in project swiftmq-ce by iitsoftware.

the class NontransactedTopicSession method visit.

public void visit(CreatePublisherRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreatePublisherRequest");
    CreatePublisherReply reply = (CreatePublisherReply) req.createReply();
    try {
        ctx.activeLogin.getResourceLimitGroup().incProducers();
    } catch (ResourceLimitException e) {
        reply.setOk(false);
        reply.setException(new JMSException(e.toString()));
        reply.send();
        return;
    }
    TopicImpl topic = req.getTopic();
    try {
        if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
            ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
        int producerId;
        TopicProducer producer;
        producerId = ArrayListTool.setFirstFreeOrExpand(producerList, null);
        producer = new TopicProducer(ctx, topic);
        producerList.set(producerId, producer);
        reply.setTopicPublisherId(producerId);
        reply.setOk(true);
        if (publisherEntityList != null) {
            Entity publisherEntity = publisherEntityList.createEntity();
            publisherEntity.setName(topic.getTopicName() + "-" + producerId);
            publisherEntity.setDynamicObject(producer);
            publisherEntity.createCommands();
            Property prop = publisherEntity.getProperty("topic");
            prop.setReadOnly(false);
            prop.setValue(topic.getTopicName());
            prop.setReadOnly(true);
            publisherEntityList.addEntity(publisherEntity);
        }
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/exception creating publisher: " + e.getMessage());
        ctx.logSwiftlet.logError("sys$jms", ctx.tracePrefix + "/exception creating publisher: " + e.getMessage());
        reply.setOk(false);
        reply.setException(e);
        ctx.activeLogin.getResourceLimitGroup().decProducers();
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) JMSException(javax.jms.JMSException) TopicImpl(com.swiftmq.jms.TopicImpl) Property(com.swiftmq.mgmt.Property) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException)

Example 14 with TopicImpl

use of com.swiftmq.jms.TopicImpl in project swiftmq-ce by iitsoftware.

the class TopicManagerImpl method createTopicAdministratively.

private synchronized void createTopicAdministratively(String topicName) throws TopicException {
    if (isTopicDefined(topicName))
        throw new TopicException("Topic '" + topicName + "' is already defined");
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "createTopic: creating topic: " + topicName);
    ctx.logSwiftlet.logInformation(getName(), "create topic: " + topicName);
    String[] tokenizedName = tokenizeTopicName(topicName, TOPIC_DELIMITER);
    String rootName = TOPIC_PREFIX + tokenizedName[0];
    TopicBroker rootBroker = (TopicBroker) rootBrokers.get(rootName);
    if (rootBroker == null) {
        try {
            ctx.queueManager.createQueue(rootName, this);
        } catch (Exception e) {
            throw new TopicException(e.getMessage());
        }
        rootBroker = (TopicBroker) rootBrokers.get(rootName);
    }
    rootBroker.addTopic(topicName, tokenizedName);
    if (ctx.jndiSwiftlet != null)
        registerJNDI(topicName, new TopicImpl(topicName));
}
Also used : TopicException(com.swiftmq.swiftlet.topic.TopicException) TopicImpl(com.swiftmq.jms.TopicImpl) InvalidDestinationException(javax.jms.InvalidDestinationException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) TopicException(com.swiftmq.swiftlet.topic.TopicException)

Example 15 with TopicImpl

use of com.swiftmq.jms.TopicImpl 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

TopicImpl (com.swiftmq.jms.TopicImpl)71 JMSException (javax.jms.JMSException)62 InvalidSelectorException (javax.jms.InvalidSelectorException)58 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)56 Entity (com.swiftmq.mgmt.Entity)42 Property (com.swiftmq.mgmt.Property)42 MessageImpl (com.swiftmq.jms.MessageImpl)17 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)14 DataByteArrayInputStream (com.swiftmq.tools.util.DataByteArrayInputStream)8 RingBuffer (com.swiftmq.tools.collection.RingBuffer)7 EntityList (com.swiftmq.mgmt.EntityList)6 List (java.util.List)6 QueueImpl (com.swiftmq.jms.QueueImpl)4 MessageSelector (com.swiftmq.ms.MessageSelector)4 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)4 TopicException (com.swiftmq.swiftlet.topic.TopicException)4 IOException (java.io.IOException)4 SwiftletException (com.swiftmq.swiftlet.SwiftletException)3 InvalidDestinationException (javax.jms.InvalidDestinationException)3 ActiveLogin (com.swiftmq.swiftlet.auth.ActiveLogin)2