Search in sources :

Example 16 with TimerListener

use of com.swiftmq.swiftlet.timer.event.TimerListener in project swiftmq-ce by iitsoftware.

the class OutboundWriter method writeObject.

public void writeObject(Dumpable obj) {
    if (closed)
        return;
    if (traceSpace.enabled)
        traceSpace.trace("smqp", "write object: " + obj);
    try {
        Dumpalizer.dump(outStream, obj);
        outStream.flush();
        if (obj.getDumpId() == SMQPFactory.DID_DISCONNECT_REP) {
            timerSwiftlet.addInstantTimerListener(10000, new TimerListener() {

                public void performTimeAction() {
                    networkSwiftlet.getConnectionManager().removeConnection(connection);
                    outboundQueue.close();
                    closed = true;
                }
            });
        }
    } catch (Exception e) {
        if (traceSpace.enabled)
            traceSpace.trace("smqp", "exception write object, exiting!: " + e);
        // closes the connection
        networkSwiftlet.getConnectionManager().removeConnection(connection);
        outboundQueue.close();
        closed = true;
    }
}
Also used : TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener)

Example 17 with TimerListener

use of com.swiftmq.swiftlet.timer.event.TimerListener in project swiftmq-ce by iitsoftware.

the class Stage method startValidTimer.

protected void startValidTimer() {
    validTimer = new TimerListener() {

        public void performTimeAction() {
            if (!stageValid)
                return;
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), Stage.this.toString() + "/stage valid timeout");
            ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
        }
    };
    ctx.timerSwiftlet.addInstantTimerListener(((Long) ctx.root.getProperty("stage-valid-timeout").getValue()).longValue(), validTimer);
}
Also used : TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener)

Example 18 with TimerListener

use of com.swiftmq.swiftlet.timer.event.TimerListener in project swiftmq-ce by iitsoftware.

the class VersionSelector method sendReply.

private void sendReply(SMQPVersionReply reply) throws IOException {
    DataStreamOutputStream dos = new DataStreamOutputStream(connection.getOutputStream());
    Dumpalizer.dump(dos, reply);
    dos.flush();
    if (!reply.isOk()) {
        ctx.timerSwiftlet.addInstantTimerListener(10000, new TimerListener() {

            public void performTimeAction() {
                ctx.networkSwiftlet.getConnectionManager().removeConnection(connection);
            }
        });
    }
}
Also used : DataStreamOutputStream(com.swiftmq.tools.util.DataStreamOutputStream) TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener)

Example 19 with TimerListener

use of com.swiftmq.swiftlet.timer.event.TimerListener in project swiftmq-ce by iitsoftware.

the class AuthStage 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) {
            try {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + " ...");
                String password = routingConnection.getPassword();
                if (password == null)
                    throw new Exception("Authentication request by remote router but no password is defined!");
                ChallengeResponseFactory crf = (ChallengeResponseFactory) Class.forName(connectReply.getCrFactory()).newInstance();
                AuthRequest ar = new AuthRequest(crf.createResponse(connectReply.getChallenge(), password));
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", sending request: " + ar);
                routingConnection.getOutboundQueue().enqueue(ar);
                startValidTimer();
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", exception=" + e + ", disconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/exception: " + e.getMessage());
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.AUTH_REPREQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + "...");
            AuthReplyRequest reply = (AuthReplyRequest) request;
            if (reply.isOk()) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", launching recovery stage");
                // Launch recovery stage
                getStageQueue().setStage(new XARecoveryStage(ctx, routingConnection));
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", disconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/exception: " + reply.getException());
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.AUTH_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request);
            AuthRequest pr = (AuthRequest) request;
            AuthReplyRequest reply = new AuthReplyRequest();
            if (ctx.challengeResponseFactory.verifyResponse(connectReply.getChallenge(), pr.getResponse(), routingConnection.getPassword())) {
                reply.setOk(true);
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", response ok, launching recovery stage");
                // Launch recovery stage
                getStageQueue().setStage(new XARecoveryStage(ctx, routingConnection));
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", invalid password, diconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/connection rejected, invalid password!");
                reply.setOk(false);
                reply.setException(new Exception("Invalid password!"));
                ctx.timerSwiftlet.addInstantTimerListener(((Long) ctx.root.getProperty("reject-disconnect-delay").getValue()).longValue(), new TimerListener() {

                    public void performTimeAction() {
                        if (ctx.traceSpace.enabled)
                            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/disconnect timeout");
                        ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
                    }
                });
            }
            routingConnection.getOutboundQueue().enqueue(reply);
        }
    });
    if (!listener)
        getStageQueue().enqueue(new StartStageRequest());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init done");
}
Also used : AuthRequest(com.swiftmq.impl.routing.single.smqpr.v400.AuthRequest) RequestHandler(com.swiftmq.impl.routing.single.smqpr.RequestHandler) ChallengeResponseFactory(com.swiftmq.auth.ChallengeResponseFactory) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) Request(com.swiftmq.tools.requestreply.Request) ConnectReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.ConnectReplyRequest) AuthReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.AuthReplyRequest) AuthRequest(com.swiftmq.impl.routing.single.smqpr.v400.AuthRequest) TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener) AuthReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.AuthReplyRequest)

