use of com.swiftmq.tools.requestreply.Request 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().endRecoverConsumers();
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());
ex.errorCode = reply.getErrorCode();
throw ex;
}
}
use of com.swiftmq.tools.requestreply.Request 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().endRecoverConsumers();
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());
ex.errorCode = reply.getErrorCode();
throw ex;
}
}
use of com.swiftmq.tools.requestreply.Request in project swiftmq-ce by iitsoftware.
the class InboundReader method dataAvailable.
public void dataAvailable(Connection connection, InputStream inputStream) throws IOException {
dis.setInputStream(inputStream);
Dumpable obj = Dumpalizer.construct(dis, dumpableFactory);
if (traceSpace.enabled)
traceSpace.trace("smqp", "read object: " + obj);
if (obj.getDumpId() != SMQPFactory.DID_KEEPALIVE_REQ) {
if (obj.getDumpId() == SMQPFactory.DID_BULK_REQ) {
SMQPBulkRequest bulkRequest = (SMQPBulkRequest) obj;
for (int i = 0; i < bulkRequest.len; i++) {
Request req = (Request) bulkRequest.dumpables[i];
if (req.getDumpId() != SMQPFactory.DID_KEEPALIVE_REQ)
dispatch(req);
else
resetKeepaliveCount();
}
} else
dispatch((Request) obj);
} else
resetKeepaliveCount();
}
use of com.swiftmq.tools.requestreply.Request in project swiftmq-ce by iitsoftware.
the class InboundReader method dataAvailable.
public void dataAvailable(Connection c, InputStream inputStream) throws IOException {
if (compression) {
dbis.reset();
dbos.rewind();
dis.setInputStream(inputStream);
int len = dis.readInt();
byte[] b = new byte[len];
dis.readFully(b);
dbis.setBuffer(b);
decompress();
dbis.setBuffer(dbos.getBuffer(), 0, dbos.getCount());
dis.setInputStream(dbis);
} else
dis.setInputStream(inputStream);
Dumpable obj = Dumpalizer.construct(dis, dumpableFactory);
if (traceSpace.enabled)
traceSpace.trace("smqr", toString() + ": read object: " + obj);
if (obj.getDumpId() != SMQRFactory.KEEPALIVE_REQ) {
if (obj.getDumpId() == SMQRFactory.BULK_REQ) {
BulkRequest bulkRequest = (BulkRequest) obj;
for (int i = 0; i < bulkRequest.len; i++) {
Request req = (Request) bulkRequest.dumpables[i];
if (req.getDumpId() != SMQRFactory.KEEPALIVE_REQ) {
dispatch(req);
} else {
keepaliveCount++;
if (traceSpace.enabled)
traceSpace.trace("smqr", toString() + ": incrementing keepaliveCount to: " + keepaliveCount);
}
}
} else {
dispatch((Request) obj);
}
} else {
keepaliveCount = 5;
if (traceSpace.enabled)
traceSpace.trace("smqr", toString() + ": setting keepaliveCount to: " + keepaliveCount);
}
}
use of com.swiftmq.tools.requestreply.Request in project swiftmq-ce by iitsoftware.
the class StageQueue method process.
protected void process(Object[] bulk, int n) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), "StageQueue/process, n=" + n);
for (int i = 0; i < n; i++) {
Request r = (Request) bulk[i];
if (r.getDumpId() == SMQRFactory.CLOSE_STAGE_QUEUE_REQ) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), "StageQueue/receiving: " + r);
close();
Semaphore sem = ((CloseStageQueueRequest) r).getSemaphore();
if (sem != null)
sem.notifySingleWaiter();
return;
}
if (stage != null)
stage.process((Request) bulk[i]);
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), "StageQueue/process, done");
}
Aggregations