Search in sources :

Example 1 with QueueTransactionClosedException

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

the class TopicTransaction method rollback.

protected void rollback() throws Exception {
    if (subscriberTransactions == null)
        return;
    List durPersSubs = new ArrayList(subscriberTransactions.length);
    for (int i = 0; i < subscriberTransactions.length; i++) {
        TopicSubscriberTransaction sub = subscriberTransactions[i];
        if (sub != null) {
            TopicSubscription subscription = sub.getTopicSubscription();
            if (subscription.isRemote() || !subscription.isDurable() || !sub.isPersistentMessageIncluded()) {
                try {
                    sub.rollback();
                } catch (QueueTransactionClosedException ignored) {
                }
            } else
                durPersSubs.add(sub);
        }
    }
    int size = durPersSubs.size();
    if (size > 0) {
        if (size == 1) {
            TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(0);
            try {
                sub.rollback();
            } catch (QueueTransactionClosedException ignored) {
            }
        } else {
            for (int i = 0; i < size; i++) {
                TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                sub.getTransaction().lockQueue();
            }
            CompositeStoreTransaction compositeTx = ctx.storeSwiftlet.createCompositeStoreTransaction();
            for (int i = 0; i < size; i++) {
                TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                try {
                    sub.getTransaction().setCompositeStoreTransaction(compositeTx);
                    sub.rollback();
                    sub.getTransaction().setCompositeStoreTransaction(null);
                } catch (QueueTransactionClosedException ignored) {
                }
            }
            compositeTx.commitTransaction();
            for (int i = 0; i < size; i++) {
                TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                sub.getTransaction().unlockQueue(false);
            }
        }
    }
    subscriberTransactions = null;
}
Also used : QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) CompositeStoreTransaction(com.swiftmq.swiftlet.store.CompositeStoreTransaction) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with QueueTransactionClosedException

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

the class TransactionManager method commitWithGlobalLock.

private void commitWithGlobalLock() throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commitWithGlobalLock, transactions.size=" + transactions.size());
    CompositeStoreTransaction compTx = ctx.storeSwiftlet.createCompositeStoreTransaction();
    compTx.setReferencable(false);
    ctx.queueManager.lockMultiQueue();
    lock();
    try {
        for (Iterator iter = transactions.iterator(); iter.hasNext(); ) {
            Pair p = (Pair) iter.next();
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commitWithGlobalLock, t=" + p.tx + ", closed=" + p.tx.isClosed());
            try {
                p.tx.setCompositeStoreTransaction(compTx);
                p.tx.commit();
                p.tx.setCompositeStoreTransaction(null);
            } catch (QueueTransactionClosedException e) {
                // Happens when temp queues have been deleted meanwhile
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commitWithGlobalLock, t=" + p.tx + ", QueueTransactionClosedException, remove");
                iter.remove();
                p.tx.unlockQueue(false);
            }
        }
        compTx.commitTransaction();
    } finally {
        unlock();
        ctx.queueManager.unlockMultiQueue();
        startTransactions();
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commitWithGlobalLock done");
}
Also used : QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) CompositeStoreTransaction(com.swiftmq.swiftlet.store.CompositeStoreTransaction) Iterator(java.util.Iterator)

Example 3 with QueueTransactionClosedException

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

the class NontransactedSession method visit.

public void visit(AcknowledgeMessageRequest req) {
    if (closed)
        return;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitAcknowledgeMessageRequest");
    AcknowledgeMessageReply reply = null;
    if (req.isReplyRequired()) {
        reply = (AcknowledgeMessageReply) req.createReply();
        reply.setOk(true);
    }
    if (ctx.ackMode == javax.jms.Session.CLIENT_ACKNOWLEDGE) {
        Map ackConsumers = new HashMap();
        for (Iterator iter = deliveredList.iterator(); iter.hasNext(); ) {
            MessageDeliveredRequest request = (MessageDeliveredRequest) iter.next();
            Consumer consumer = (Consumer) consumerList.get(request.getQueueConsumerId());
            MessageIndex actIndex = request.getMessageIndex();
            QueuePullTransaction t = consumer.getTransaction();
            ConsumerAckEntry ackEntry = (ConsumerAckEntry) ackConsumers.get(consumer);
            if (ackEntry == null) {
                ackEntry = new ConsumerAckEntry(t);
                ackConsumers.put(consumer, ackEntry);
            }
            ackEntry.ackList.add(actIndex);
        }
        deliveredList.clear();
        boolean callbackRegistered = false;
        MultiAckJoin join = new MultiAckJoin(reply);
        for (Iterator iter = ackConsumers.entrySet().iterator(); iter.hasNext(); ) {
            Map.Entry entry = (Map.Entry) iter.next();
            Consumer consumer = (Consumer) entry.getKey();
            ConsumerAckEntry ackEntry = (ConsumerAckEntry) entry.getValue();
            try {
                join.incNumberCallbacks();
                ackEntry.transaction.acknowledgeMessages(ackEntry.ackList, new MultiAckCallback(join, consumer, ackEntry.ackList.size()));
                callbackRegistered = true;
            } catch (QueueTransactionClosedException e) {
            }
        }
        join.setBlocked(false);
        if (!callbackRegistered && reply != null)
            reply.send();
    } else {
        MessageIndex ackIndex = req.getMessageIndex();
        Consumer consumer = (Consumer) consumerList.get(req.getQueueConsumerId());
        ackSingleMessage(reply, ackIndex, consumer);
    }
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex) QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction)

