Search in sources :

Example 6 with XAContextException

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");
}
Also used : CommitRequest(com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest) RequestHandler(com.swiftmq.impl.routing.single.smqpr.RequestHandler) RecoveryRequest(com.swiftmq.impl.routing.single.smqpr.v942.RecoveryRequest) XAContext(com.swiftmq.swiftlet.xa.XAContext) XidFilter(com.swiftmq.swiftlet.xa.XidFilter) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) Request(com.swiftmq.tools.requestreply.Request) CommitRequest(com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest) RecoveryRequest(com.swiftmq.impl.routing.single.smqpr.v942.RecoveryRequest) RecoveryReplyRequest(com.swiftmq.impl.routing.single.smqpr.v942.RecoveryReplyRequest) StartDeliveryRequest(com.swiftmq.impl.routing.single.smqpr.v942.StartDeliveryRequest) StartDeliveryRequest(com.swiftmq.impl.routing.single.smqpr.v942.StartDeliveryRequest) ArrayList(java.util.ArrayList) List(java.util.List) RecoveryReplyRequest(com.swiftmq.impl.routing.single.smqpr.v942.RecoveryReplyRequest) XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

Example 7 with XAContextException

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");
}
Also used : CommitRequest(com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest) RequestHandler(com.swiftmq.impl.routing.single.smqpr.RequestHandler) RecoveryRequest(com.swiftmq.impl.routing.single.smqpr.v400.RecoveryRequest) XAContext(com.swiftmq.swiftlet.xa.XAContext) XidFilter(com.swiftmq.swiftlet.xa.XidFilter) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) CommitRequest(com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest) RecoveryRequest(com.swiftmq.impl.routing.single.smqpr.v400.RecoveryRequest) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) Request(com.swiftmq.tools.requestreply.Request) StartDeliveryRequest(com.swiftmq.impl.routing.single.smqpr.v400.StartDeliveryRequest) RecoveryReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.RecoveryReplyRequest) StartDeliveryRequest(com.swiftmq.impl.routing.single.smqpr.v400.StartDeliveryRequest) ArrayList(java.util.ArrayList) List(java.util.List) RecoveryReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.RecoveryReplyRequest) XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

Example 8 with XAContextException

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;
}
Also used : XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

Example 9 with XAContextException

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;
}
Also used : AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) XAContextException(com.swiftmq.swiftlet.xa.XAContextException) XAException(javax.transaction.xa.XAException) XAContextException(com.swiftmq.swiftlet.xa.XAContextException) QueueTransaction(com.swiftmq.swiftlet.queue.QueueTransaction)

Example 10 with XAContextException

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");
}
Also used : XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

Aggregations

XAContextException (com.swiftmq.swiftlet.xa.XAContextException)13 XAContext (com.swiftmq.swiftlet.xa.XAContext)7 XidImpl (com.swiftmq.jms.XidImpl)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)3 XAException (javax.transaction.xa.XAException)3 RequestHandler (com.swiftmq.impl.routing.single.smqpr.RequestHandler)2 StartStageRequest (com.swiftmq.impl.routing.single.smqpr.StartStageRequest)2 CommitRequest (com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest)2 CommitRequest (com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest)2 EntityAddException (com.swiftmq.mgmt.EntityAddException)2 QueuePullTransaction (com.swiftmq.swiftlet.queue.QueuePullTransaction)2 QueueReceiver (com.swiftmq.swiftlet.queue.QueueReceiver)2 QueueSender (com.swiftmq.swiftlet.queue.QueueSender)2 XidFilter (com.swiftmq.swiftlet.xa.XidFilter)2 Request (com.swiftmq.tools.requestreply.Request)2 Comparator (java.util.Comparator)2 JMSException (javax.jms.JMSException)2 RecoveryReplyRequest (com.swiftmq.impl.routing.single.smqpr.v400.RecoveryReplyRequest)1