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);
}
}
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();
}
}
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");
}
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();
}
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()));
}
}
Aggregations