Example 4 with QueueTransactionClosedException

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

the class MQTTSession method visit.

@Override
public void visit(POSendMessage po) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
    try {
        BytesMessageImpl jmsMessage = (BytesMessageImpl) po.getJmsMessage();
        jmsMessage.reset();
        MqttQoS qos = po.getQos();
        String topicName = topicNameTranslateReverse(po.getTopicName());
        byte[] b = new byte[(int) jmsMessage.getBodyLength()];
        jmsMessage.readBytes(b);
        ByteBuf byteBuf = new ByteBuf(b);
        byteBuf.reset();
        int packetId = -1;
        if (qos != MqttQoS.AT_MOST_ONCE) {
            if (pid == 65535)
                pid = 1;
            packetId = pid++;
            outboundPackets.put(packetId, po);
        }
        mqttConnection.getOutboundQueue().enqueue(new MqttPublishMessage(new MqttFixedHeader(MqttMessageType.PUBLISH, false, qos, false, 0), new MqttPublishVariableHeader(topicName, packetId), byteBuf));
        if (qos == MqttQoS.AT_MOST_ONCE) {
            po.getTransaction().commit();
            po.getSubscription().restart();
        } else
            addReplay(packetId, new MqttPublishMessage(new MqttFixedHeader(MqttMessageType.PUBLISH, true, qos, false, 0), new MqttPublishVariableHeader(topicName, packetId), byteBuf));
        incMsgsReceived(1);
    } catch (QueueTransactionClosedException qtc) {
    } catch (Exception e) {
        mqttConnection.initiateClose("send message: exception=" + e);
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
Also used : QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) ByteBuf(com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf) EntityAddException(com.swiftmq.mgmt.EntityAddException) QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException)

Example 5 with QueueTransactionClosedException

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

the class TopicSubscriberTransaction method commit.

protected void commit(AsyncCompletionCallback callback) {
    if (!valid) {
        callback.setException(new QueueTransactionClosedException("TopicSubscriberTransaction is invalid"));
        callback.done(false);
        return;
    }
    transaction.commit(new AsyncCompletionCallback(callback) {

        public void done(boolean success) {
            topicSubscription.removeTransaction(TopicSubscriberTransaction.this);
            valid = false;
            fcDelay = transaction.getFlowControlDelay();
            if (success)
                next.setResult(Long.valueOf(fcDelay));
            else
                next.setException(getException());
        }
    });
}
Also used : QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback)

Aggregations

QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)12 CompositeStoreTransaction (com.swiftmq.swiftlet.store.CompositeStoreTransaction)3 QueueException (com.swiftmq.swiftlet.queue.QueueException)2 AsyncCompletionCallback (com.swiftmq.tools.concurrent.AsyncCompletionCallback)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ByteBuf (com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)1 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)1 EntityAddException (com.swiftmq.mgmt.EntityAddException)1 EntityList (com.swiftmq.mgmt.EntityList)1 EntityRemoveException (com.swiftmq.mgmt.EntityRemoveException)1 MessageIndex (com.swiftmq.swiftlet.queue.MessageIndex)1 QueueLimitException (com.swiftmq.swiftlet.queue.QueueLimitException)1 QueuePullTransaction (com.swiftmq.swiftlet.queue.QueuePullTransaction)1 Selector (com.swiftmq.swiftlet.queue.Selector)1 Iterator (java.util.Iterator)1 JMSException (javax.jms.JMSException)1