use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.
the class XARecoveryContextImpl method commit.
public synchronized long commit(boolean onePhase) throws XAContextException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/commit onePhase=" + onePhase + " ...");
if (closed)
throw new XAContextException(XAException.XAER_PROTO, "XA transaction is in closed state");
if (onePhase)
throw new XAContextException(XAException.XAER_PROTO, "Operation is not supported on a XARecoveryContextImpl");
for (int i = 0; i < transactions.size(); i++) {
Object[] wrapper = (Object[]) transactions.get(i);
try {
((AbstractQueue) wrapper[0]).commit(wrapper[1], xid);
ctx.logSwiftlet.logInformation(ctx.xaSwiftlet.getName(), toString() + "commit xid=" + signature);
} catch (Exception e) {
if (!ctx.queueManager.isTemporaryQueue(((AbstractQueue) wrapper[0]).getQueueName()))
ctx.logSwiftlet.logError(ctx.xaSwiftlet.getName(), toString() + "commit (two phase) xid=" + signature + ", failed for queue: " + ((AbstractQueue) wrapper[0]).getQueueName());
}
}
if (liveContext != null)
liveContext.commit(onePhase);
removeUsageEntity();
close();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/commit onePhase=" + onePhase + " done");
return 0;
}
use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.
the class XADeliveryStage method close.
public void close() {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close ...");
super.close();
closed = true;
if (notificationList.size() > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, final notify ...");
for (Iterator iter = notificationList.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
DeliveryRequest dr = (DeliveryRequest) entry.getValue();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, final notify: " + dr);
dr.callback.delivered(dr);
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, final notify done");
notificationList.clear();
}
if (outboundTransactions.size() > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared outbound tx to XAResourceManager ...");
for (Iterator iter = outboundTransactions.entrySet().iterator(); iter.hasNext(); ) {
try {
Map.Entry entry = (Map.Entry) iter.next();
XidImpl xid = (XidImpl) entry.getKey();
XAContext xac = ctx.xaResourceManagerSwiftlet.createXAContext(xid);
int id = xac.register(toString());
QueuePullTransaction t = (QueuePullTransaction) entry.getValue();
xac.addTransaction(id, t.getQueueName(), t);
xac.unregister(id, false);
xac.setPrepared(true);
} catch (XAContextException e) {
ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared outbound tx to XAResourceManager, exception: " + e);
}
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared outbound tx to XAResourceManager done");
outboundTransactions.clear();
}
if (inboundTransactions.size() > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared inbound tx to XAResourceManager ...");
for (Iterator iter = inboundTransactions.entrySet().iterator(); iter.hasNext(); ) {
((Tx) ((Map.Entry) iter.next()).getValue()).handOver();
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared inbound tx to XAResourceManager done");
}
for (Iterator iter = producers.entrySet().iterator(); iter.hasNext(); ) {
QueueSender sender = (QueueSender) ((Map.Entry) iter.next()).getValue();
try {
sender.close();
} catch (Exception e) {
}
}
producers.clear();
for (Iterator iter = consumers.entrySet().iterator(); iter.hasNext(); ) {
QueueReceiver receiver = (QueueReceiver) ((Map.Entry) iter.next()).getValue();
try {
receiver.close();
} catch (Exception e) {
}
}
consumers.clear();
if (throttleQueue != null)
throttleQueue.close();
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.START_STAGE_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.SEND_ROUTE_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.DELIVERY_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.ROUTE_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.ADJUST_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.TRANSACTION_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.COMMIT_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.COMMIT_REPREQ, null);
}
use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.
the class XARecoveryStage method doRecover.
private void doRecover(List localXids, List remoteXids) {
// Nothing to recover
if (localXids == null && remoteXids == null) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover, nothing to do");
return;
}
List remoteRecoveryList = new ArrayList();
// Check local vs remote
if (localXids != null) {
for (int i = 0; i < localXids.size(); i++) {
XidImpl lXid = (XidImpl) localXids.get(i);
if (containsXid(remoteXids, lXid)) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover [" + lXid + "], local prepared, remote prepared, commit 1:local, 2:remote");
// local prepared, remote prepared, commit 1:local, 2:remote
XAContext xac = ctx.xaResourceManagerSwiftlet.getXAContext(lXid);
try {
xac.commit(false);
} catch (XAContextException e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover, exception=" + e);
ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), toString() + "/doRecover, commit, exception=" + e);
}
ctx.xaResourceManagerSwiftlet.removeXAContext(lXid);
remoteRecoveryList.add(new CommitRequest(lXid));
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover [" + lXid + "], local prepared, remote unknown, rollback local");
// local prepared, remote unknown, rollback local
XAContext xac = ctx.xaResourceManagerSwiftlet.getXAContext(lXid);
try {
xac.rollback();
} catch (XAContextException e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover, exception=" + e);
ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), toString() + "/doRecover, rollback, exception=" + e);
}
ctx.xaResourceManagerSwiftlet.removeXAContext(lXid);
}
}
}
// Check remote Xids not known locally
if (remoteXids != null) {
for (int i = 0; i < remoteXids.size(); i++) {
XidImpl rXid = (XidImpl) remoteXids.get(i);
if (!containsXid(localXids, rXid)) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover [" + rXid + "], remote prepared, locally already committed, commit remote");
// remote prepared, locally already committed, commit remote
remoteRecoveryList.add(new CommitRequest(rXid));
}
}
}
if (remoteRecoveryList.size() > 0) {
Collections.sort(remoteRecoveryList, new Comparator() {
public int compare(Object o1, Object o2) {
int i1 = ((CommitRequest) o1).getXid().getFormatId();
int i2 = ((CommitRequest) o2).getXid().getFormatId();
return i1 == i2 ? 0 : i1 < i2 ? -1 : 1;
}
});
for (int i = 0; i < remoteRecoveryList.size(); i++) {
CommitRequest r = (CommitRequest) remoteRecoveryList.get(i);
routingConnection.getOutboundQueue().enqueue(r);
}
}
}
Aggregations