Search in sources :

Example 6 with TimerListener

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

the class AMQPHandler method visit.

public void visit(POSendOpen po) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
    Entity connectionTemplate = versionedConnection.getConnectionTemplate();
    myIdleTimeout = ((Long) connectionTemplate.getProperty("idle-timeout").getValue()).longValue();
    OpenFrame frame = new OpenFrame(0);
    frame.setContainerId(new AMQPString(SwiftletManager.getInstance().getRouterName()));
    frame.setChannelMax(new AMQPUnsignedShort(((Integer) connectionTemplate.getProperty("max-channel-number").getValue()).intValue()));
    frame.setMaxFrameSize(new AMQPUnsignedInt(((Long) connectionTemplate.getProperty("max-frame-size").getValue()).longValue()));
    try {
        AMQPArray offeredCapas = new AMQPArray(AMQPTypeDecoder.SYM8, new AMQPSymbol[] { new AMQPSymbol(CAPABILITY_NO_LOCAL), new AMQPSymbol(CAPABILITY_SELECTOR) });
        frame.setOfferedCapabilities(offeredCapas);
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (myIdleTimeout > 0) {
        frame.setIdleTimeOut(new Milliseconds(myIdleTimeout));
        idleTimeoutChecker = new TimerListener() {

            public void performTimeAction() {
                dispatch(new POCheckIdleTimeout(null));
            }
        };
        ctx.timerSwiftlet.addTimerListener(myIdleTimeout / 2, idleTimeoutChecker);
    }
    versionedConnection.send(AMQPHandlerFactory.AMQP_INIT);
    versionedConnection.send(frame);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
Also used : Entity(com.swiftmq.mgmt.Entity) IOException(java.io.IOException) Milliseconds(com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds) TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener)

Example 7 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 8 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 9 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 10 with TimerListener

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

the class StreamController method restart.

public void restart() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/restart ...");
    stop();
    long restartDelay = (Long) entity.getProperty("restart-delay").getValue();
    if (restartDelay > 0) {
        long maxRestarts = (Integer) entity.getProperty("restart-max").getValue();
        nRestarts++;
        if (maxRestarts > nRestarts) {
            ctx.timerSwiftlet.addInstantTimerListener(restartDelay, new TimerListener() {

                @Override
                public void performTimeAction() {
                    try {
                        if (enabled)
                            start();
                    } catch (Exception e) {
                        ctx.logSwiftlet.logError(toString(), "Exception restarting stream: " + e);
                        stop();
                    }
                }
            });
        }
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/restart done");
}
Also used : TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener) MalformedURLException(java.net.MalformedURLException)

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