Search in sources :

Example 21 with TxnIdIF

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

the class Requestor method sendRequests.

public void sendRequests() {
    try {
        AddressIF tempDest = consumer.getRemoteAddress();
        for (int i = 0; i < nMsgs; i++) {
            TxnIdIF txnIdIF = txc.createTxnId();
            AMQPMessage request = messageFactory.create(i);
            request.setTxnIdIF(txnIdIF);
            Properties prop = new Properties();
            prop.setReplyTo(tempDest);
            request.setProperties(prop);
            producer.send(request, persistent, 5, -1);
            txc.commit(txnIdIF);
            txnIdIF = txc.createTxnId();
            AMQPMessage reply = consumer.receive();
            if (reply == null)
                throw new Exception("Reply is null");
            if (!reply.isSettled())
                reply.accept();
            txc.commit(txnIdIF);
        }
    } catch (Exception e) {
        fail("test failed: " + e);
    }
}
Also used : AddressIF(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF) TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 22 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-client by iitsoftware.

the class SessionDispatcher method doSend.

private void doSend(POSendMessage po) {
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", doSend, po=" + po + ", dataLength=" + po.getPackager().getSize());
    try {
        Producer producer = po.getProducer();
        producer.verifyState();
        Packager packager = po.getPackager();
        if (remoteIncomingWindow > 0 && outgoingWindow > 0) {
            do {
                boolean wasFirstPacket = false;
                boolean isAtMostOnce = producer.getQoS() == QoS.AT_MOST_ONCE;
                packager.setMaxFrameSize(mySession.myConnection.connectionDispatcher.getMaxFrameSize());
                TransferFrame frame = new TransferFrame(mySession.getChannel());
                frame.setHandle(new Handle(producer.getHandle()));
                frame.setSettled(new AMQPBoolean(isAtMostOnce));
                if (packager.getCurrentPacketNumber() == 0) {
                    long dId = nextDeliveryId();
                    wasFirstPacket = true;
                    producer.incDeliveryCountSnd();
                    DeliveryTag deliveryTag = po.getDeliveryTag() != null ? po.getDeliveryTag() : producer.createDeliveryTag();
                    if (!isAtMostOnce) {
                        if (po.getTxnId() == null && !po.isRecovery())
                            producer.getDeliveryMemory().addUnsettledDelivery(new UnsettledDelivery(deliveryTag, null, po.getMessage()));
                        unsettledOutgoingDeliveries.put(dId, new DeliveryMapping(deliveryTag, producer));
                    }
                    frame.setDeliveryTag(deliveryTag);
                    frame.setDeliveryId(new DeliveryNumber(dId));
                    frame.setMessageFormat(new MessageFormat(0));
                    TxnIdIF txnId = po.getTxnId();
                    if (txnId != null) {
                        TransactionalState txState = new TransactionalState();
                        txState.setTxnId(txnId);
                        frame.setState(txState);
                    }
                }
                packager.setMessageFormat(0);
                packager.getNextPacket(frame);
                // We may increase the outgoing window and send a flow before
                if (wasFirstPacket && outgoingWindow - packager.getPredictedNumberPackets() < 0) {
                    outgoingWindow += packager.getPredictedNumberPackets();
                    sendFlow();
                    windowChanged = true;
                }
                if (pTracer.isEnabled())
                    pTracer.trace(toString(), ", doSend, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", sending message, wasFirstPacket=" + wasFirstPacket + ", maxSize=" + packager.getMaxPayloadLength() + ", packetSize=" + frame.getPayload().length + ", predictedNumberPackets=" + packager.getPredictedNumberPackets() + ", currentPacket=" + packager.getCurrentPacketNumber() + ", hasMore=" + packager.hasMore());
                outboundHandler.send(frame);
                nextOutgoingId++;
                remoteIncomingWindow--;
                if (!isAtMostOnce)
                    outgoingWindow--;
                if (!packager.hasMore()) {
                    // b) everything else: after the last packet has been sent
                    if (producer.isTransactionController() || po.getTxnId() != null)
                        producer.setWaitingPO(po);
                    else {
                        po.setSuccess(true);
                        if (po.getSemaphore() != null)
                            po.getSemaphore().notifySingleWaiter();
                    }
                    // 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 = mySession.getOutgoingWindowSize();
                        sendFlow();
                    }
                    break;
                }
            } while (remoteIncomingWindow > 0 && outgoingWindow > 0);
            if (packager.hasMore()) {
                if (pTracer.isEnabled())
                    pTracer.trace(toString(), ", doSend, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", has more but no window, storing message");
                outboundDeliveries.add(po);
            }
        } else {
            if (pTracer.isEnabled())
                pTracer.trace(toString(), ", doSend, po=" + po + ", remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", no window, storing message");
            outboundDeliveries.add(po);
        }
    } catch (Exception e) {
        po.setSuccess(false);
        po.setException(e.getMessage());
        if (po.getSemaphore() != null)
            po.getSemaphore().notifySingleWaiter();
    }
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) IOException(java.io.IOException) TransactionalState(com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState) Packager(com.swiftmq.amqp.v100.transport.Packager)

Example 23 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-client by iitsoftware.

the class SessionDispatcher method visit.

public void visit(POFillCache po) {
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " ...");
    Consumer c = po.getConsumer();
    FlowFrame flowFrame = new FlowFrame(mySession.getChannel());
    flowFrame.setHandle(new Handle(c.getHandle()));
    flowFrame.setAvailable(new AMQPUnsignedInt(0));
    flowFrame.setDrain(AMQPBoolean.FALSE);
    flowFrame.setNextIncomingId(new TransferNumber(nextIncomingId));
    flowFrame.setNextOutgoingId(new TransferNumber(nextOutgoingId));
    flowFrame.setLinkCredit(new AMQPUnsignedInt(po.getLinkCredit()));
    flowFrame.setIncomingWindow(new AMQPUnsignedInt(incomingWindow));
    flowFrame.setOutgoingWindow(new AMQPUnsignedInt(outgoingWindow));
    if (po.getLastDeliveryId() != -1)
        flowFrame.setDeliveryCount(new SequenceNo(po.getLastDeliveryId()));
    TxnIdIF txnIdIF = po.getTxnIdIF();
    if (txnIdIF != null) {
        Map map = new HashMap();
        map.put(new AMQPSymbol("txn-id"), txnIdIF);
        try {
            flowFrame.setProperties(new Fields(map));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    outboundHandler.send(flowFrame);
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " done");
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) IOException(java.io.IOException)

Example 24 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-client by iitsoftware.

the class TransactionController method createTxnId.

/**
 * Creates a new transaction id.
 *
 * @return transaction id
 * @throws AMQPException on error
 */
public synchronized TxnIdIF createTxnId() throws AMQPException {
    if (producer == null) {
        producer = mySession.createProducer(Coordinator.DESCRIPTOR_NAME, QoS.AT_LEAST_ONCE);
        producer.setTransactionController(true);
        Set capa = producer.getDestinationCapabilities();
        if (capa != null) {
            if (capa.contains(TxnCapability.LOCAL_TRANSACTIONS.getValue()))
                supportLocalTransactions = true;
            supportDistributedTransactions = capa.contains(TxnCapability.DISTRIBUTED_TRANSACTIONS.getValue());
            supportPromotableTransactions = capa.contains(TxnCapability.PROMOTABLE_TRANSACTIONS.getValue());
            supportMultiTxnsPerSsn = capa.contains(TxnCapability.MULTI_TXNS_PER_SSN.getValue());
            supportMultiSsnsPerTxn = capa.contains(TxnCapability.MULTI_SSNS_PER_TXN.getValue());
        }
    }
    AMQPMessage msg = new AMQPMessage();
    msg.setAmqpValue(new AmqpValue(new Declare()));
    Declared declared = (Declared) producer.send(msg);
    return declared == null ? null : declared.getTxnId();
}
Also used : Set(java.util.Set) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Example 25 with TxnIdIF

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

Aggregations

TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)22 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)21 AddressIF (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF)8 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)8 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)8 DeliveryStateIF (com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)5 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)5 Producer (com.swiftmq.amqp.v100.client.Producer)4 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)4 QueueException (com.swiftmq.swiftlet.queue.QueueException)4 IOException (java.io.IOException)4 AMQPContext (com.swiftmq.amqp.AMQPContext)3 JSSESocketFactory (com.swiftmq.net.JSSESocketFactory)3 HashMap (java.util.HashMap)3 InvalidStateException (com.swiftmq.amqp.v100.client.InvalidStateException)2 Rejected (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Rejected)2 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)2 Accepted (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)1 TransactionId (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionId)1 Packager (com.swiftmq.amqp.v100.transport.Packager)1