use of com.swiftmq.jms.XidImpl in project swiftmq-client by iitsoftware.
the class XAResourceImpl method toSwiftMQXid.
private XidImpl toSwiftMQXid(Xid xid) {
XidImpl rXid = null;
if (xid instanceof com.swiftmq.jms.XidImpl)
rXid = (XidImpl) xid;
else {
rXid = (XidImpl) xidMapping.get(xid);
if (rXid == null) {
rXid = new XidImpl(xid);
xidMapping.put(xid, rXid);
}
}
if (logWriter != null)
log(toString() + "/toSwiftMQXid, xid=" + xid + ", rXid=" + rXid);
return rXid;
}
use of com.swiftmq.jms.XidImpl in project swiftmq-client by iitsoftware.
the class XAResourceImpl method rollback.
public synchronized void rollback(Xid xid) throws XAException {
if (logWriter != null)
log(toString() + "/rollback, xid=" + xid);
XidImpl sxid = toSwiftMQXid(xid);
xidMapping.remove(xid);
XAResRollbackReply reply = null;
try {
int connectionId = session.getSessionImpl().getMyConnection().getConnectionId();
session.getSessionImpl().startRecoverConsumers();
session.getAndClearCurrentTransaction();
List recoveryList = null;
if (endRequestInDoubt())
recoveryList = XARecoverRegistry.getInstance().getRequestList(sxid);
Request request = new XAResRollbackRequest(this, session.getDispatchId(), sxid, false, recoveryList, session.getSessionImpl().getRecoveryEpoche());
request.setConnectionId(connectionId);
reply = (XAResRollbackReply) session.request(request);
} catch (Exception e) {
if (completionListener != null)
completionListener.transactionAborted(sxid);
XAException ex = new XAException(e.toString());
ex.errorCode = XAException.XAER_RMFAIL;
throw ex;
}
if (reply.isOk()) {
session.getSessionImpl().endRecoverConsumersXA();
try {
session.getSessionImpl().closeDelayedProducers();
} catch (JMSException e) {
e.printStackTrace();
}
if (completionListener != null)
completionListener.transactionAborted(sxid);
XARecoverRegistry.getInstance().clear(sxid);
} else {
if (completionListener != null)
completionListener.transactionAborted(sxid);
XAException ex = new XAException(reply.getException().getMessage());
if (reply.getErrorCode() != 0)
ex.errorCode = reply.getErrorCode();
else
ex.errorCode = XAException.XAER_RMFAIL;
throw ex;
}
}
use of com.swiftmq.jms.XidImpl in project swiftmq-client by iitsoftware.
the class XAResStartRequest method readContent.
public void readContent(DataInput in) throws IOException {
super.readContent(in);
xid = new XidImpl();
xid.readContent(in);
flags = in.readInt();
}
use of com.swiftmq.jms.XidImpl in project swiftmq-ce by iitsoftware.
the class XAResourceManagerSwiftletImpl method startup.
protected void startup(Configuration configuration) throws SwiftletException {
ctx = new SwiftletContext(this, configuration);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup...");
try {
ctx.heuristicHandler.loadHeuristics();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "exception during loadHeuristics: " + e.toString());
ctx.logSwiftlet.logError(getName(), "exception during loadHeuristics: " + e.toString());
}
try {
buildPreparedTransactions();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "exception during buildPreparedTransactions: " + e.toString());
ctx.logSwiftlet.logError(getName(), "exception during buildPreparedTransactions: " + e.toString());
}
if (contexts.size() > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), contexts.size() + " prepared transactions found");
ctx.logSwiftlet.logWarning(getName(), contexts.size() + " prepared transactions found!");
System.out.println("+++ WARNING! " + contexts.size() + " prepared transactions found!");
System.out.println("+++ HA/Routing XA transactions are automatically recovered.");
System.out.println("+++ You may also use Explorer/CLI for heuristic commit or rollback.");
}
Property prop = configuration.getProperty("scan-interval");
scanInterval = ((Long) prop.getValue()).longValue();
ctx.timerSwiftlet.addTimerListener(scanInterval, this);
prop.setPropertyChangeListener(new PropertyChangeListener() {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
ctx.timerSwiftlet.removeTimerListener(XAResourceManagerSwiftletImpl.this);
scanInterval = ((Long) newValue).longValue();
ctx.timerSwiftlet.addTimerListener(scanInterval, XAResourceManagerSwiftletImpl.this);
}
});
prop = configuration.getProperty("default-transaction-timeout");
defaultTxTimeout = ((Long) prop.getValue()).longValue();
long timeout = getTransactionTimeout();
if (timeout > 0)
ctx.timerSwiftlet.addTimerListener(timeout, txTimer);
prop.setPropertyChangeListener(new PropertyChangeListener() {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
long timeout = getTransactionTimeout();
if (timeout > 0)
ctx.timerSwiftlet.removeTimerListener(txTimer);
defaultTxTimeout = ((Long) newValue).longValue();
timeout = getTransactionTimeout();
if (timeout > 0)
ctx.timerSwiftlet.addTimerListener(timeout, txTimer);
}
});
CommandRegistry commandRegistry = ctx.preparedUsageList.getCommandRegistry();
CommandExecutor commitExecutor = new CommandExecutor() {
public String[] execute(String[] context, Entity entity, String[] cmd) {
if (cmd.length != 2)
return new String[] { TreeCommands.ERROR, "Invalid command, please try 'commit <id>'" };
Entity e = ctx.preparedUsageList.getEntity(cmd[1]);
if (e == null)
return new String[] { TreeCommands.ERROR, "Unknown Entity: " + cmd[1] };
XAContext xac = (XAContext) contexts.get(e.getDynamicObject());
XidImpl xid = xac.getXid();
try {
xac.commit(false);
if (!xid.isRouting())
ctx.heuristicHandler.addHeuristic(xid, true);
} catch (Exception e1) {
return new String[] { TreeCommands.ERROR, "Exception during commit: " + e1 };
}
removeXAContext(xid);
return null;
}
};
Command commitCommand = new Command("commit", "commit <id>", "Commit", true, commitExecutor, true, true);
commandRegistry.addCommand(commitCommand);
CommandExecutor rollbackExecutor = new CommandExecutor() {
public String[] execute(String[] context, Entity entity, String[] cmd) {
if (cmd.length != 2)
return new String[] { TreeCommands.ERROR, "Invalid command, please try 'rollback <id>'" };
Entity e = ctx.preparedUsageList.getEntity(cmd[1]);
if (e == null)
return new String[] { TreeCommands.ERROR, "Unknown Entity: " + cmd[1] };
XAContext xac = (XAContext) contexts.get(e.getDynamicObject());
XidImpl xid = xac.getXid();
try {
xac.rollback();
if (!xid.isRouting())
ctx.heuristicHandler.addHeuristic(xid, false);
} catch (Exception e1) {
return new String[] { TreeCommands.ERROR, "Exception during rollback: " + e1 };
}
removeXAContext(xid);
return null;
}
};
Command rollbackCommand = new Command("rollback", "rollback <id>", "Rollback", true, rollbackExecutor, true, true);
commandRegistry.addCommand(rollbackCommand);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup...done");
}
use of com.swiftmq.jms.XidImpl in project swiftmq-ce by iitsoftware.
the class XAResourceManagerSwiftletImpl method buildPreparedTransactions.
private void buildPreparedTransactions() throws Exception {
List prepareRecordList = ctx.storeSwiftlet.getPrepareLogRecords();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "buildPreparedTransactions, recordList: " + prepareRecordList);
if (prepareRecordList != null && prepareRecordList.size() > 0) {
for (int i = 0; i < prepareRecordList.size(); i++) {
PrepareLogRecord record = (PrepareLogRecord) prepareRecordList.get(i);
AbstractQueue queue = getPreparedQueue(record.getQueueName());
if (queue != null) {
XidImpl xid = record.getGlobalTxId();
Object localTxId = queue.buildPreparedTransaction(record);
XALiveContextImpl xac = (XALiveContextImpl) contexts.get(xid);
if (xac == null) {
xac = new XALiveContextImpl(ctx, xid, true);
xac.setRecovered(true);
xac.registerUsageList();
contexts.put(xid, xac);
}
xac._addTransaction(queue, localTxId);
}
}
}
}
Aggregations