Search in sources :

Example 26 with Request

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;
    }
}
Also used : XAException(javax.transaction.xa.XAException) XidImpl(com.swiftmq.jms.XidImpl) Request(com.swiftmq.tools.requestreply.Request) List(java.util.List) JMSException(javax.jms.JMSException) ValidationException(com.swiftmq.tools.requestreply.ValidationException) JMSException(javax.jms.JMSException) XAException(javax.transaction.xa.XAException)

Example 27 with Request

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;
    }
}
Also used : XAException(javax.transaction.xa.XAException) XidImpl(com.swiftmq.jms.XidImpl) Request(com.swiftmq.tools.requestreply.Request) List(java.util.List) JMSException(javax.jms.JMSException) ValidationException(com.swiftmq.tools.requestreply.ValidationException) JMSException(javax.jms.JMSException) XAException(javax.transaction.xa.XAException)

Example 28 with Request

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();
}
Also used : SMQPBulkRequest(com.swiftmq.jms.smqp.v630.SMQPBulkRequest) SMQPBulkRequest(com.swiftmq.jms.smqp.v630.SMQPBulkRequest) Request(com.swiftmq.tools.requestreply.Request) Dumpable(com.swiftmq.tools.dump.Dumpable)

Example 29 with Request

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);
    }
}
Also used : BulkRequest(com.swiftmq.impl.routing.single.smqpr.BulkRequest) Request(com.swiftmq.tools.requestreply.Request) BulkRequest(com.swiftmq.impl.routing.single.smqpr.BulkRequest) Dumpable(com.swiftmq.tools.dump.Dumpable)

Example 30 with Request

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");
}
Also used : CloseStageQueueRequest(com.swiftmq.impl.routing.single.smqpr.CloseStageQueueRequest) CloseStageQueueRequest(com.swiftmq.impl.routing.single.smqpr.CloseStageQueueRequest) Request(com.swiftmq.tools.requestreply.Request) Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Aggregations

Request (com.swiftmq.tools.requestreply.Request)35 XidImpl (com.swiftmq.jms.XidImpl)16 JMSException (javax.jms.JMSException)16 ValidationException (com.swiftmq.tools.requestreply.ValidationException)14 XAException (javax.transaction.xa.XAException)14 Dumpable (com.swiftmq.tools.dump.Dumpable)8 RequestHandler (com.swiftmq.impl.routing.single.smqpr.RequestHandler)6 StartStageRequest (com.swiftmq.impl.routing.single.smqpr.StartStageRequest)6 List (java.util.List)6 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)4 ChallengeResponseFactory (com.swiftmq.auth.ChallengeResponseFactory)2 POAddObject (com.swiftmq.impl.routing.single.manager.po.POAddObject)2 ConnectReplyRequest (com.swiftmq.impl.routing.single.smqpr.v400.ConnectReplyRequest)2 ConnectReplyRequest (com.swiftmq.impl.routing.single.smqpr.v942.ConnectReplyRequest)2 MessageImpl (com.swiftmq.jms.MessageImpl)2 QueuePullTransaction (com.swiftmq.swiftlet.queue.QueuePullTransaction)2 QueueReceiver (com.swiftmq.swiftlet.queue.QueueReceiver)2 TimerListener (com.swiftmq.swiftlet.timer.event.TimerListener)2 XAContext (com.swiftmq.swiftlet.xa.XAContext)2 XidFilter (com.swiftmq.swiftlet.xa.XidFilter)2