use of com.swiftmq.jms.XidImpl in project swiftmq-client by iitsoftware.
the class XAResourceImpl method start.
public synchronized void start(Xid xid, int flags) throws XAException {
if (logWriter != null)
log(toString() + "/start, xid=" + xid + ", flags=" + flags);
XidImpl sxid = toSwiftMQXid(xid);
XAResStartReply reply = null;
try {
reply = (XAResStartReply) session.request(new XAResStartRequest(dispatchId, sxid, flags));
} catch (Exception e) {
XAException ex = new XAException(e.toString());
ex.errorCode = XAException.XAER_RMFAIL;
throw ex;
}
if (!reply.isOk()) {
XAException ex = new XAException(reply.getException().getMessage());
ex.errorCode = reply.getErrorCode();
throw ex;
} else {
try {
session.session.assignLastMessage();
} catch (Exception e) {
XAException ex = new XAException(reply.getException().getMessage());
ex.errorCode = reply.getErrorCode();
throw ex;
}
}
if (completionListener != null)
completionListener.transactionStarted(sxid, session);
}
use of com.swiftmq.jms.XidImpl in project swiftmq-client by iitsoftware.
the class XAResourceImpl method end.
public synchronized void end(Xid xid, int flags) throws XAException {
XidImpl sxid = toSwiftMQXid(xid);
XAResEndReply reply = null;
try {
reply = (XAResEndReply) session.request(new XAResEndRequest(dispatchId, sxid, flags));
} catch (Exception e) {
XAException ex = new XAException(e.toString());
ex.errorCode = XAException.XA_RBINTEGRITY;
throw ex;
}
if (!reply.isOk()) {
XAException ex = new XAException(reply.getException().getMessage());
ex.errorCode = reply.getErrorCode();
throw ex;
} else {
Object[] content = session.getAndClearCurrentTransaction();
if (content != null && content.length > 0)
xidContent.put(sxid, content);
}
}
use of com.swiftmq.jms.XidImpl in project swiftmq-client by iitsoftware.
the class XAResourceImpl method prepare.
public synchronized int prepare(Xid xid) throws XAException {
XidImpl sxid = toSwiftMQXid(xid);
XAResPrepareReply reply = null;
try {
reply = (XAResPrepareReply) session.request(new XAResPrepareRequest(dispatchId, sxid, (Object[]) xidContent.remove(sxid)));
} catch (Exception e) {
XAException ex = new XAException(e.toString());
ex.errorCode = XAException.XA_RBINTEGRITY;
throw ex;
}
if (!reply.isOk()) {
XAException ex = new XAException(reply.getException().getMessage());
ex.errorCode = reply.getErrorCode();
throw ex;
}
return XA_OK;
}
use of com.swiftmq.jms.XidImpl in project swiftmq-client by iitsoftware.
the class XAResourceImpl method commit.
public synchronized void commit(Xid xid, boolean onePhase) throws XAException {
XidImpl sxid = toSwiftMQXid(xid);
xidMapping.remove(xid);
XAResCommitReply reply = null;
try {
XAResCommitRequest req = new XAResCommitRequest(dispatchId, sxid, onePhase);
if (onePhase)
req.setMessages((Object[]) xidContent.remove(sxid));
reply = (XAResCommitReply) session.request(req);
} catch (Exception e) {
XAException ex = new XAException(e.toString());
ex.errorCode = XAException.XA_RBINTEGRITY;
throw ex;
}
if (!reply.isOk()) {
XAException ex = new XAException(reply.getException().getMessage());
ex.errorCode = reply.getErrorCode();
throw ex;
} else {
if (reply.getDelay() > 0) {
try {
Thread.sleep(reply.getDelay());
} catch (Exception ignored) {
}
}
}
}
use of com.swiftmq.jms.XidImpl in project swiftmq-ce by iitsoftware.
the class XADeliveryStage method processTransactionRequest.
private void processTransactionRequest(TransactionRequest request) throws Exception {
XidImpl xid = request.getXid();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + " ...");
Tx tx = new Tx(xid);
inboundTransactions.put(xid, tx);
List messageList = request.getMessageList();
for (int i = 0; i < messageList.size(); i++) {
boolean msgValid = true;
MessageImpl msg = (MessageImpl) messageList.get(i);
String queueName = null;
if (msg.getDestRouter().equals(ctx.routerName))
queueName = msg.getDestQueue();
else
queueName = SchedulerRegistry.QUEUE_PREFIX + msg.getDestRouter();
QueueSender sender = (QueueSender) producers.get(queueName);
if (sender == null) {
try {
sender = ctx.queueManager.createQueueSender(queueName, null);
producers.put(queueName, sender);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", exception creating sender, queue=" + queueName);
if (ctx.queueManager.isTemporaryQueue(queueName)) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", temp queue, forget it");
msgValid = false;
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", using unroutable queue");
sender = (QueueSender) producers.get(RoutingSwiftletImpl.UNROUTABLE_QUEUE);
msg.setStringProperty(MessageImpl.PROP_UNROUTABLE_REASON, e.toString());
}
}
}
if (msgValid) {
try {
QueuePushTransaction t = tx.getTransaction(queueName);
if (t == null) {
t = sender.createTransaction();
tx.addTransaction(queueName, t);
}
t.putMessage(msg);
} catch (Exception e) {
try {
if (!sender.getQueueName().startsWith(RoutingSwiftletImpl.UNROUTABLE_QUEUE))
sender.close();
} catch (Exception e1) {
}
producers.remove(queueName);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", exception put message, queue=" + queueName);
if (ctx.queueManager.isTemporaryQueue(queueName)) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", temp queue, forget it");
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", using unroutable queue");
sender = (QueueSender) producers.get(RoutingSwiftletImpl.UNROUTABLE_QUEUE);
msg.setStringProperty(MessageImpl.PROP_UNROUTABLE_REASON, e.toString());
QueuePushTransaction t = tx.getTransaction(RoutingSwiftletImpl.UNROUTABLE_QUEUE);
if (t == null) {
t = sender.createTransaction();
tx.addTransaction(RoutingSwiftletImpl.UNROUTABLE_QUEUE, t);
}
t.putMessage(msg);
}
}
}
}
try {
tx.prepare();
} catch (Exception e) {
tx.rollback();
inboundTransactions.remove(xid);
throw e;
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + " done");
}
Aggregations