@Component
@Slf4j
public class NettyServerHandler extends ChannelInboundHandlerAdapter {
@Autowired
private IDpDeviceService dpDeviceService;
public static NettyServerHandler nettyServerHandler;
@PostConstruct
public void init() {
nettyServerHandler = this;
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
log.info("{}:发生了错误,此连接被关闭。此时连通数量:{}",ctx.channel().id(),ChannelMap.getChannelMap().size());
ctx.close();
DpDevice dpDevice = nettyServerHandler.dpDeviceService.selectDpDeviceById(1L);
dpDevice.setState(0L);
nettyServerHandler.dpDeviceService.updateDpDevice(dpDevice);
}
}