use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.
the class XARecoveryStage method init.
protected void init() {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init...");
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.START_STAGE_REQ, new RequestHandler() {
public void visited(Request request) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + "...");
RecoveryRequest rc = new RecoveryRequest();
rc.setBranchQualifier(recoveryBranchQ);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + ", sending request=" + rc);
routingConnection.getOutboundQueue().enqueue(rc);
routingConnection.setXaSelected(true);
}
});
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.RECOVERY_REPREQ, new RequestHandler() {
public void visited(Request request) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + "...");
RecoveryReplyRequest reply = (RecoveryReplyRequest) request;
if (reply.isOk()) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + ", do recovery");
// do recovery
List localXids = getPreparedXids(new Filter(recoveryBranchQ));
List remoteXids = reply.getXidList();
doRecover(localXids, remoteXids);
localRecovered = true;
if (remoteRecovered) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + ", launching delivery stage");
getStageQueue().setStage(new XADeliveryStage(ctx, routingConnection));
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + ", start remote delivery");
// start delivery
routingConnection.getOutboundQueue().enqueue(new StartDeliveryRequest());
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + ", disconnect");
ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/exception: " + reply.getException());
ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
}
}
});
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.RECOVERY_REQ, new RequestHandler() {
public void visited(Request request) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request);
// It then sends a request by itself to ensure the XARecoveryStage is active at the connector side.
if (listener)
getStageQueue().enqueue(new StartStageRequest());
RecoveryRequest pr = (RecoveryRequest) request;
RecoveryReplyRequest reply = new RecoveryReplyRequest();
reply.setOk(true);
// fill xid list
reply.setXidList(getPreparedXids(new Filter(pr.getBranchQualifier())));
routingConnection.getOutboundQueue().enqueue(reply);
remoteRecovered = true;
}
});
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.COMMIT_REQ, new RequestHandler() {
public void visited(Request request) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request);
CommitRequest cr = (CommitRequest) request;
XAContext xac = ctx.xaResourceManagerSwiftlet.getXAContext(cr.getXid());
try {
xac.commit(false);
} catch (XAContextException e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/visited, request=" + request + ", exception=" + e);
ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), toString() + "/visited, request=" + request + ", exception=" + e);
}
ctx.xaResourceManagerSwiftlet.removeXAContext(cr.getXid());
}
});
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.STARTDELIVERY_REQ, new RequestHandler() {
public void visited(Request request) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + ", launching delivery stage");
if (localRecovered && remoteRecovered)
getStageQueue().setStage(new XADeliveryStage(ctx, routingConnection));
}
});
if (!listener)
getStageQueue().enqueue(new StartStageRequest());
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init done");
}
use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.
the class XARecoveryStage method init.
protected void init() {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init...");
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.START_STAGE_REQ, new RequestHandler() {
public void visited(Request request) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + "...");
RecoveryRequest rc = new RecoveryRequest();
rc.setBranchQualifier(recoveryBranchQ);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + ", sending request=" + rc);
routingConnection.getOutboundQueue().enqueue(rc);
routingConnection.setXaSelected(true);
}
});
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.RECOVERY_REPREQ, new RequestHandler() {
public void visited(Request request) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + "...");
RecoveryReplyRequest reply = (RecoveryReplyRequest) request;
if (reply.isOk()) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + ", do recovery");
// do recovery
List localXids = getPreparedXids(new Filter(recoveryBranchQ));
List remoteXids = reply.getXidList();
doRecover(localXids, remoteXids);
localRecovered = true;
if (remoteRecovered) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + ", launching delivery stage");
getStageQueue().setStage(new XADeliveryStage(ctx, routingConnection));
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + ", start remote delivery");
// start delivery
routingConnection.getOutboundQueue().enqueue(new StartDeliveryRequest());
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + ", disconnect");
ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/exception: " + reply.getException());
ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
}
}
});
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.RECOVERY_REQ, new RequestHandler() {
public void visited(Request request) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request);
// It then sends a request by itself to ensure the XARecoveryStage is active at the connector side.
if (listener)
getStageQueue().enqueue(new StartStageRequest());
RecoveryRequest pr = (RecoveryRequest) request;
RecoveryReplyRequest reply = new RecoveryReplyRequest();
reply.setOk(true);
// fill xid list
reply.setXidList(getPreparedXids(new Filter(pr.getBranchQualifier())));
routingConnection.getOutboundQueue().enqueue(reply);
remoteRecovered = true;
}
});
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.COMMIT_REQ, new RequestHandler() {
public void visited(Request request) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request);
CommitRequest cr = (CommitRequest) request;
XAContext xac = ctx.xaResourceManagerSwiftlet.getXAContext(cr.getXid());
try {
xac.commit(false);
} catch (XAContextException e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/visited, request=" + request + ", exception=" + e);
ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), toString() + "/visited, request=" + request + ", exception=" + e);
}
ctx.xaResourceManagerSwiftlet.removeXAContext(cr.getXid());
}
});
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.STARTDELIVERY_REQ, new RequestHandler() {
public void visited(Request request) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), XARecoveryStage.this.toString() + "/visited, request=" + request + ", launching delivery stage");
if (localRecovered && remoteRecovered)
getStageQueue().setStage(new XADeliveryStage(ctx, routingConnection));
}
});
if (!listener)
getStageQueue().enqueue(new StartStageRequest());
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init done");
}
use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.
the class XALiveContextImpl method register.
public synchronized int register(String description) throws XAContextException {
if (prepared)
throw new XAContextException(XAException.XAER_PROTO, "XA transaction is in prepared state");
if (rollbackOnly)
throw new XAContextException(XAException.XA_RBROLLBACK, "XA transaction is marked as rollback-only");
if (wasTimeout)
throw new XAContextException(XAException.XA_RBTIMEOUT, "transaction timeout occured");
if (rolledBack)
throw new XAContextException(XAException.XA_RBROLLBACK, "XA transaction was rolled back from another thread");
if (closed)
throw new XAContextException(XAException.XAER_PROTO, "XA transaction is in closed state");
nReg++;
int id = ArrayListTool.setFirstFreeOrExpand(registrations, description);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/register, id=" + id + ", description: " + description);
return id;
}
use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.
the class XALiveContextImpl method commit.
public synchronized long commit(boolean onePhase) throws XAContextException {
long fcDelay = 0;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/commit onePhase=" + onePhase + " ...");
if (wasTimeout)
throw new XAContextException(XAException.XA_RBTIMEOUT, "transaction timeout occured");
if (closed)
throw new XAContextException(XAException.XAER_PROTO, "XA transaction is in closed state");
if (rollbackOnly)
throw new XAContextException(XAException.XA_RBROLLBACK, "XA transaction is marked as rollback-only");
for (int i = 0; i < recoveryTransactions.size(); i++) {
Object[] wrapper = (Object[]) recoveryTransactions.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 (onePhase) {
if (prepared)
throw new XAContextException(XAException.XAER_PROTO, "can't use one phase commit, XA transaction is in prepared state");
for (int i = 0; i < transactions.size(); i++) {
QueueTransaction t = (QueueTransaction) transactions.get(i);
try {
t.commit();
if (t instanceof QueuePushTransaction)
fcDelay = Math.max(fcDelay, ((QueuePushTransaction) t).getFlowControlDelay());
} catch (Exception e) {
if (!ctx.queueManager.isTemporaryQueue(t.getQueueName()))
ctx.logSwiftlet.logError(ctx.xaSwiftlet.getName(), toString() + "commit (one phase) xid=" + signature + ", failed for queue: " + t.getQueueName());
}
}
} else {
if (!prepared)
throw new XAContextException(XAException.XAER_PROTO, "can't use two phase commit, XA transaction is not in prepared state");
for (int i = 0; i < transactions.size(); i++) {
QueueTransaction t = (QueueTransaction) transactions.get(i);
try {
t.commit(xid);
if (t instanceof QueuePushTransaction)
fcDelay = Math.max(fcDelay, ((QueuePushTransaction) t).getFlowControlDelay());
} catch (Exception e) {
if (!ctx.queueManager.isTemporaryQueue(t.getQueueName()))
ctx.logSwiftlet.logError(ctx.xaSwiftlet.getName(), toString() + "commit (two phase) xid=" + signature + ", failed for queue: " + t.getQueueName() + ", exception: " + e);
}
}
if (registeredUsageList)
removeUsageEntity();
}
closed = true;
transactions.clear();
recoveryTransactions.clear();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/commit onePhase=" + onePhase + " done");
return fcDelay;
}
use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.
the class XALiveContextImpl method unregister.
public synchronized void unregister(int id, boolean rollbackOnly) throws XAContextException {
if (registrations.get(id) == null)
throw new XAContextException(XAException.XAER_PROTO, "try to unregister an invalid id");
nReg--;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/unregister, id=" + id + ", description: " + registrations.get(id));
registrations.set(id, null);
this.rollbackOnly = rollbackOnly;
if (rolledBack) {
_rollback(false);
transactions.clear();
recoveryTransactions.clear();
if (wasTimeout)
throw new XAContextException(XAException.XA_RBTIMEOUT, "transaction timeout occured");
throw new XAContextException(XAException.XA_RBROLLBACK, "XA transaction was rolled back from another thread");
}
if (closed)
throw new XAContextException(XAException.XAER_PROTO, "XA transaction is in closed state");
}
Aggregations