Search in sources :

Example 61 with TopicImpl

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

the class CompositeQueue method putMessage.

public void putMessage(Object object, MessageImpl message) throws QueueException {
    if (ctx.queueSpace.enabled)
        ctx.queueSpace.trace(getQueueName(), "putMessage, cTxId=" + object + " ...");
    boolean needCopy = false;
    boolean hasDefaultDelivery = false;
    int timesDelivered = 0;
    List entries = ((CompositeTransactionId) object).getEntries();
    for (int i = 0; i < entries.size(); i++) {
        CompositeTransactionIdEntry entry = (CompositeTransactionIdEntry) entries.get(i);
        if (entry.isDefaultBinding)
            hasDefaultDelivery = true;
        if (!entry.isDefaultBinding && (entry.selector == null || entry.selector.isSelected(message))) {
            try {
                MessageImpl m = message;
                if (needCopy)
                    m = copyMessage(message);
                else
                    needCopy = true;
                if (entry.generateNewMessageId)
                    m.setJMSMessageID(nextId());
                if (entry.changeDestination)
                    m.setJMSDestination(new QueueImpl(ctx.queueManager.fqn(entry.originalName)));
                if (!entry.isQueue)
                    m.setJMSDestination(new TopicImpl(entry.originalName));
                if (ctx.queueSpace.enabled)
                    ctx.queueSpace.trace(getQueueName(), "putMessage on binding '" + entry.queue.getQueueName());
                entry.queue.putMessage(entry.txId, m);
                timesDelivered++;
            } catch (Exception e) {
                ctx.logSwiftlet.logError(ctx.queueManager.getName(), "Composite Queue '" + getQueueName() + "': putMessage on binding queue '" + entry.queue.getQueueName() + "', exception=" + e);
                if (ctx.queueSpace.enabled)
                    ctx.queueSpace.trace(getQueueName(), "putMessage on binding queue '" + entry.queue.getQueueName() + "', exception=" + e);
            }
        }
    }
    if (ctx.queueSpace.enabled)
        ctx.queueSpace.trace(getQueueName(), "putMessage delivered to " + timesDelivered + " bindings, hasDefaultDelivery=" + hasDefaultDelivery);
    if (timesDelivered == 0 && hasDefaultDelivery) {
        if (ctx.queueSpace.enabled)
            ctx.queueSpace.trace(getQueueName(), "putMessage, let's check the default bindings ...");
        for (int i = 0; i < entries.size(); i++) {
            CompositeTransactionIdEntry entry = (CompositeTransactionIdEntry) entries.get(i);
            if (entry.isDefaultBinding) {
                try {
                    MessageImpl m = message;
                    if (needCopy)
                        m = copyMessage(message);
                    else
                        needCopy = true;
                    if (entry.generateNewMessageId)
                        m.setJMSMessageID(nextId());
                    if (entry.changeDestination)
                        m.setJMSDestination(new QueueImpl(ctx.queueManager.fqn(entry.originalName)));
                    if (!entry.isQueue)
                        m.setJMSDestination(new TopicImpl(entry.originalName));
                    if (ctx.queueSpace.enabled)
                        ctx.queueSpace.trace(getQueueName(), "putMessage on DEFAULT binding '" + entry.queue.getQueueName());
                    entry.queue.putMessage(entry.txId, m);
                } catch (Exception e) {
                    ctx.logSwiftlet.logError(ctx.queueManager.getName(), "Composite Queue '" + getQueueName() + "': putMessage on binding queue '" + entry.queue.getQueueName() + "', exception=" + e);
                    if (ctx.queueSpace.enabled)
                        ctx.queueSpace.trace(getQueueName(), "putMessage on binding queue '" + entry.queue.getQueueName() + "', exception=" + e);
                }
            }
        }
    }
    if (ctx.queueSpace.enabled)
        ctx.queueSpace.trace(getQueueName(), "putMessage, cTxId=" + object + " done");
}
Also used : List(java.util.List) TopicImpl(com.swiftmq.jms.TopicImpl) MessageImpl(com.swiftmq.jms.MessageImpl) QueueImpl(com.swiftmq.jms.QueueImpl) UnknownHostException(java.net.UnknownHostException) QueueException(com.swiftmq.swiftlet.queue.QueueException) InvalidSelectorException(javax.jms.InvalidSelectorException)

Example 62 with TopicImpl

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

the class TopicConnectionConsumerImpl method createDurableSubscriber.

void createDurableSubscriber(TopicImpl topic, String messageSelector, String durableName) throws JMSException {
    try {
        SwiftUtilities.verifyDurableName(durableName);
    } catch (Exception e) {
        throw new JMSException(e.getMessage());
    }
    Reply reply = null;
    try {
        reply = (CreateDurableReply) requestRegistry.request(new CreateDurableRequest(dispatchId, (TopicImpl) topic, messageSelector, false, durableName));
    } catch (Exception e) {
        throw ExceptionConverter.convert(e);
    }
    if (reply.isOk()) {
        queueName = ((CreateDurableReply) reply).getQueueName();
    } else {
        throw ExceptionConverter.convert(reply.getException());
    }
    fillCache();
}
Also used : CreateDurableRequest(com.swiftmq.jms.smqp.v500.CreateDurableRequest) Reply(com.swiftmq.tools.requestreply.Reply) CreateSubscriberReply(com.swiftmq.jms.smqp.v500.CreateSubscriberReply) CreateDurableReply(com.swiftmq.jms.smqp.v500.CreateDurableReply) JMSException(javax.jms.JMSException) TopicImpl(com.swiftmq.jms.TopicImpl) JMSException(javax.jms.JMSException)

