protected String getClientInfo() { String clientInfo = "Session n/a"; if (session != null) { clientInfo = session.getClientInfo(); } return clientInfo; }
protected void handleWillMessage() { // Container.logger().info("handle will message... "); if (session != null) { // Container.logger().info("handle will message: session found!"); session.handleWillMessage(); } // Container.logger().info("handle will message end."); }
public void shutdown() { if (tokenizer != null) { tokenizer.removeAllListeners(); tokenizer = null; } if (session != null) { session.shutdown(); session = null; } vertx = null; }
private void onMessageFromClient(AbstractMessage msg) throws Exception { Container.logger().debug("<<< " + msg); switch (msg.getMessageType()) { case CONNECT: ConnectMessage connect = (ConnectMessage) msg; ConnAckMessage connAck = new ConnAckMessage(); if (session == null) { session = new MQTTSession(vertx, config); session.setPublishMessageHandler(this::sendMessageToClient); session.setKeepaliveErrorHandler( clientID -> { String cinfo = clientID; if (session != null) { cinfo = session.getClientInfo(); } Container.logger() .info("keep alive exausted! closing connection for client[" + cinfo + "] ..."); closeConnection(); }); connAck.setSessionPresent(false); } else { Container.logger().warn("Session alredy allocated ..."); /* The Server MUST process a second CONNECT Packet sent from a Client as a protocol violation and disconnect the Client */ // connAck.setSessionPresent(true);// TODO implement cleanSession=false closeConnection(); break; } session.handleConnectMessage( connect, authenticated -> { if (authenticated) { connAck.setReturnCode(ConnAckMessage.CONNECTION_ACCEPTED); sendMessageToClient(connAck); } else { Container.logger() .error( "Authentication failed! clientID= " + connect.getClientID() + " username="******"type of message not known: " + msg.getClass().getSimpleName()); break; } // TODO: forward mqtt message to backup server }
private void handleDisconnect(DisconnectMessage disconnectMessage) { session.handleDisconnect(disconnectMessage); session = null; }