Example 20 with TimerListener

use of com.swiftmq.swiftlet.timer.event.TimerListener in project swiftmq-ce by iitsoftware.

the class AuthStage 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) {
            try {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + " ...");
                String password = routingConnection.getPassword();
                if (password == null)
                    throw new Exception("Authentication request by remote router but no password is defined!");
                ChallengeResponseFactory crf = (ChallengeResponseFactory) Class.forName(connectReply.getCrFactory()).newInstance();
                AuthRequest ar = new AuthRequest(crf.createResponse(connectReply.getChallenge(), password));
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", sending request: " + ar);
                routingConnection.getOutboundQueue().enqueue(ar);
                startValidTimer();
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", exception=" + e + ", disconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/exception: " + e.getMessage());
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.AUTH_REPREQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + "...");
            AuthReplyRequest reply = (AuthReplyRequest) request;
            if (reply.isOk()) {
                if (connectReply.isRequestXA() || routingConnection.isXa()) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", launching recovery stage");
                    // Launch recovery stage
                    getStageQueue().setStage(new XARecoveryStage(ctx, routingConnection));
                } else {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", launching non-xa delivery stage");
                    // Launch non-XA delivery stage
                    getStageQueue().setStage(new NonXADeliveryStage(ctx, routingConnection));
                }
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", disconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/exception: " + reply.getException());
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.AUTH_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request);
            AuthRequest pr = (AuthRequest) request;
            AuthReplyRequest reply = new AuthReplyRequest();
            if (ctx.challengeResponseFactory.verifyResponse(connectReply.getChallenge(), pr.getResponse(), routingConnection.getPassword())) {
                reply.setOk(true);
                if (connectReply.isRequestXA() || routingConnection.isXa()) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", launching recovery stage");
                    // Launch recovery stage
                    getStageQueue().setStage(new XARecoveryStage(ctx, routingConnection));
                } else {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", launching non-xa delivery stage");
                    // Launch non-XA delivery stage
                    getStageQueue().setStage(new NonXADeliveryStage(ctx, routingConnection));
                }
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", invalid password, diconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/connection rejected, invalid password!");
                reply.setOk(false);
                reply.setException(new Exception("Invalid password!"));
                ctx.timerSwiftlet.addInstantTimerListener(((Long) ctx.root.getProperty("reject-disconnect-delay").getValue()).longValue(), new TimerListener() {

                    public void performTimeAction() {
                        if (ctx.traceSpace.enabled)
                            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/disconnect timeout");
                        ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
                    }
                });
            }
            routingConnection.getOutboundQueue().enqueue(reply);
        }
    });
    if (!listener)
        getStageQueue().enqueue(new StartStageRequest());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init done");
}
Also used : AuthRequest(com.swiftmq.impl.routing.single.smqpr.v942.AuthRequest) RequestHandler(com.swiftmq.impl.routing.single.smqpr.RequestHandler) ChallengeResponseFactory(com.swiftmq.auth.ChallengeResponseFactory) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) AuthRequest(com.swiftmq.impl.routing.single.smqpr.v942.AuthRequest) AuthReplyRequest(com.swiftmq.impl.routing.single.smqpr.v942.AuthReplyRequest) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) Request(com.swiftmq.tools.requestreply.Request) ConnectReplyRequest(com.swiftmq.impl.routing.single.smqpr.v942.ConnectReplyRequest) TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener) AuthReplyRequest(com.swiftmq.impl.routing.single.smqpr.v942.AuthReplyRequest)

Aggregations

TimerListener (com.swiftmq.swiftlet.timer.event.TimerListener)21 POTimer (com.swiftmq.impl.streams.processor.po.POTimer)3 ChallengeResponseFactory (com.swiftmq.auth.ChallengeResponseFactory)2 RequestHandler (com.swiftmq.impl.routing.single.smqpr.RequestHandler)2 StartStageRequest (com.swiftmq.impl.routing.single.smqpr.StartStageRequest)2 Request (com.swiftmq.tools.requestreply.Request)2 DataStreamOutputStream (com.swiftmq.tools.util.DataStreamOutputStream)2 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)1 AuthReplyRequest (com.swiftmq.impl.routing.single.smqpr.v400.AuthReplyRequest)1 AuthRequest (com.swiftmq.impl.routing.single.smqpr.v400.AuthRequest)1 ConnectReplyRequest (com.swiftmq.impl.routing.single.smqpr.v400.ConnectReplyRequest)1 AuthReplyRequest (com.swiftmq.impl.routing.single.smqpr.v942.AuthReplyRequest)1 AuthRequest (com.swiftmq.impl.routing.single.smqpr.v942.AuthRequest)1 ConnectReplyRequest (com.swiftmq.impl.routing.single.smqpr.v942.ConnectReplyRequest)1 MessageImpl (com.swiftmq.jms.MessageImpl)1 Entity (com.swiftmq.mgmt.Entity)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 JMSException (javax.jms.JMSException)1