Search in sources :

Example 6 with TransactionalState

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState 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 7 with TransactionalState

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState in project swiftmq-ce by iitsoftware.

the class TargetLink method addTransferFrame.

public boolean addTransferFrame(TransferFrame frame) throws EndWithErrorException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addTransferFrame, frame=" + frame);
    if (currentMessage == null)
        currentMessage = frame;
    else {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addTransferFrame, frame=" + frame + ", add payload to currentMessage");
        currentMessage.addMorePayload(frame.getPayload());
        if (frame.getSettled() != null)
            currentMessage.setSettled(frame.getSettled());
    }
    if (frame.getMore() != null && frame.getMore().getValue())
        return false;
    boolean settled = false;
    if (currentMessage.getSettled() != null)
        settled = currentMessage.getSettled().getValue();
    lastDeliveryId = currentMessage.getDeliveryId();
    DeliveryStateIF state = currentMessage.getState();
    if (settled || rcvSettleMode == ReceiverSettleMode.FIRST.getValue() || state != null && state instanceof TransactionalState)
        transformAndStore(currentMessage);
    else
        unsettledFrames.put(currentMessage.getDeliveryId().getValue(), currentMessage);
    deliveryCount++;
    currentLinkCredit--;
    nmsgs++;
    boolean needMore = currentLinkCredit == 0;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addTransferFrame, frame=" + frame + ", currentLinkCredit=" + currentLinkCredit + ", needMore=" + needMore);
    if (needMore)
        currentLinkCredit = linkCredit;
    currentMessage = null;
    return needMore;
}
Also used : DeliveryStateIF(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)

Aggregations

TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)5 DeliveryStateIF (com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)4 IOException (java.io.IOException)4 InvalidStateException (com.swiftmq.amqp.v100.client.InvalidStateException)2 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)2 QueueException (com.swiftmq.swiftlet.queue.QueueException)2 Accepted (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)1 Rejected (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Rejected)1 Declared (com.swiftmq.amqp.v100.generated.transactions.coordination.Declared)1 Packager (com.swiftmq.amqp.v100.transport.Packager)1 MessageImpl (com.swiftmq.jms.MessageImpl)1 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)1 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)1 TopicException (com.swiftmq.swiftlet.topic.TopicException)1 MalformedURLException (java.net.MalformedURLException)1 InvalidSelectorException (javax.jms.InvalidSelectorException)1