/** * Used for calling the connect handler when the server replies to the request * * @param msg connection response message */ private void handleConnack(MqttConnAckMessage msg) { synchronized (this) { this.isConnected = msg.code() == MqttConnectReturnCode.CONNECTION_ACCEPTED; } Handler<AsyncResult<MqttConnAckMessage>> handler = connectHandler(); if (handler != null) { if (msg.code() == MqttConnectReturnCode.CONNECTION_ACCEPTED) { handler.handle(Future.succeededFuture(msg)); } else { MqttConnectionException exception = new MqttConnectionException(msg.code()); log.error(String.format("Connection refused by the server - code: %s", msg.code())); handler.handle(Future.failedFuture(exception)); } } }
/** * Used for calling the connect handler when the server replies to the request * * @param msg connection response message */ private void handleConnack(MqttConnAckMessage msg) { synchronized (this) { this.isConnected = msg.code() == MqttConnectReturnCode.CONNECTION_ACCEPTED; } Handler<AsyncResult<MqttConnAckMessage>> handler = connectHandler(); if (handler != null) { if (msg.code() == MqttConnectReturnCode.CONNECTION_ACCEPTED) { handler.handle(Future.succeededFuture(msg)); } else { MqttConnectionException exception = new MqttConnectionException(msg.code()); log.error(String.format("Connection refused by the server - code: %s", msg.code())); handler.handle(Future.failedFuture(exception)); } } }
private Future<Device> handleConnectionRequest(final MqttEndpoint endpoint, final Span currentSpan) { if (isConnectionLimitExceeded()) { LOG.debug("Connection limit ({}) exceeded, reject connection request", getConnectionLimit()); currentSpan.log(String.format("connection limit (%d) exceeded", getConnectionLimit())); return Future.failedFuture(new MqttConnectionException( MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE)); } if (getConfig().isAuthenticationRequired()) { return handleEndpointConnectionWithAuthentication(endpoint, currentSpan); } else { return handleEndpointConnectionWithoutAuthentication(endpoint); } }