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 {
if (logWriter != null)
log(toString() + "/commit, xid=" + xid + ", onePhase=" + onePhase);
XidImpl sxid = toSwiftMQXid(xid);
xidMapping.remove(xid);
XAResCommitReply reply = null;
try {
int connectionId = session.getSessionImpl().getMyConnection().getConnectionId();
XAResCommitRequest req = new XAResCommitRequest(this, session.getDispatchId(), sxid, onePhase, false, onePhase && endRequestInDoubt() ? XARecoverRegistry.getInstance().getRequestList(sxid) : null);
req.setConnectionId(connectionId);
reply = (XAResCommitReply) session.request(req);
} catch (Exception e) {
if (completionListener != null)
completionListener.transactionCommitted(sxid);
XAException ex = new XAException(e.toString());
ex.errorCode = XAException.XAER_RMFAIL;
throw ex;
}
if (!reply.isOk()) {
if (completionListener != null)
completionListener.transactionCommitted(sxid);
XAException ex = new XAException(reply.getException().getMessage());
if (reply.getErrorCode() != 0)
ex.errorCode = reply.getErrorCode();
else
ex.errorCode = XAException.XAER_RMFAIL;
throw ex;
} else {
try {
session.getSessionImpl().afterCommit();
} catch (JMSException e) {
XAException ex = new XAException(e.toString());
ex.errorCode = XAException.XAER_RMFAIL;
throw ex;
}
if (reply.getDelay() > 0) {
try {
Thread.sleep(reply.getDelay());
} catch (Exception ignored) {
}
}
if (completionListener != null)
completionListener.transactionCommitted(sxid);
XARecoverRegistry.getInstance().clear(sxid);
}
}
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 {
if (logWriter != null)
log(toString() + "/prepare, xid=" + xid);
XidImpl sxid = toSwiftMQXid(xid);
XAResPrepareReply reply = null;
try {
int connectionId = session.getSessionImpl().getMyConnection().getConnectionId();
Request request = new XAResPrepareRequest(this, session.getDispatchId(), sxid, false, endRequestInDoubt() ? XARecoverRegistry.getInstance().getRequestList(sxid) : null);
request.setConnectionId(connectionId);
reply = (XAResPrepareReply) session.request(request);
} 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());
if (reply.getErrorCode() != 0)
ex.errorCode = reply.getErrorCode();
else
ex.errorCode = XAException.XAER_RMFAIL;
throw ex;
}
XARecoverRegistry.getInstance().clear(sxid);
return XA_OK;
}
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 {
if (logWriter != null)
log(toString() + "/end, xid=" + xid + ", flags=" + flags);
XidImpl sxid = toSwiftMQXid(xid);
XAResEndReply reply = null;
XAResEndRequest request = null;
try {
int connectionId = session.getSessionImpl().getMyConnection().getConnectionId();
List content = session.getAndClearCurrentTransaction();
if (content != null && content.size() == 0)
content = null;
request = new XAResEndRequest(this, session.getDispatchId(), sxid, flags, false, content, XARecoverRegistry.getInstance().getRequestList(sxid));
request.setConnectionId(connectionId);
lastEndRequestConnectionId = connectionId;
reply = (XAResEndReply) session.request(request);
} 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());
if (reply.getErrorCode() != 0)
ex.errorCode = reply.getErrorCode();
else
ex.errorCode = XAException.XAER_RMFAIL;
throw ex;
}
request.setRecoverRequestList(null);
XARecoverRegistry.getInstance().addRequest(sxid, request);
if (completionListener != null)
completionListener.transactionEnded(sxid);
}
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 {
if (logWriter != null)
log(toString() + "/end, xid=" + xid + ", flags=" + flags);
XidImpl sxid = toSwiftMQXid(xid);
XAResEndReply reply = null;
XAResEndRequest request = null;
try {
int connectionId = session.getSessionImpl().getMyConnection().getConnectionId();
List content = session.getAndClearCurrentTransaction();
if (content != null && content.size() == 0)
content = null;
request = new XAResEndRequest(this, session.getDispatchId(), sxid, flags, false, content, XARecoverRegistry.getInstance().getRequestList(sxid));
request.setConnectionId(connectionId);
lastEndRequestConnectionId = connectionId;
reply = (XAResEndReply) session.request(request);
} 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());
if (reply.getErrorCode() != 0)
ex.errorCode = reply.getErrorCode();
else
ex.errorCode = XAException.XAER_RMFAIL;
throw ex;
}
request.setRecoverRequestList(null);
XARecoverRegistry.getInstance().addRequest(sxid, request);
if (completionListener != null)
completionListener.transactionEnded(sxid);
}
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 {
if (logWriter != null)
log(toString() + "/commit, xid=" + xid + ", onePhase=" + onePhase);
XidImpl sxid = toSwiftMQXid(xid);
xidMapping.remove(xid);
XAResCommitReply reply = null;
try {
int connectionId = session.getSessionImpl().getMyConnection().getConnectionId();
XAResCommitRequest req = new XAResCommitRequest(this, session.getDispatchId(), sxid, onePhase, false, onePhase && endRequestInDoubt() ? XARecoverRegistry.getInstance().getRequestList(sxid) : null);
req.setConnectionId(connectionId);
reply = (XAResCommitReply) session.request(req);
} catch (Exception e) {
if (completionListener != null)
completionListener.transactionCommitted(sxid);
XAException ex = new XAException(e.toString());
ex.errorCode = XAException.XAER_RMFAIL;
throw ex;
}
if (!reply.isOk()) {
if (completionListener != null)
completionListener.transactionCommitted(sxid);
XAException ex = new XAException(reply.getException().getMessage());
if (reply.getErrorCode() != 0)
ex.errorCode = reply.getErrorCode();
else
ex.errorCode = XAException.XAER_RMFAIL;
throw ex;
} else {
try {
session.getSessionImpl().afterCommit();
} catch (JMSException e) {
XAException ex = new XAException(e.toString());
ex.errorCode = XAException.XAER_RMFAIL;
throw ex;
}
if (reply.getDelay() > 0) {
try {
Thread.sleep(reply.getDelay());
} catch (Exception ignored) {
}
}
if (completionListener != null)
completionListener.transactionCommitted(sxid);
XARecoverRegistry.getInstance().clear(sxid);
}
}
Aggregations