public MqttConnection()

in provisioning/provisioning-device-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/device/transport/mqtt/MqttConnection.java [51:91]


    public MqttConnection(String hostname, String clientId, String userName, String password, SSLContext sslContext, MqttListener listener, boolean useWebSockets) throws IOException
    {
        if (hostname == null || clientId == null || userName == null || sslContext == null)
        {
            throw new IllegalArgumentException();
        }
        if (hostname.isEmpty() || clientId.isEmpty() || userName.isEmpty())
        {
            throw new IllegalArgumentException();
        }
        if (listener == null)
        {
            throw new IllegalArgumentException("The listener cannot be null.");
        }

        try
        {
            final String serverUri;
            if (useWebSockets)
            {
                serverUri = String.format(WS_SSL_URL_FORMAT, hostname);
            }
            else
            {
                serverUri = String.format(SSL_URL_FORMAT, hostname);
            }
            this.hostName = hostname;
            this.mqttListener = listener;
            this.mqttAsyncClient = new MqttAsyncClient(serverUri, clientId, new MemoryPersistence());
            this.connectionOptions = new MqttConnectOptions();
            this.mqttAsyncClient.setCallback(this);
            this.updateConnectionOptions(userName, password, sslContext);
            this.connectionId = UUID.randomUUID().toString();
        }
        catch (MqttException e)
        {
            this.mqttAsyncClient = null;
            this.connectionOptions = null;
            throw new IOException("Error initializing MQTT connection:" + e.getMessage());
        }
    }