Search in sources :

Example 1 with RecoveryReplyRequest

use of com.swiftmq.impl.routing.single.smqpr.v942.RecoveryReplyRequest 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 2 with RecoveryReplyRequest

use of com.swiftmq.impl.routing.single.smqpr.v942.RecoveryReplyRequest 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)

Aggregations

RequestHandler (com.swiftmq.impl.routing.single.smqpr.RequestHandler)2 StartStageRequest (com.swiftmq.impl.routing.single.smqpr.StartStageRequest)2 XAContext (com.swiftmq.swiftlet.xa.XAContext)2 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)2 XidFilter (com.swiftmq.swiftlet.xa.XidFilter)2 Request (com.swiftmq.tools.requestreply.Request)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CommitRequest (com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest)1 RecoveryReplyRequest (com.swiftmq.impl.routing.single.smqpr.v400.RecoveryReplyRequest)1 RecoveryRequest (com.swiftmq.impl.routing.single.smqpr.v400.RecoveryRequest)1 StartDeliveryRequest (com.swiftmq.impl.routing.single.smqpr.v400.StartDeliveryRequest)1 CommitRequest (com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest)1 RecoveryReplyRequest (com.swiftmq.impl.routing.single.smqpr.v942.RecoveryReplyRequest)1 RecoveryRequest (com.swiftmq.impl.routing.single.smqpr.v942.RecoveryRequest)1 StartDeliveryRequest (com.swiftmq.impl.routing.single.smqpr.v942.StartDeliveryRequest)1