Search in sources :

Example 11 with TimerListener

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

the class ChannelHandler method publishCurrentMessage.

private void publishCurrentMessage(Exchange exchange) {
    if (exchange.getType() == Exchange.DIRECT) {
        String rk = getMapping(currentMessage.getPublish().getRoutingKey());
        QueueSender sender = (QueueSender) producers.get(rk);
        try {
            if (sender == null) {
                if (producers.size() > 10) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", sender cache > 10, closing all");
                    for (Iterator iter = producers.entrySet().iterator(); iter.hasNext(); ) {
                        QueueSender s = (QueueSender) ((Map.Entry) iter.next()).getValue();
                        if (ctx.traceSpace.enabled)
                            ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", closing sender for queue: " + s.getQueueName());
                        s.close();
                        iter.remove();
                    }
                }
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", creating new sender on queue: " + rk);
                sender = ctx.queueManager.createQueueSender(rk, versionedConnection.getActiveLogin());
                producers.put(rk, sender);
            }
            QueuePushTransaction t = sender.createTransaction();
            MessageImpl msg = inboundTransformer.transform(currentMessage, this);
            msg.setJMSDestination(create(rk));
            msg.reset();
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", converted JMS message: " + msg);
            t.putMessage(msg);
            t.commit();
            if (remoteFlowActive) {
                long fcDelay = t.getFlowControlDelay();
                if (fcDelay > 100) {
                    sendFlow(false);
                    ctx.timerSwiftlet.addInstantTimerListener(fcDelay, new TimerListener() {

                        public void performTimeAction() {
                            dispatch(PO_ACTIVATE_FLOW);
                        }
                    });
                }
            }
        } catch (JMSException e) {
            amqpHandler.dispatch(new POSendChannelClose(channelNo, Constants.CHANNEL_ERROR, "Exception on publishing to exchange '" + currentMessage.getPublish().getExchange() + "': " + e, currentMessage.getPublish()));
        }
    } else
        amqpHandler.dispatch(new POSendChannelClose(channelNo, Constants.NOT_IMPLEMENTED, "Exchange is not of type direct: " + currentMessage.getPublish().getExchange(), currentMessage.getPublish()));
}
Also used : JMSException(javax.jms.JMSException) TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 12 with TimerListener

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

the class AMQPHandler method visit.

public void visit(POSendTune po) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
    lastActivity = System.currentTimeMillis();
    Tune tune = new Tune();
    int channelMax = ((Integer) connectionTemplate.getProperty("max-channel-number").getValue()).intValue();
    tune.setChannelMax(channelMax > Short.MAX_VALUE ? 0 : channelMax);
    tune.setFrameMax(maxLocalFrameSize);
    tune.setHeartbeat((int) (myIdleTimeout / 1000));
    Frame frame = new Frame(Frame.TYPE_METHOD, 0, 0, null);
    toPayload(frame, tune);
    versionedConnection.send(frame);
    if (myIdleTimeout > 0) {
        idleTimeoutChecker = new TimerListener() {

            public void performTimeAction() {
                dispatch(new POCheckIdleTimeout(null));
            }
        };
        ctx.timerSwiftlet.addTimerListener(myIdleTimeout + 5000, idleTimeoutChecker);
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
Also used : TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener)

Example 13 with TimerListener

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

the class DispatchQueue method checkStartLeases.

private void checkStartLeases() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/checkStartLeases, dispatchers.size(): " + dispatchers.size());
    if (dispatchers.size() == 1) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/checkStartLeases, start timers");
        ctx.timerSwiftlet.addTimerListener(EXPIRATION_CHECK_INTERVAL, this);
        updateTimer = new TimerListener() {

            public void performTimeAction() {
                pipelineQueue.enqueue(new SendUpdates());
            }
        };
        Property prop = ctx.root.getProperty("flush-interval");
        flushInterval = ((Long) prop.getValue()).longValue();
        ctx.timerSwiftlet.addTimerListener(flushInterval, updateTimer);
        prop.setPropertyChangeListener(new PropertyChangeListener() {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                ctx.timerSwiftlet.removeTimerListener(updateTimer);
                flushInterval = ((Long) newValue).longValue();
                ctx.timerSwiftlet.addTimerListener(flushInterval, updateTimer);
            }
        });
        RouterConfiguration.Singleton().addEntityWatchListener(this);
        addWatchListeners(RouterConfiguration.Singleton());
        ctx.mgmtSwiftlet.fireEvent(true);
        leaseStarted = true;
    }
}
Also used : TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener)

Example 14 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 15 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)

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