2014-06-11 23:40:19 +02:00
|
|
|
/*
|
2017-01-04 14:37:29 +01:00
|
|
|
* Copyright (c) 2012-2017 The original author or authorsgetRockQuestions()
|
2014-06-11 23:40:19 +02:00
|
|
|
* ------------------------------------------------------
|
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
|
* and Apache License v2.0 which accompanies this distribution.
|
|
|
|
|
*
|
|
|
|
|
* The Eclipse Public License is available at
|
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
*
|
|
|
|
|
* The Apache License v2.0 is available at
|
|
|
|
|
* http://www.opensource.org/licenses/apache2.0.php
|
|
|
|
|
*
|
|
|
|
|
* You may elect to redistribute this code under either of these licenses.
|
|
|
|
|
*/
|
2015-11-20 20:54:27 +01:00
|
|
|
package io.moquette.server.netty;
|
2013-09-19 20:09:46 +02:00
|
|
|
|
2017-01-11 15:26:30 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
2013-09-19 20:09:46 +02:00
|
|
|
import io.netty.channel.ChannelDuplexHandler;
|
2015-09-24 12:05:50 +02:00
|
|
|
import io.netty.channel.ChannelHandler.Sharable;
|
2013-09-19 20:09:46 +02:00
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
|
|
import io.netty.handler.timeout.IdleState;
|
2014-01-11 13:19:12 +01:00
|
|
|
import io.netty.handler.timeout.IdleStateEvent;
|
2013-09-19 20:09:46 +02:00
|
|
|
|
2015-09-24 12:05:50 +02:00
|
|
|
@Sharable
|
2015-12-13 14:08:56 +01:00
|
|
|
class MoquetteIdleTimeoutHandler extends ChannelDuplexHandler {
|
2017-01-11 15:26:30 +01:00
|
|
|
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(MoquetteIdleTimeoutHandler.class);
|
|
|
|
|
|
2013-09-19 20:09:46 +02:00
|
|
|
@Override
|
|
|
|
|
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
2014-01-11 13:19:12 +01:00
|
|
|
if (evt instanceof IdleStateEvent) {
|
|
|
|
|
IdleState e = ((IdleStateEvent) evt).state();
|
2013-09-19 20:09:46 +02:00
|
|
|
if (e == IdleState.ALL_IDLE) {
|
2017-01-11 15:26:30 +01:00
|
|
|
LOG.info("Firing channel inactive event. MqttClientId = {}.", NettyUtils.clientID(ctx.channel()));
|
2014-06-15 18:16:24 +02:00
|
|
|
//fire a channelInactive to trigger publish of Will
|
|
|
|
|
ctx.fireChannelInactive();
|
2013-09-19 20:09:46 +02:00
|
|
|
ctx.close();
|
2015-09-24 12:05:50 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2017-01-11 15:26:30 +01:00
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
|
|
LOG.debug("Firing Netty event. MqttClientId = {}, eventClass = {}.", NettyUtils.clientID(ctx.channel()),
|
|
|
|
|
evt.getClass().getName());
|
|
|
|
|
}
|
2015-09-24 12:05:50 +02:00
|
|
|
super.userEventTriggered(ctx, evt);
|
2013-09-19 20:09:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|