Search in sources :

Example 11 with QueueException

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

the class ClusterMetricPublisher method performTimeAction.

public void performTimeAction() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction ...");
    ClusteredQueueMetricCollection cmc = ctx.dispatchPolicyRegistry.getClusteredQueueMetricCollection();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction, cmc=" + cmc);
    List list = cmc.getClusteredQueueMetrics();
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            ClusteredQueueMetric cm = (ClusteredQueueMetric) list.get(i);
            List list2 = cm.getQueueMetrics();
            if (list2 != null) {
                for (int j = 0; j < list2.size(); j++) {
                    QueueMetric qm = (QueueMetric) list2.get(j);
                    AbstractQueue queue = ctx.queueManager.getQueueForInternalUse(qm.getQueueName());
                    if (queue != null) {
                        try {
                            if (ctx.traceSpace.enabled)
                                ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction, queue=" + qm.getQueueName() + ", qm.hasReceiver()=" + qm.hasReceiver() + ", cm.isReceiverSomewhere()=" + cm.isReceiverSomewhere() + ", qm.isRedispatch()=" + qm.isRedispatch() + ", queue.getNumberQueueMessages()=" + queue.getNumberQueueMessages());
                            if (!qm.hasReceiver() && cm.isReceiverSomewhere() && qm.isRedispatch() && queue.getNumberQueueMessages() > 0)
                                ctx.redispatcherController.redispatch(qm.getQueueName(), cm.getClusteredQueueName());
                        } catch (QueueException e) {
                        }
                    }
                }
            }
        }
    }
    try {
        QueuePushTransaction transaction = sender.createTransaction();
        Versionable versionable = new Versionable();
        versionable.addVersioned(700, createVersioned(700, cmc), "com.swiftmq.impl.queue.standard.cluster.v700.MetricFactory");
        BytesMessageImpl msg = createMessage(versionable);
        transaction.putMessage(msg);
        transaction.commit();
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction, exception=" + e);
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction done");
}
Also used : Versionable(com.swiftmq.tools.versioning.Versionable) AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) QueueException(com.swiftmq.swiftlet.queue.QueueException) List(java.util.List) QueueException(com.swiftmq.swiftlet.queue.QueueException) PropertyChangeException(com.swiftmq.mgmt.PropertyChangeException)

Example 12 with QueueException

use of com.swiftmq.swiftlet.queue.QueueException 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 13 with QueueException

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

the class QueueCleanupJob 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;
    if (stopCalled) {
        terminate();
        return;
    }
    try {
        String predicate = properties.getProperty("Queue Name Predicate");
        String[] names = ctx.queueManager.getDefinedQueueNames();
        if (names != null) {
            for (int i = 0; i < names.length; i++) {
                if (!names[i].startsWith("tpc$")) {
                    if (LikeComparator.compare(names[i], predicate, '\\')) {
                        try {
                            AbstractQueue queue = ctx.queueManager.getQueueForInternalUse(names[i]);
                            if (queue != null) {
                                if (ctx.traceSpace.enabled)
                                    ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/cleanup: " + names[i]);
                                queue.cleanUpExpiredMessages();
                            }
                        } catch (QueueException e) {
                            if (ctx.traceSpace.enabled)
                                ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/cleanup: " + names[i] + ", exception=" + e);
                        }
                    }
                }
                if (stopCalled)
                    break;
            }
        }
    } catch (Exception e) {
        terminate();
        throw new JobException(e.toString(), e, false);
    }
    terminate();
    jobTerminationListener.jobTerminated();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " done");
}
Also used : JobException(com.swiftmq.swiftlet.scheduler.JobException) AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) QueueException(com.swiftmq.swiftlet.queue.QueueException) QueueException(com.swiftmq.swiftlet.queue.QueueException) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Example 14 with QueueException

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

the class SessionHandler method doSendOneMessage.

