Search in sources :

Example 31 with QueueImpl

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

the class TransactedQueueSession 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) {
                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 = (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) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) RingBuffer(com.swiftmq.tools.collection.RingBuffer) DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream) JMSException(javax.jms.JMSException) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 32 with QueueImpl

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

the class BrowserManager method createBrowser.

public void createBrowser(CreateBrowserRequest request) {
    CreateBrowserReply reply = (CreateBrowserReply) request.createReply();
    QueueImpl queue = request.getQueue();
    String messageSelector = request.getMessageSelector();
    MessageSelector msel = null;
    String queueName = null;
    try {
        queueName = queue.getQueueName();
    } catch (JMSException ignored) {
    }
    try {
        if (messageSelector != null) {
            msel = new MessageSelector(messageSelector);
            msel.compile();
        }
        if (!ctx.queueManager.isQueueRunning(queueName)) {
            ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": Invalid destination: " + queueName);
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Invalid destination: " + queue);
            reply.setOk(false);
            reply.setException(new InvalidDestinationException("Invalid destination: " + queueName));
        } else {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Creating browser with selector: " + msel);
            com.swiftmq.swiftlet.queue.QueueBrowser queueBrowser = ctx.queueManager.createQueueBrowser(queueName, ctx.activeLogin, msel);
            int idx = ArrayListTool.setFirstFreeOrExpand(queueBrowsers, queueBrowser);
            reply.setOk(true);
            reply.setQueueBrowserId(idx);
            if (browserEntityList != null) {
                Entity browserEntity = browserEntityList.createEntity();
                browserEntity.setName(queueName + "-" + idx);
                browserEntity.setDynamicObject(queueBrowser);
                browserEntity.createCommands();
                Property prop = browserEntity.getProperty("queue");
                prop.setValue(queueName);
                prop.setReadOnly(true);
                prop = browserEntity.getProperty("selector");
                if (msel != null) {
                    prop.setValue(msel.getConditionString());
                }
                prop.setReadOnly(true);
                browserEntityList.addEntity(browserEntity);
            }
        }
    } catch (InvalidSelectorException e) {
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": CreateBrowser has invalid Selector: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": CreateBrowser has invalid Selector: " + e);
        reply.setOk(false);
        reply.setException(e);
    } catch (Exception e) {
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": Exception during createQueueBrowser: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Exception during createQueueBrowser: " + e);
        reply.setOk(false);
        reply.setException(e);
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) QueueImpl(com.swiftmq.jms.QueueImpl) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) MessageSelector(com.swiftmq.ms.MessageSelector) Property(com.swiftmq.mgmt.Property)

Example 33 with QueueImpl

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

the class BrowserManager method createBrowser.

public void createBrowser(CreateBrowserRequest request) {
    CreateBrowserReply reply = (CreateBrowserReply) request.createReply();
    QueueImpl queue = request.getQueue();
    String messageSelector = request.getMessageSelector();
    MessageSelector msel = null;
    String queueName = null;
    try {
        queueName = queue.getQueueName();
    } catch (JMSException ignored) {
    }
    try {
        if (messageSelector != null) {
            msel = new MessageSelector(messageSelector);
            msel.compile();
        }
        if (!ctx.queueManager.isQueueRunning(queueName)) {
            ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": Invalid destination: " + queueName);
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Invalid destination: " + queue);
            reply.setOk(false);
            reply.setException(new InvalidDestinationException("Invalid destination: " + queueName));
        } else {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Creating browser with selector: " + msel);
            com.swiftmq.swiftlet.queue.QueueBrowser queueBrowser = ctx.queueManager.createQueueBrowser(queueName, ctx.activeLogin, msel);
            int idx = ArrayListTool.setFirstFreeOrExpand(queueBrowsers, queueBrowser);
            reply.setOk(true);
            reply.setQueueBrowserId(idx);
            if (browserEntityList != null) {
                Entity browserEntity = browserEntityList.createEntity();
                browserEntity.setName(queueName + "-" + idx);
                browserEntity.setDynamicObject(queueBrowser);
                browserEntity.createCommands();
                Property prop = browserEntity.getProperty("queue");
                prop.setValue(queueName);
                prop.setReadOnly(true);
                prop = browserEntity.getProperty("selector");
                if (msel != null) {
                    prop.setValue(msel.getConditionString());
                }
                prop.setReadOnly(true);
                browserEntityList.addEntity(browserEntity);
            }
        }
    } catch (InvalidSelectorException e) {
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": CreateBrowser has invalid Selector: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": CreateBrowser has invalid Selector: " + e);
        reply.setOk(false);
        reply.setException(e);
    } catch (Exception e) {
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": Exception during createQueueBrowser: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Exception during createQueueBrowser: " + e);
        reply.setOk(false);
        reply.setException(new javax.jms.JMSException(e.toString()));
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) QueueImpl(com.swiftmq.jms.QueueImpl) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) MessageSelector(com.swiftmq.ms.MessageSelector) Property(com.swiftmq.mgmt.Property)

