Search in sources :

Example 71 with QueueImpl

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

the class QueueCleanupDLQJob method cleanupQueue.

private int cleanupQueue(String queueName) throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/cleanupQueue ...");
    receiver = ctx.queueManager.createQueueReceiver(queueName, null, null);
    pullTx = receiver.createTransaction(false);
    targetQueue = new QueueImpl(QueueManagerImpl.DLQ + '@' + SwiftletManager.getInstance().getRouterName());
    sender = ctx.queueManager.createQueueSender(targetQueue.getQueueName(), null);
    pushTx = sender.createTransaction();
    if (stopCalled) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/cleanupQueue, stopCalled (2)");
        closeResources();
        return 0;
    }
    int cnt = 0;
    MessageEntry entry = null;
    while ((entry = pullTx.getExpiredMessage(0)) != null) {
        MessageImpl msg = entry.getMessage();
        pushTx.putMessage(msg);
        cnt++;
        pushTx.commit();
        pullTx.commit();
        if (stopCalled) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/cleanupQueue, stopCalled (2)");
            closeResources();
            return cnt;
        }
        pullTx = receiver.createTransaction(false);
        pushTx = sender.createTransaction();
    }
    closeResources();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/cleanupQueue done, cnt=" + cnt);
    return cnt;
}
Also used : MessageImpl(com.swiftmq.jms.MessageImpl) QueueImpl(com.swiftmq.jms.QueueImpl)

Example 72 with QueueImpl

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

the class CreateProducerRequest method readContent.

/**
 * Read the content of this object from the stream.
 *
 * @param in input stream
 * @throws IOException if an error occurs
 */
public void readContent(DataInput in) throws IOException {
    super.readContent(in);
    byte set = in.readByte();
    if (set == 0) {
        queue = null;
    } else {
        queue = new QueueImpl(in.readUTF());
    }
}
Also used : QueueImpl(com.swiftmq.jms.QueueImpl)

Example 73 with QueueImpl

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

the class NontransactedQueueSession 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) {
            String queueName = ((QueueImpl) msg.getJMSDestination()).getQueueName();
            if (!ctx.queueManager.isQueueRunning(queueName))
                throw new InvalidDestinationException("Invalid destination: " + queueName);
            producer = new QueueProducer(ctx, queueName);
        } 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) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) 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 74 with QueueImpl

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

the class NontransactedQueueSession method visitCreateProducerRequest.

public void visitCreateProducerRequest(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 instanceof JMSException) ? e : new javax.jms.JMSException(e.toString()));
        ctx.activeLogin.getResourceLimitGroup().decProducers();
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) JMSException(javax.jms.JMSException) Property(com.swiftmq.mgmt.Property) JMSException(javax.jms.JMSException) 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 75 with QueueImpl

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

the class NontransactedQueueSession method visitCreateConsumerRequest.

public void visitCreateConsumerRequest(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 {
        if (!queueName.endsWith('@' + SwiftletManager.getInstance().getRouterName()))
            throw new InvalidDestinationException("Queue '" + queueName + "' is not local! Can't create a Consumer on it!");
        int consumerId = 0;
        QueueConsumer consumer = null;
        consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
        consumer = new QueueConsumer(ctx, queueName, messageSelector);
        consumerList.set(consumerId, consumer);
        consumer.createReadTransaction();
        consumer.createTransaction();
        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);
        }
    } 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 instanceof JMSException) ? e1 : new javax.jms.JMSException(e1.toString()));
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) 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) Property(com.swiftmq.mgmt.Property) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException)

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