Search in sources :

Example 96 with MessageImpl

use of com.swiftmq.jms.MessageImpl 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 97 with MessageImpl

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

the class MessageConsumerImpl method reportDelivered.

private void reportDelivered(Message message) {
    try {
        MessageIndex messageIndex = ((MessageImpl) message).getMessageIndex();
        requestRegistry.request(new MessageDeliveredRequest(dispatchId, serverQueueConsumerId, messageIndex));
    } catch (Exception e) {
    }
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 98 with MessageImpl

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

the class JMSMappingInboundTransformer method transform.

public MessageImpl transform(TransferFrame frame, DestinationFactory destinationFactory) throws AMQPException, JMSException {
    jmsTypeProp = getValue(PROP_JMS_TYPE, null);
    MessageImpl jmsMessage = null;
    try {
        AMQPMessage amqpMessage = null;
        if (frame.getMorePayloads() != null) {
            List morePayloads = frame.getMorePayloads();
            byte[][] b = new byte[morePayloads.size() + 1][];
            b[0] = frame.getPayload();
            for (int i = 0; i < morePayloads.size(); i++) b[i + 1] = (byte[]) morePayloads.get(i);
            amqpMessage = new AMQPMessage(b, frame.getPayloadLength());
        } else
            amqpMessage = new AMQPMessage(frame.getPayload());
        jmsMessage = messageFactory.create(amqpMessage);
        jmsMessage.setLongProperty(prefixVendor + Util.PROP_MESSAGE_FORMAT, frame.getMessageFormat().getValue());
        jmsMessage.setBooleanProperty(amqpNative, false);
        Header header = amqpMessage.getHeader();
        if (header != null)
            transformHeader(header, jmsMessage);
        DeliveryAnnotations deliveryAnnotations = amqpMessage.getDeliveryAnnotations();
        if (deliveryAnnotations != null)
            transformMap(deliveryAnnotations.getValue(), jmsMessage, prefixDA);
        MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations();
        if (messageAnnotations != null)
            transformMap(messageAnnotations.getValue(), jmsMessage, prefixMA);
        Properties properties = amqpMessage.getProperties();
        if (properties != null)
            transformProperties(properties, jmsMessage, destinationFactory);
        ApplicationProperties applicationProperties = amqpMessage.getApplicationProperties();
        if (applicationProperties != null)
            transformApplicationProperties(applicationProperties, jmsMessage);
        Footer footer = amqpMessage.getFooter();
        if (footer != null)
            transformMap(footer.getValue(), jmsMessage, prefixFT);
    } catch (Exception e) {
        throw new AMQPException(e.toString());
    }
    jmsMessage.reset();
    return jmsMessage;
}
Also used : AMQPException(com.swiftmq.amqp.v100.client.AMQPException) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPException(com.swiftmq.amqp.v100.client.AMQPException) JMSException(javax.jms.JMSException) List(java.util.List) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 99 with MessageImpl

use of com.swiftmq.jms.MessageImpl 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 100 with MessageImpl

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

Aggregations

MessageImpl (com.swiftmq.jms.MessageImpl)106 JMSException (javax.jms.JMSException)42 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)33 InvalidSelectorException (javax.jms.InvalidSelectorException)31 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)28 QueueImpl (com.swiftmq.jms.QueueImpl)21 DataByteArrayInputStream (com.swiftmq.tools.util.DataByteArrayInputStream)20 TopicImpl (com.swiftmq.jms.TopicImpl)17 MessageEntry (com.swiftmq.swiftlet.queue.MessageEntry)15 MessageIndex (com.swiftmq.swiftlet.queue.MessageIndex)15 RingBuffer (com.swiftmq.tools.collection.RingBuffer)14 InvalidDestinationException (javax.jms.InvalidDestinationException)14 List (java.util.List)13 EntityList (com.swiftmq.mgmt.EntityList)10 Message (javax.jms.Message)10 XidImpl (com.swiftmq.jms.XidImpl)6 DataByteArrayOutputStream (com.swiftmq.tools.util.DataByteArrayOutputStream)6 MessageSelector (com.swiftmq.ms.MessageSelector)5 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)4 ArrayList (java.util.ArrayList)4