Example 34 with QueueImpl

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

the class BrowserManager method createBrowser.

public void createBrowser(CreateBrowserRequest request) {
    CreateBrowserReply reply = (CreateBrowserReply) request.createReply();
    QueueImpl queue = request.getQueue();
    String messageSelector = request.getMessageSelector();
    MessageSelector msel = null;
    String queueName = null;
    try {
        queueName = queue.getQueueName();
    } catch (JMSException ignored) {
    }
    try {
        if (messageSelector != null) {
            msel = new MessageSelector(messageSelector);
            msel.compile();
        }
        if (!ctx.queueManager.isQueueRunning(queueName)) {
            ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": Invalid destination: " + queueName);
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Invalid destination: " + queue);
            reply.setOk(false);
            reply.setException(new InvalidDestinationException("Invalid destination: " + queueName));
        } else {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Creating browser with selector: " + msel);
            com.swiftmq.swiftlet.queue.QueueBrowser queueBrowser = ctx.queueManager.createQueueBrowser(queueName, ctx.activeLogin, msel);
            int idx = ArrayListTool.setFirstFreeOrExpand(queueBrowsers, queueBrowser);
            reply.setOk(true);
            reply.setQueueBrowserId(idx);
            if (browserEntityList != null) {
                Entity browserEntity = browserEntityList.createEntity();
                browserEntity.setName(queueName + "-" + idx);
                browserEntity.setDynamicObject(queueBrowser);
                browserEntity.createCommands();
                Property prop = browserEntity.getProperty("queue");
                prop.setValue(queueName);
                prop.setReadOnly(true);
                prop = browserEntity.getProperty("selector");
                if (msel != null) {
                    prop.setValue(msel.getConditionString());
                }
                prop.setReadOnly(true);
                browserEntityList.addEntity(browserEntity);
            }
        }
    } catch (InvalidSelectorException e) {
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": CreateBrowser has invalid Selector: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": CreateBrowser has invalid Selector: " + e);
        reply.setOk(false);
        reply.setException(e);
    } catch (Exception e) {
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": Exception during createQueueBrowser: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Exception during createQueueBrowser: " + e);
        reply.setOk(false);
        reply.setException(new javax.jms.JMSException(e.toString()));
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) QueueImpl(com.swiftmq.jms.QueueImpl) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) MessageSelector(com.swiftmq.ms.MessageSelector) Property(com.swiftmq.mgmt.Property)

Example 35 with QueueImpl

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

the class StreamLibDeployer method processChunk.

private void processChunk(BytesMessage msg) throws Exception {
    String domain = msg.getStringProperty("domain");
    String pkg = msg.getStringProperty("package");
    String stream = msg.getStringProperty("stream");
    String libname = msg.getStringProperty("libname");
    int chunk = msg.getIntProperty("nchunk");
    boolean last = msg.getBooleanProperty("last");
    QueueImpl replyTo = (QueueImpl) msg.getJMSReplyTo();
    int len = (int) msg.getBodyLength();
    byte[] buffer = new byte[len];
    msg.readBytes(buffer);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/processChunk, domain=" + domain + ", package=" + pkg + ", stream=" + stream + ", libname=" + libname + ", chunk=" + chunk + ", last=" + last);
    File dir = getOrCreateDeployDir(domain, pkg, stream);
    appendChunk(dir, libname, chunk, buffer);
    if (last) {
        try {
            addCerts(domain + "." + pkg + "." + stream, dir);
            sendReply(replyTo, true);
        } catch (Exception e) {
            ctx.logSwiftlet.logError(ctx.streamsSwiftlet.getName(), toString() + "/Exception during addCert: " + e);
            removeStreamLibs(domain + "." + pkg + "." + stream);
            sendReply(replyTo, false);
        }
    }
}
Also used : QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException)

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