Example 63 with TopicImpl

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

the class TopicConnectionConsumerImpl method createDurableSubscriber.

void createDurableSubscriber(TopicImpl topic, String messageSelector, String durableName) throws JMSException {
    try {
        SwiftUtilities.verifyDurableName(durableName);
    } catch (Exception e) {
        throw new JMSException(e.getMessage());
    }
    Reply reply = null;
    try {
        reply = (CreateDurableReply) requestRegistry.request(new CreateDurableRequest(dispatchId, (TopicImpl) topic, messageSelector, false, durableName));
    } catch (Exception e) {
        throw ExceptionConverter.convert(e);
    }
    if (reply.isOk()) {
        queueName = ((CreateDurableReply) reply).getQueueName();
    } else {
        throw ExceptionConverter.convert(reply.getException());
    }
    fillCache();
}
Also used : CreateDurableRequest(com.swiftmq.jms.smqp.v400.CreateDurableRequest) Reply(com.swiftmq.tools.requestreply.Reply) CreateSubscriberReply(com.swiftmq.jms.smqp.v400.CreateSubscriberReply) CreateDurableReply(com.swiftmq.jms.smqp.v400.CreateDurableReply) JMSException(javax.jms.JMSException) TopicImpl(com.swiftmq.jms.TopicImpl) JMSException(javax.jms.JMSException)

Example 64 with TopicImpl

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

the class TransactedTopicSession method visitCommitRequest.

public void visitCommitRequest(CommitRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCommitRequest");
    CommitReply reply = (CommitReply) req.createReply();
    reply.setOk(true);
    try {
        // first: produce all messages
        Object[] wrapper = req.getMessages();
        ctx.incMsgsSent(wrapper.length);
        req.setMessages(null);
        long fcDelay = 0;
        RingBuffer tempProducers = null;
        for (int i = 0; i < wrapper.length; i++) {
            DataByteArrayInputStream dis = new DataByteArrayInputStream((byte[]) wrapper[i]);
            int producerId = dis.readInt();
            int type = dis.readInt();
            MessageImpl msg = MessageImpl.createInstance(type);
            msg.readContent(dis);
            dis.close();
            Producer producer = null;
            if (producerId == -1) {
                TopicImpl topic = (TopicImpl) msg.getJMSDestination();
                if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
                    ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
                producer = new TopicProducer(ctx, topic);
                if (tempProducers == null)
                    tempProducers = new RingBuffer(8);
                tempProducers.add(producer);
                transactionManager.addTransactionFactory(producer);
            } else {
                producer = (Producer) producerList.get(producerId);
            }
            QueuePushTransaction transaction = (QueuePushTransaction) producer.getTransaction();
            transaction.putMessage(msg);
            fcDelay = Math.max(fcDelay, transaction.getFlowControlDelay());
            if (producerId == -1)
                producer.markForClose();
        }
        // Next: do the commit
        transactionManager.commit();
        if (tempProducers != null) {
            int size = tempProducers.getSize();
            for (int i = 0; i < size; i++) {
                ((Producer) tempProducers.remove()).close();
            }
        }
        reply.setDelay(fcDelay);
        purgeMarkedProducers();
        purgeMarkedConsumers();
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/commit produced messages failed: " + e.getMessage());
        reply.setOk(false);
        reply.setException((e instanceof JMSException) ? e : new javax.jms.JMSException(e.toString()));
    }
    reply.send();
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) JMSException(javax.jms.JMSException) RingBuffer(com.swiftmq.tools.collection.RingBuffer) DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) TopicImpl(com.swiftmq.jms.TopicImpl) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 65 with TopicImpl

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

the class NontransactedTopicSession method visitProduceMessageRequest.

public void visitProduceMessageRequest(ProduceMessageRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitProduceMessageRequest");
    ctx.incMsgsSent(1);
    ProduceMessageReply reply = null;
    if (req.isReplyRequired())
        reply = (ProduceMessageReply) req.createReply();
    MessageImpl msg = req.getMessage();
    int producerId = req.getQueueProducerId();
    Producer producer = null;
    try {
        if (producerId == -1) {
            TopicImpl topic = (TopicImpl) msg.getJMSDestination();
            if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
                ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
            producer = new TopicProducer(ctx, topic);
        } else {
            producer = (Producer) producerList.get(producerId);
        }
        QueuePushTransaction transaction = (QueuePushTransaction) producer.createTransaction();
        transaction.putMessage(msg);
        transaction.commit();
        if (req.isReplyRequired()) {
            reply.setDelay(transaction.getFlowControlDelay());
            reply.setOk(true);
        }
        if (producerId == -1)
            producer.close();
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/produce messages failed: " + e.getMessage());
        if (req.isReplyRequired()) {
            reply.setOk(false);
            reply.setException((e instanceof JMSException) ? e : new javax.jms.JMSException(e.toString()));
        }
    }
    if (req.isReplyRequired())
        reply.send();
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) JMSException(javax.jms.JMSException) TopicImpl(com.swiftmq.jms.TopicImpl) MessageImpl(com.swiftmq.jms.MessageImpl) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException)

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