Search in sources :

Example 6 with QueuePushTransaction

use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.

the class TransactedUnifiedSession 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());
        req.setMessages(null);
        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();
            Producer producer = null;
            if (producerId == -1) {
                DestinationImpl destImpl = (DestinationImpl) msg.getJMSDestination();
                switch(destImpl.getType()) {
                    case DestinationFactory.TYPE_QUEUE:
                    case DestinationFactory.TYPE_TEMPQUEUE:
                        String queueName = ((QueueImpl) destImpl).getQueueName();
                        if (!ctx.queueManager.isQueueRunning(queueName))
                            throw new InvalidDestinationException("Invalid destination: " + queueName);
                        producer = new QueueProducer(ctx, queueName);
                        break;
                    case DestinationFactory.TYPE_TOPIC:
                    case DestinationFactory.TYPE_TEMPTOPIC:
                        TopicImpl topic = (TopicImpl) msg.getJMSDestination();
                        if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
                            ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
                        producer = new TopicProducer(ctx, topic);
                        break;
                }
                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) 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)

Example 7 with QueuePushTransaction

use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.

the class NontransactedQueueSession method visit.

public void visit(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();
    int producerId = req.getQueueProducerId();
    Producer producer = null;
    try {
        MessageImpl msg = SMQPUtil.getMessage(req);
        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);
        }
    }
    if (req.isReplyRequired())
        reply.send();
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageImpl(com.swiftmq.jms.MessageImpl) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException)

Example 8 with QueuePushTransaction

use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.

the class NontransactedQueueSession method visit.

public void visit(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();
    int producerId = req.getQueueProducerId();
    Producer producer = null;
    try {
        MessageImpl msg = SMQPUtil.getMessage(req);
        long ttl = msg.getJMSExpiration();
        if (ttl > 0)
            msg.setJMSExpiration(System.currentTimeMillis() + ttl);
        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);
        }
    }
    if (req.isReplyRequired())
        reply.send();
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageImpl(com.swiftmq.jms.MessageImpl) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException)

Example 9 with QueuePushTransaction

use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.

the class TargetLink method transformAndStore.

private void transformAndStore(TransferFrame frame) throws EndWithErrorException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/transformAndStore, frame=" + frame);
    if (mySessionHandler.maxMessageSize > 0 && frame.getPayloadLength() > mySessionHandler.maxMessageSize)
        throw new LinkEndException(this, LinkError.MESSAGE_SIZE_EXCEEDED, new AMQPString("Message size (" + frame.getPayloadLength() + ") > max message size (" + mySessionHandler.maxMessageSize));
    if (coordinator)
        handleTransactionRequest(frame);
    else {
        try {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/transformAndStore, localDestination=" + localDestination);
            long payloadLength = frame.getPayloadLength();
            MessageImpl msg = getTransformer(frame.getMessageFormat().getValue()).transform(frame, this);
            if (msg.getJMSDestination() == null)
                msg.setJMSDestination(getLocalDestination());
            msg.setStringProperty(MessageImpl.PROP_CLIENT_ID, mySessionHandler.getVersionedConnection().getActiveLogin().getClientId());
            if (remoteUnsettled != null) {
                DeliveryTag deliveryTag = frame.getDeliveryTag();
                if (remoteUnsettled.remove(deliveryTag) != null) {
                    msg.setBooleanProperty(MessageImpl.PROP_DOUBT_DUPLICATE, true);
                    if (remoteUnsettled.size() == 0)
                        remoteUnsettled = null;
                }
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/transformAndStore, msg=" + msg);
            DeliveryStateIF state = frame.getState();
            if (state != null && state instanceof TransactionalState) {
                TransactionalState txState = (TransactionalState) state;
                TxnIdIF txnId = txState.getTxnId();
                if (txnId != null) {
                    transactionRegistry.addToTransaction(txnId, name, msg, this);
                } else
                    throw new SessionEndException(TransactionError.UNKNOWN_ID, new AMQPString("Missing TxnId in TransactionalState: " + txState));
            } else {
                QueuePushTransaction tx = sender.createTransaction();
                tx.putMessage(msg);
                tx.commit();
                setFlowcontrolDelay(tx.getFlowControlDelay());
            }
        } catch (Exception e) {
            throw new SessionEndException(AmqpError.INTERNAL_ERROR, new AMQPString("Exception during transformAndStore: " + e));
        }
    }
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) DeliveryStateIF(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF) MessageImpl(com.swiftmq.jms.MessageImpl) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) QueueException(com.swiftmq.swiftlet.queue.QueueException) InvalidSelectorException(javax.jms.InvalidSelectorException) TopicException(com.swiftmq.swiftlet.topic.TopicException)

Example 10 with QueuePushTransaction

use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.

the class TransactionRegistry method addToTransaction.

public void addToTransaction(TxnIdIF btxnId, String linkName, MessageImpl message, TargetLink targetLink) throws EndWithErrorException {
    String txnId = new String(((TransactionId) btxnId).getValue());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", linkName=" + linkName + ", message=" + message);
    lock.lock();
    try {
        ActiveTxEntry activeTxEntry = (ActiveTxEntry) activeTx.get(txnId);
        if (activeTxEntry == null) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", not found!");
            throw new SessionEndException(TransactionError.UNKNOWN_ID, new AMQPString("Transaction id not found: " + txnId));
        }
        if (activeTxEntry.inboundTxEntryMap == null)
            activeTxEntry.inboundTxEntryMap = new HashMap();
        InboundTxEntry inboundTxEntry = (InboundTxEntry) activeTxEntry.inboundTxEntryMap.get(linkName);
        try {
            if (inboundTxEntry == null) {
                QueuePushTransaction tx = targetLink.getQueueSender().createTransaction();
                targetLink.increaseActiveTransactions();
                inboundTxEntry = new InboundTxEntry(tx, targetLink);
                activeTxEntry.inboundTxEntryMap.put(linkName, inboundTxEntry);
            }
            ((QueuePushTransaction) inboundTxEntry.tx).putMessage(message);
        } catch (QueueException e) {
            throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString(e.toString()));
        }
    } finally {
        lock.unlock();
    }
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) HashMap(java.util.HashMap) QueueException(com.swiftmq.swiftlet.queue.QueueException) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString)

Aggregations

QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)57 JMSException (javax.jms.JMSException)44 InvalidSelectorException (javax.jms.InvalidSelectorException)43 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)42 MessageImpl (com.swiftmq.jms.MessageImpl)33 InvalidDestinationException (javax.jms.InvalidDestinationException)28 RingBuffer (com.swiftmq.tools.collection.RingBuffer)21 DataByteArrayInputStream (com.swiftmq.tools.util.DataByteArrayInputStream)21 QueueImpl (com.swiftmq.jms.QueueImpl)16 List (java.util.List)16 EntityList (com.swiftmq.mgmt.EntityList)15 TopicImpl (com.swiftmq.jms.TopicImpl)14 QueueSender (com.swiftmq.swiftlet.queue.QueueSender)7 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)5 com.swiftmq.jms (com.swiftmq.jms)4 QueueException (com.swiftmq.swiftlet.queue.QueueException)4 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)3 XidImpl (com.swiftmq.jms.XidImpl)2 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)2 Versionable (com.swiftmq.tools.versioning.Versionable)2