All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.godmao.mqbroker.handler.HeartbeatMessageHandler Maven / Gradle / Ivy

There is a newer version: 0.2.7.RELEASE
Show newest version
package com.godmao.mqbroker.handler;

import com.godmao.mqbroker.Broker;
import com.godmao.mqbroker.Static;
import com.godmao.mqbroker.message.HeartbeatMessage;
import com.godmao.mqbroker.message.TopicSyncMessage;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.Map;

@ChannelHandler.Sharable
public class HeartbeatMessageHandler extends SimpleChannelInboundHandler {
    private final Broker connect;

    public HeartbeatMessageHandler(Broker connect) {
        this.connect = connect;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, HeartbeatMessage.Request msg) {
        final long version = msg.getVersion();
        final long _version = Static.TOPIC_VERSION.get();
        if (_version != version) {
            final Map topicCount = connect.getTopicCount();
            ctx.writeAndFlush(new TopicSyncMessage(_version, true, topicCount));
        }
        ctx.writeAndFlush(new HeartbeatMessage.Response());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy