Search in sources :

Example 36 with QueueImpl

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

the class QueueManagerImpl method startQueue.

/**
 * @param queue
 * @throws QueueException
 */
private void startQueue(ActiveQueue queue) throws QueueException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startQueue: starting queue '" + queue.getAbstractQueue().getQueueName() + "'");
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startQueue: queue '" + queue.getAbstractQueue().getQueueName() + "' fireQueueManagerEvent, method: queueStartInitiated");
    fireQueueManagerEvent(queue.getAbstractQueue().getQueueName(), "queueStartInitiated", new QueueManagerEvent(this, queue.getAbstractQueue().getQueueName()));
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startQueue: queue '" + queue.getAbstractQueue().getQueueName() + "' queue.getAbstractQueue().startQueue()");
    queue.getAbstractQueue().startQueue();
    queue.setStartupTime(System.currentTimeMillis());
    Entity queueEntity = ((ActiveQueueImpl) queue).getQueueEntity();
    if (queueEntity != null) {
        Property prop = queueEntity.getProperty(PROP_CLEANUP_INTERVAL);
        CleanupListener l = new CleanupListener((ActiveQueueImpl) queue);
        prop.addPropertyWatchListener(l);
        ((ActiveQueueImpl) queue).setWatchListener(l);
    }
    long interval = queue.getAbstractQueue().getCleanUpInterval();
    if (interval > 0) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "startQueue: queue '" + queue.getAbstractQueue().getQueueName() + "' addTimerListener for interval " + interval);
        ctx.timerSwiftlet.addTimerListener(interval, queue);
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startQueue: queue '" + queue.getAbstractQueue().getQueueName() + "' fireQueueManagerEvent, method: queueStarted");
    fireQueueManagerEvent(queue.getAbstractQueue().getQueueName(), "queueStarted", new QueueManagerEvent(this, queue.getAbstractQueue().getQueueName()));
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startQueue: queue '" + queue.getAbstractQueue().getQueueName() + "' started");
    if (ctx.jndiSwiftlet != null) {
        String name = queue.getAbstractQueue().getQueueName();
        try {
            SwiftUtilities.verifyQueueName(name);
            registerJNDI(name, new QueueImpl(name));
        } catch (Exception ignored) {
        }
    }
}
Also used : QueueManagerEvent(com.swiftmq.swiftlet.queue.event.QueueManagerEvent) QueueImpl(com.swiftmq.jms.QueueImpl) IOException(java.io.IOException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException)

Example 37 with QueueImpl

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

the class ClusteredQueue method createPushTransaction.

public Object createPushTransaction() throws QueueException {
    ClusteredTransactionId txId = null;
    if (dispatchPolicy.isMessageBasedDispatch()) {
        txId = new ClusteredTransactionId(ctx, true);
    } else {
        String queueName = dispatchPolicy.getNextSendQueue();
        if (ctx.queueSpace.enabled)
            ctx.queueSpace.trace(getQueueName(), toString() + "/createPushTransaction, nextSendQueue=" + queueName);
        if (queueName == null)
            throw new QueueException("Unable to select a physical destination queue for this clustered queue!");
        AbstractQueue queue = ctx.queueManager.getQueueForInternalUse(queueName, true);
        txId = new ClusteredTransactionId(ctx, queue, queue.createPushTransaction(), new QueueImpl(queueName));
    }
    return txId;
}
Also used : AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) QueueException(com.swiftmq.swiftlet.queue.QueueException) QueueImpl(com.swiftmq.jms.QueueImpl)

Example 38 with QueueImpl

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

the class ClusteredTransactionId method putMessage.

public void putMessage(String queueName, MessageImpl message) throws Exception {
    Entry entry = queueMap.get(queueName);
    if (entry == null) {
        AbstractQueue abstractQueue = ctx.queueManager.getQueueForInternalUse(queueName);
        QueueImpl destination = new QueueImpl(queueName);
        Object transaction = abstractQueue.createPushTransaction();
        entry = new Entry(abstractQueue, destination, transaction);
        queueMap.put(queueName, entry);
    }
    message.setJMSDestination(entry.destination);
    message.setSourceRouter(null);
    message.setDestRouter(null);
    message.setDestQueue(queueName);
    entry.abstractQueue.putMessage(entry.transaction, message);
}
Also used : AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) QueueImpl(com.swiftmq.jms.QueueImpl)

Example 39 with QueueImpl

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

the class QueueMoverJob method start.

public void start(Properties properties, JobTerminationListener jobTerminationListener) throws JobException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " ...");
    this.properties = properties;
    int cnt = 0;
    String queueName = properties.getProperty("Source Queue");
    if (!queueName.startsWith("tpc$")) {
        MessageSelector selector = null;
        String s = properties.getProperty("Message Selector");
        if (s != null) {
            selector = new MessageSelector(s);
            try {
                selector.compile();
            } catch (InvalidSelectorException e) {
                throw new JobException(e.toString(), e, false);
            }
        }
        try {
            receiver = ctx.queueManager.createQueueReceiver(queueName, null, selector);
            pullTx = receiver.createTransaction(false);
            targetQueue = new QueueImpl(properties.getProperty("Target Queue"));
            sender = ctx.queueManager.createQueueSender(targetQueue.getQueueName(), null);
            pushTx = sender.createTransaction();
        } catch (Exception e) {
            throw new JobException(e.toString(), e, false);
        }
        if (stopCalled) {
            terminate();
            return;
        }
        try {
            MessageEntry entry = null;
            while ((entry = pullTx.getMessage(0, selector)) != null) {
                MessageImpl msg = entry.getMessage();
                msg.setJMSDestination(targetQueue);
                msg.setSourceRouter(null);
                msg.setDestRouter(null);
                pushTx.putMessage(msg);
                cnt++;
                pushTx.commit();
                pullTx.commit();
                if (stopCalled) {
                    terminate();
                    return;
                }
                pullTx = receiver.createTransaction(false);
                pushTx = sender.createTransaction();
            }
        } catch (Exception e) {
            terminate();
            throw new JobException(e.toString(), e, false);
        }
    }
    terminate();
    jobTerminationListener.jobTerminated(cnt + " Messages moved");
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " done, cnt=" + cnt);
}
Also used : JobException(com.swiftmq.swiftlet.scheduler.JobException) InvalidSelectorException(javax.jms.InvalidSelectorException) MessageSelector(com.swiftmq.ms.MessageSelector) MessageImpl(com.swiftmq.jms.MessageImpl) QueueImpl(com.swiftmq.jms.QueueImpl) InvalidSelectorException(javax.jms.InvalidSelectorException) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Example 40 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)

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