Search in sources :

Example 66 with QueueImpl

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

the class NontransactedQueueSession method visit.

public void visit(CreateProducerRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateProducerRequest");
    CreateProducerReply reply = (CreateProducerReply) req.createReply();
    try {
        ctx.activeLogin.getResourceLimitGroup().incProducers();
    } catch (ResourceLimitException e) {
        reply.setOk(false);
        reply.setException(new JMSException(e.toString()));
        reply.send();
        return;
    }
    QueueImpl queue = req.getQueue();
    try {
        int producerId;
        QueueProducer producer;
        producerId = ArrayListTool.setFirstFreeOrExpand(producerList, null);
        producer = new QueueProducer(ctx, queue.getQueueName());
        producerList.set(producerId, producer);
        reply.setQueueProducerId(producerId);
        reply.setOk(true);
        if (senderEntityList != null) {
            Entity senderEntity = senderEntityList.createEntity();
            senderEntity.setName(queue.getQueueName() + "-" + producerId);
            senderEntity.setDynamicObject(producer);
            senderEntity.createCommands();
            Property prop = senderEntity.getProperty("queue");
            prop.setValue(queue.getQueueName());
            prop.setReadOnly(true);
            senderEntityList.addEntity(senderEntity);
        }
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/exception creating producer: " + e.getMessage());
        ctx.logSwiftlet.logError("sys$jms", ctx.tracePrefix + "/exception creating producer: " + 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) Property(com.swiftmq.mgmt.Property) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException)

Example 67 with QueueImpl

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

the class TransactedQueueSession method visit.

public void visit(CreateConsumerRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateConsumerRequest");
    CreateConsumerReply reply = (CreateConsumerReply) req.createReply();
    try {
        ctx.activeLogin.getResourceLimitGroup().incConsumers();
    } catch (ResourceLimitException e) {
        reply.setOk(false);
        reply.setException(new JMSException(e.toString()));
        reply.send();
        return;
    }
    QueueImpl queue = req.getQueue();
    String messageSelector = req.getMessageSelector();
    String queueName = null;
    try {
        queueName = queue.getQueueName();
    } catch (JMSException ignored) {
    }
    try {
        queueName = validateDestination(queueName);
        int consumerId = 0;
        QueueConsumer consumer = null;
        consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
        consumer = new QueueConsumer(ctx, queueName, messageSelector);
        consumerList.set(consumerId, consumer);
        reply.setOk(true);
        reply.setQueueConsumerId(consumerId);
        if (receiverEntityList != null) {
            Entity consEntity = receiverEntityList.createEntity();
            consEntity.setName(queueName + "-" + consumerId);
            consEntity.setDynamicObject(consumer);
            consEntity.createCommands();
            Property prop = consEntity.getProperty("queue");
            prop.setValue(queueName);
            prop.setReadOnly(true);
            prop = consEntity.getProperty("selector");
            if (messageSelector != null) {
                prop.setValue(messageSelector);
            }
            prop.setReadOnly(true);
            receiverEntityList.addEntity(consEntity);
        }
        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 + "/CreateConsumer has invalid Selector: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/CreateConsumer 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 consumer: " + e1);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/Exception during create consumer: " + e1);
        reply.setOk(false);
        reply.setException(e1);
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) InvalidSelectorException(javax.jms.InvalidSelectorException) JMSException(javax.jms.JMSException) Property(com.swiftmq.mgmt.Property) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException)

Example 68 with QueueImpl

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

the class TransactedQueueSession method visit.

public void visit(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
        List ml = req.getMessages();
        ctx.incMsgsSent(ml.size());
        long fcDelay = 0;
        RingBuffer tempProducers = null;
        for (int i = 0; i < ml.size(); i++) {
            DataByteArrayInputStream dis = new DataByteArrayInputStream((byte[]) ml.get(i));
            int producerId = dis.readInt();
            int type = dis.readInt();
            MessageImpl msg = MessageImpl.createInstance(type);
            msg.readContent(dis);
            dis.close();
            long ttl = msg.getJMSExpiration();
            if (ttl > 0)
                msg.setJMSExpiration(System.currentTimeMillis() + ttl);
            Producer producer = null;
            if (producerId == -1) {
                String queueName = ((QueueImpl) msg.getJMSDestination()).getQueueName();
                if (!ctx.queueManager.isQueueRunning(queueName))
                    throw new InvalidDestinationException("Invalid destination: " + queueName);
                producer = new QueueProducer(ctx, queueName);
                if (tempProducers == null)
                    tempProducers = new RingBuffer(8);
                tempProducers.add(producer);
                transactionManager.addTransactionFactory(producer);
            } else {
                producer = (Producer) producerList.get(producerId);
            }
            QueuePushTransaction transaction = 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);
    }
    reply.send();
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) InvalidDestinationException(javax.jms.InvalidDestinationException) RingBuffer(com.swiftmq.tools.collection.RingBuffer) DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) EntityList(com.swiftmq.mgmt.EntityList) List(java.util.List) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 69 with QueueImpl

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

the class QueueManagerImpl method registerJNDIQueues.

private void registerJNDIQueues() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "registering JNDI queues ...");
    synchronized (qSemaphore) {
        Iterator iter = queueTable.entrySet().iterator();
        while (iter.hasNext()) {
            ActiveQueue activeQueue = (ActiveQueue) ((Map.Entry) iter.next()).getValue();
            if (activeQueue.getStartupTime() != -1) {
                try {
                    String fqName = activeQueue.getAbstractQueue().getQueueName();
                    SwiftUtilities.verifyQueueName(fqName);
                    registerJNDI(fqName, new QueueImpl(fqName));
                } catch (Exception ignored) {
                }
            }
        }
    }
}
Also used : QueueImpl(com.swiftmq.jms.QueueImpl) IOException(java.io.IOException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException)

Example 70 with QueueImpl

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

Aggregations

QueueImpl (com.swiftmq.jms.QueueImpl)78 InvalidSelectorException (javax.jms.InvalidSelectorException)51 JMSException (javax.jms.JMSException)51 InvalidDestinationException (javax.jms.InvalidDestinationException)49 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)42 Entity (com.swiftmq.mgmt.Entity)35 Property (com.swiftmq.mgmt.Property)35 MessageImpl (com.swiftmq.jms.MessageImpl)21 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)16 MessageSelector (com.swiftmq.ms.MessageSelector)9 RingBuffer (com.swiftmq.tools.collection.RingBuffer)7 DataByteArrayInputStream (com.swiftmq.tools.util.DataByteArrayInputStream)7 List (java.util.List)6 EntityList (com.swiftmq.mgmt.EntityList)5 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)4 TopicImpl (com.swiftmq.jms.TopicImpl)4 SwiftletException (com.swiftmq.swiftlet.SwiftletException)3 TextMessageImpl (com.swiftmq.jms.TextMessageImpl)2 JNDIRequest (com.swiftmq.jndi.protocol.v400.JNDIRequest)2 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)2