use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.
the class TransactionRegistry method addToTransaction.
public void addToTransaction(TxnIdIF txnIdIF, DispositionFrame frame) throws EndWithErrorException {
String txnId = new String(((TransactionId) txnIdIF).getValue());
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", frame=" + frame);
long from = frame.getFirst().getValue();
long to = from;
if (frame.getLast() != null)
to = frame.getLast().getValue();
DeliveryStateIF deliveryStateIF = frame.getState();
long current = from;
while (current <= to) {
addToTransaction(txnId, current, deliveryStateIF);
current++;
}
}
use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.
the class TransactionRegistry method discharge.
public void discharge(TxnIdIF btxnId, boolean rollback) throws EndWithErrorException {
String txnId = new String(((TransactionId) btxnId).getValue());
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/discharge, txnId=" + txnId + ", rollback=" + rollback);
lock.lock();
try {
ActiveTxEntry activeTxEntry = (ActiveTxEntry) activeTx.remove(txnId);
if (activeTxEntry == null) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/discharge, txnId=" + txnId + ", not found!");
throw new SessionEndException(TransactionError.UNKNOWN_ID, new AMQPString("Transaction id not found: " + txnId));
}
if (activeTxEntry.inboundTxEntryMap != null) {
for (Iterator iter = activeTxEntry.inboundTxEntryMap.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
InboundTxEntry inboundTxEntry = (InboundTxEntry) entry.getValue();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/discharge txnid=" + txnId + ", linkName=" + entry.getKey());
if (rollback)
inboundTxEntry.tx.rollback();
else
inboundTxEntry.tx.commit();
inboundTxEntry.targetLink.setFlowcontrolDelay(inboundTxEntry.tx.getFlowControlDelay());
inboundTxEntry.targetLink.decreaseActiveTransactions();
inboundTxEntry.targetLink.closeResource();
}
activeTxEntry.inboundTxEntryMap.clear();
}
if (activeTxEntry.outboundTxEntryMap != null) {
for (Iterator iter = activeTxEntry.outboundTxEntryMap.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
long deliveryId = ((Long) entry.getKey()).longValue();
OutboundTxEntry outboundTxEntry = (OutboundTxEntry) entry.getValue();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/discharge txnid=" + txnId + ", deliveryId=" + deliveryId);
if (rollback) {
if (outboundTxEntry.sourceLink != null)
sessionHandler.settleOutbound(deliveryId, RELEASED);
} else
sessionHandler.settleOutbound(deliveryId, outboundTxEntry.deliveryStateIF);
if (outboundTxEntry.sourceLink != null) {
outboundTxEntry.sourceLink.decreaseActiveTransactions();
outboundTxEntry.sourceLink.closeResource();
}
}
activeTxEntry.outboundTxEntryMap.clear();
sessionHandler.sendOutboundDeliveries();
}
} catch (QueueException e) {
throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString(e.toString()));
} finally {
lock.unlock();
}
}
use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.
the class TransactionRegistry method createTxId.
public TxnIdIF createTxId() {
lock.lock();
try {
StringBuffer b = new StringBuffer();
b.append(startupTime);
b.append('-');
b.append(++lastId);
String id = b.toString();
activeTx.put(id, new ActiveTxEntry());
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/createTxId: " + id);
return new TransactionId(id.getBytes());
} finally {
lock.unlock();
}
}
use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.
the class TransactionRegistry method addToTransaction.
public void addToTransaction(TxnIdIF btxnId, String linkName, MessageImpl message, TargetLink targetLink) throws EndWithErrorException {
String txnId = new String(((TransactionId) btxnId).getValue());
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", linkName=" + linkName + ", message=" + message);
lock.lock();
try {
ActiveTxEntry activeTxEntry = (ActiveTxEntry) activeTx.get(txnId);
if (activeTxEntry == null) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", not found!");
throw new SessionEndException(TransactionError.UNKNOWN_ID, new AMQPString("Transaction id not found: " + txnId));
}
if (activeTxEntry.inboundTxEntryMap == null)
activeTxEntry.inboundTxEntryMap = new HashMap();
InboundTxEntry inboundTxEntry = (InboundTxEntry) activeTxEntry.inboundTxEntryMap.get(linkName);
try {
if (inboundTxEntry == null) {
QueuePushTransaction tx = targetLink.getQueueSender().createTransaction();
targetLink.increaseActiveTransactions();
inboundTxEntry = new InboundTxEntry(tx, targetLink);
activeTxEntry.inboundTxEntryMap.put(linkName, inboundTxEntry);
}
((QueuePushTransaction) inboundTxEntry.tx).putMessage(message);
} catch (QueueException e) {
throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString(e.toString()));
}
} finally {
lock.unlock();
}
}
use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.
the class Replier method serviceRequests.
public void serviceRequests() {
try {
for (int i = 0; i < nMsgs; i++) {
TxnIdIF txnIdIF = txc.createTxnId();
AMQPMessage request = consumer.receive();
request.setTxnIdIF(txnIdIF);
if (request != null) {
messageFactory.verify(request);
if (!request.isSettled())
request.accept();
Properties prop = request.getProperties();
if (prop == null)
throw new Exception("Properties not set in request: " + request);
AddressIF replyTo = prop.getReplyTo();
if (replyTo == null)
throw new Exception("replyTo not set in request: " + request);
Producer p = getSession().createProducer(replyTo.getValueString(), qos);
AMQPMessage reply = messageFactory.createReplyMessage(request);
reply.setTxnIdIF(txnIdIF);
Properties prop2 = new Properties();
prop2.setTo(replyTo);
prop2.setCorrelationId(prop.getMessageId());
reply.setProperties(prop2);
p.send(reply);
p.close();
} else
throw new Exception("Msg == null at i=" + i);
txc.commit(txnIdIF);
}
} catch (Exception e) {
fail("test failed: " + e);
}
}
Aggregations