private void doSendOneMessage(SourceMessageProcessor sourceMessageProcessor, SourceLink sourceLink, Delivery delivery, boolean restart) throws EndWithErrorException {
    try {
        if (remoteIncomingWindow > 0 && outgoingWindow > 0) {
            do {
                boolean wasFirstPacket = false;
                delivery.setMaxFrameSize(amqpHandler.getMaxFrameSize());
                TransferFrame frame = new TransferFrame(channel);
                frame.setHandle(new Handle(sourceLink.getHandle()));
                frame.setSettled(new AMQPBoolean(sourceLink.getSndSettleMode() == SenderSettleMode.SETTLED.getValue()));
                if (delivery.getCurrentPacketNumber() == 0) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", doSendOneMessage, amqpMessage=" + delivery.getAmqpMessage());
                    long totalSize = delivery.getSize();
                    wasFirstPacket = true;
                    sourceLink.incDeliveryCountSnd();
                    long dId = nextDeliveryId();
                    frame.setDeliveryId(new DeliveryNumber(dId));
                    frame.setDeliveryTag(createDeliveryTag(delivery));
                    TxnIdIF currentTx = sourceLink.getCurrentTx();
                    if (currentTx != null) {
                        TransactionalState tState = new TransactionalState();
                        tState.setTxnId(currentTx);
                        frame.setState(tState);
                        transactionRegistry.addToTransaction(currentTx, sourceLink, dId, delivery.getMessageIndex(), totalSize);
                        totalSize = 0;
                    }
                    if (!frame.getSettled().getValue()) {
                        unsettledOutgoingDeliveries.put(dId, sourceLink);
                        if (totalSize > 0)
                            sourceLink.addUnsettled(dId, delivery.getMessageIndex(), totalSize);
                        else
                            sourceLink.addUnsettled(dId, delivery.getMessageIndex());
                    } else {
                        sourceLink.autoack(delivery.getMessageIndex());
                    }
                    incMsgsSent(1);
                }
                delivery.getNextPacket(frame);
                // We may increase the outgoing window and send a flow before
                if (wasFirstPacket && outgoingWindow - delivery.getPredictedNumberPackets() < 0) {
                    outgoingWindow += delivery.getPredictedNumberPackets();
                    sendFlow();
                    windowChanged = true;
                }
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", doSendOneMessage, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", sending message, wasFirstPacket=" + wasFirstPacket + ", maxSize=" + delivery.getMaxPayloadLength() + ", packetSize=" + frame.getPayload().length + ", predictedNumberPackets=" + delivery.getPredictedNumberPackets() + ", currentPacket=" + delivery.getCurrentPacketNumber() + ", hasMore=" + delivery.hasMore());
                versionedConnection.send(frame);
                if (!frame.getSettled().getValue())
                    outgoingWindow--;
                nextOutgoingId++;
                remoteIncomingWindow--;
                if (!delivery.hasMore()) {
                    if (restart) {
                        if (sourceLink.getLinkCredit() > 0)
                            sourceLink.startMessageProcessor(sourceMessageProcessor);
                        else
                            sourceLink.clearMessageProcessor();
                    }
                    // If that was the last packet and outgoing window was increased for this message, we need to reset it and send another flow
                    if (windowChanged) {
                        outgoingWindow = initialOutgoingWindow;
                        sendFlow();
                    }
                    break;
                }
            } while (remoteIncomingWindow > 0 && outgoingWindow > 0);
            if (delivery.hasMore()) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", doSendOneMessage, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", has more but no window, storing message");
                outboundDeliveries.add(new OutboundDelivery(sourceMessageProcessor, sourceLink, delivery, restart));
            }
        } else {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", doSendOneMessage, no remote incoming window = " + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", store for later transfer");
            outboundDeliveries.add(new OutboundDelivery(sourceMessageProcessor, sourceLink, delivery, restart));
        }
    } catch (IOException e) {
        throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString("IOException during outbound send: " + e.getMessage()));
    } catch (QueueException e) {
        throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString("QueueException during outbound send: " + e.getMessage()));
    }
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) IOException(java.io.IOException) TransactionalState(com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState) QueueException(com.swiftmq.swiftlet.queue.QueueException)

Example 15 with QueueException

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

the class CompositeQueue method putMessage.

