public int getKeepAlive() { return msg.variableHeader().keepAliveTimeSeconds(); }
private void initializeKeepAliveTimeout(Channel channel, MqttConnectMessage msg, String clientId) { int keepAlive = msg.variableHeader().keepAliveTimeSeconds(); NettyUtils.keepAlive(channel, keepAlive); NettyUtils.cleanSession(channel, msg.variableHeader().isCleanSession()); NettyUtils.clientID(channel, clientId); int idleTime = Math.round(keepAlive * 1.5f); setIdleTime(channel.pipeline(), idleTime); LOG.debug("Connection has been configured CId={}, keepAlive={}, removeTemporaryQoS2={}, idleTime={}", clientId, keepAlive, msg.variableHeader().isCleanSession(), idleTime); }
buf.writeShort(variableHeader.keepAliveTimeSeconds());
@Override public void handleMessage(Message message) { MqttClient client = (MqttClient) message.getClient(); MqttConnectMessage connectMessage = (MqttConnectMessage) message.getPayload(); MqttConnectReturnCode returnCode; MqttConnAckMessage ackMessage; ChannelHandlerContext ctx = client.getCtx(); if (!isClientIdValid(connectMessage.payload().clientIdentifier())) { returnCode = MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED; } else if (!checkUsername(connectMessage.payload().userName()) || !checkPassword(connectMessage.payload().passwordInBytes())) { returnCode = MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD; } else if (!isAuthorized(connectMessage)) { returnCode = MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED; } else if (client.isConnected()) { // protocol violation and disconnect ctx.fireUserEventTriggered(new DisconnectChannelEvent(ctx.channel())); return; } else if (!isServiceAviable(connectMessage)) { returnCode = MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE; } else { client.setId(connectMessage.payload().clientIdentifier()); client.setConnected(true); client.setCleanSession(connectMessage.variableHeader().isCleanSession()); ctx.channel().attr(ChannelConfiguration.CHANNEL_IDLE_TIME_ATTRIBUTE_KEY).set(connectMessage.variableHeader().keepAliveTimeSeconds()); returnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED; } ackMessage = MessageUtil.getMqttConnackMessage(connectMessage, returnCode); ctx.writeAndFlush(ackMessage); }
public int getKeepAlive() { return msg.variableHeader().keepAliveTimeSeconds(); }
private void initializeKeepAliveTimeout(Channel channel, MqttConnectMessage msg, String clientId) { int keepAlive = msg.variableHeader().keepAliveTimeSeconds(); NettyUtils.keepAlive(channel, keepAlive); NettyUtils.cleanSession(channel, msg.variableHeader().isCleanSession()); NettyUtils.clientID(channel, clientId); int idleTime = Math.round(keepAlive * 1.5f); setIdleTime(channel.pipeline(), idleTime); LOG.debug("Connection has been configured CId={}, keepAlive={}, removeTemporaryQoS2={}, idleTime={}", clientId, keepAlive, msg.variableHeader().isCleanSession(), idleTime); }
.append(", hasPassword=").append(connectHeader.hasPassword()) .append(", isCleanSession=").append(connectHeader.isCleanSession()) .append(", keepAliveTimeSeconds=").append(connectHeader.keepAliveTimeSeconds()) .append(", clientIdentifier=").append(payload.clientIdentifier()) .append(", hasUserName=").append(connectHeader.hasUserName());
.append(", hasPassword=").append(connectHeader.hasPassword()) .append(", isCleanSession=").append(connectHeader.isCleanSession()) .append(", keepAliveTimeSeconds=").append(connectHeader.keepAliveTimeSeconds()) .append(", clientIdentifier=").append(payload.clientIdentifier()) .append(", hasUserName=").append(connectHeader.hasUserName());
buf.writeShort(variableHeader.keepAliveTimeSeconds());
msg.variableHeader().version(), msg.variableHeader().name(), msg.variableHeader().keepAliveTimeSeconds()); if (msg.variableHeader().keepAliveTimeSeconds() != 0) { int timeout = msg.variableHeader().keepAliveTimeSeconds() + msg.variableHeader().keepAliveTimeSeconds() / 2;
msg.variableHeader().version(), msg.variableHeader().name(), msg.variableHeader().keepAliveTimeSeconds()); if (msg.variableHeader().keepAliveTimeSeconds() != 0) { int timeout = msg.variableHeader().keepAliveTimeSeconds() + msg.variableHeader().keepAliveTimeSeconds() / 2;
msg.variableHeader().version(), msg.variableHeader().name(), msg.variableHeader().keepAliveTimeSeconds()); if (msg.variableHeader().keepAliveTimeSeconds() != 0) { int timeout = msg.variableHeader().keepAliveTimeSeconds() + msg.variableHeader().keepAliveTimeSeconds() / 2;
if (msg.variableHeader().keepAliveTimeSeconds() > 0) { if (channel.pipeline().names().contains("idle")) { channel.pipeline().remove("idle"); channel.pipeline().addFirst("idle", new IdleStateHandler(0, 0, Math.round(msg.variableHeader().keepAliveTimeSeconds() * 1.5f)));
/** * Called during connection. * * @param connect */ void handleConnect(MqttConnectMessage connect, ChannelHandlerContext ctx) throws Exception { this.ctx = ctx; connectionEntry.ttl = connect.variableHeader().keepAliveTimeSeconds() * 1500L; String clientId = connect.payload().clientIdentifier(); session.getConnectionManager().connect(clientId, connect.payload().userName(), connect.payload().passwordInBytes(), connect.variableHeader().isWillFlag(), connect.payload().willMessageInBytes(), connect.payload().willTopic(), connect.variableHeader().isWillRetain(), connect.variableHeader().willQos(), connect.variableHeader().isCleanSession()); }
/** * Called during connection. * * @param connect */ void handleConnect(MqttConnectMessage connect, ChannelHandlerContext ctx) throws Exception { this.ctx = ctx; connectionEntry.ttl = connect.variableHeader().keepAliveTimeSeconds() * 1500L; String clientId = connect.payload().clientIdentifier(); session.getConnectionManager().connect(clientId, connect.payload().userName(), connect.payload().passwordInBytes(), connect.variableHeader().isWillFlag(), connect.payload().willMessageInBytes(), connect.payload().willTopic(), connect.variableHeader().isWillRetain(), connect.variableHeader().willQos(), connect.variableHeader().isCleanSession()); }