com.whizzosoftware.wzwave.channel.inbound.ACKInboundHandler.java Source code

Java tutorial

Introduction

Here is the source code for com.whizzosoftware.wzwave.channel.inbound.ACKInboundHandler.java

Source

/*
 *******************************************************************************
 * Copyright (c) 2013 Whizzo Software, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************
*/
package com.whizzosoftware.wzwave.channel.inbound;

import com.whizzosoftware.wzwave.frame.ACK;
import com.whizzosoftware.wzwave.frame.DataFrame;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * An inbound handler that sends ACK frames when necessary.
 *
 * @author Dan Noguerol
 */
public class ACKInboundHandler extends ChannelInboundHandlerAdapter {
    private static final Logger logger = LoggerFactory.getLogger(ZWaveChannelInboundHandler.class);

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        if (msg instanceof DataFrame) {
            logger.trace("Sending ACK for received data frame: {}", msg);
            ctx.channel().writeAndFlush(new ACK());
        }
        ctx.fireChannelRead(msg);
    }
}