public void putMessage(Object object, MessageImpl message) throws QueueException {
    if (ctx.queueSpace.enabled)
        ctx.queueSpace.trace(getQueueName(), "putMessage, cTxId=" + object + " ...");
    boolean needCopy = false;
    boolean hasDefaultDelivery = false;
    int timesDelivered = 0;
    List entries = ((CompositeTransactionId) object).getEntries();
    for (int i = 0; i < entries.size(); i++) {
        CompositeTransactionIdEntry entry = (CompositeTransactionIdEntry) entries.get(i);
        if (entry.isDefaultBinding)
            hasDefaultDelivery = true;
        if (!entry.isDefaultBinding && (entry.selector == null || entry.selector.isSelected(message))) {
            try {
                MessageImpl m = message;
                if (needCopy)
                    m = copyMessage(message);
                else
                    needCopy = true;
                if (entry.generateNewMessageId)
                    m.setJMSMessageID(nextId());
                if (entry.changeDestination)
                    m.setJMSDestination(new QueueImpl(ctx.queueManager.fqn(entry.originalName)));
                if (!entry.isQueue)
                    m.setJMSDestination(new TopicImpl(entry.originalName));
                if (ctx.queueSpace.enabled)
                    ctx.queueSpace.trace(getQueueName(), "putMessage on binding '" + entry.queue.getQueueName());
                entry.queue.putMessage(entry.txId, m);
                timesDelivered++;
            } catch (Exception e) {
                ctx.logSwiftlet.logError(ctx.queueManager.getName(), "Composite Queue '" + getQueueName() + "': putMessage on binding queue '" + entry.queue.getQueueName() + "', exception=" + e);
                if (ctx.queueSpace.enabled)
                    ctx.queueSpace.trace(getQueueName(), "putMessage on binding queue '" + entry.queue.getQueueName() + "', exception=" + e);
            }
        }
    }
    if (ctx.queueSpace.enabled)
        ctx.queueSpace.trace(getQueueName(), "putMessage delivered to " + timesDelivered + " bindings, hasDefaultDelivery=" + hasDefaultDelivery);
    if (timesDelivered == 0 && hasDefaultDelivery) {
        if (ctx.queueSpace.enabled)
            ctx.queueSpace.trace(getQueueName(), "putMessage, let's check the default bindings ...");
        for (int i = 0; i < entries.size(); i++) {
            CompositeTransactionIdEntry entry = (CompositeTransactionIdEntry) entries.get(i);
            if (entry.isDefaultBinding) {
                try {
                    MessageImpl m = message;
                    if (needCopy)
                        m = copyMessage(message);
                    else
                        needCopy = true;
                    if (entry.generateNewMessageId)
                        m.setJMSMessageID(nextId());
                    if (entry.changeDestination)
                        m.setJMSDestination(new QueueImpl(ctx.queueManager.fqn(entry.originalName)));
                    if (!entry.isQueue)
                        m.setJMSDestination(new TopicImpl(entry.originalName));
                    if (ctx.queueSpace.enabled)
                        ctx.queueSpace.trace(getQueueName(), "putMessage on DEFAULT binding '" + entry.queue.getQueueName());
                    entry.queue.putMessage(entry.txId, m);
                } catch (Exception e) {
                    ctx.logSwiftlet.logError(ctx.queueManager.getName(), "Composite Queue '" + getQueueName() + "': putMessage on binding queue '" + entry.queue.getQueueName() + "', exception=" + e);
                    if (ctx.queueSpace.enabled)
                        ctx.queueSpace.trace(getQueueName(), "putMessage on binding queue '" + entry.queue.getQueueName() + "', exception=" + e);
                }
            }
        }
    }
    if (ctx.queueSpace.enabled)
        ctx.queueSpace.trace(getQueueName(), "putMessage, cTxId=" + object + " done");
}
Also used : List(java.util.List) TopicImpl(com.swiftmq.jms.TopicImpl) MessageImpl(com.swiftmq.jms.MessageImpl) QueueImpl(com.swiftmq.jms.QueueImpl) UnknownHostException(java.net.UnknownHostException) QueueException(com.swiftmq.swiftlet.queue.QueueException) InvalidSelectorException(javax.jms.InvalidSelectorException)

Aggregations

QueueException (com.swiftmq.swiftlet.queue.QueueException)20 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)8 EntityRemoveException (com.swiftmq.mgmt.EntityRemoveException)7 JMSException (javax.jms.JMSException)7 Property (com.swiftmq.mgmt.Property)3 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)3 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)3 NonPersistentStore (com.swiftmq.swiftlet.store.NonPersistentStore)3 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)2 MessageImpl (com.swiftmq.jms.MessageImpl)2 QueueImpl (com.swiftmq.jms.QueueImpl)2 TopicImpl (com.swiftmq.jms.TopicImpl)2 EntityList (com.swiftmq.mgmt.EntityList)2 PropertyChangeException (com.swiftmq.mgmt.PropertyChangeException)2 PersistentStore (com.swiftmq.swiftlet.store.PersistentStore)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)1 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)1