public synchronized void open()

in provisioning/provisioning-device-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/device/internal/contract/mqtt/ContractAPIMqtt.java [159:196]


    public synchronized void open(RequestData requestData) throws ProvisioningDeviceConnectionException
    {
        if (this.mqttConnection != null && this.mqttConnection.isMqttConnected())
        {
            throw new ProvisioningDeviceConnectionException("Open called on an already open connection");
        }
        if (requestData == null)
        {
            throw new ProvisioningDeviceConnectionException(new IllegalArgumentException("RequestData cannot be null"));
        }
        String registrationId = requestData.getRegistrationId();
        if (registrationId == null || registrationId.isEmpty())
        {
            throw new ProvisioningDeviceConnectionException(new IllegalArgumentException("registration Id cannot be null or empty"));
        }
        SSLContext sslContext = requestData.getSslContext();
        if (sslContext == null)
        {
            throw new ProvisioningDeviceConnectionException(new IllegalArgumentException("sslContext cannot be null"));
        }

        if (requestData.isX509() || (requestData.getSasToken() != null && !requestData.getSasToken().isEmpty()))
        {
            try
            {
                String username = String.format(MQTT_USERNAME_FMT, this.idScope, registrationId, SDKUtils.getServiceApiVersion(), SDKUtils.getServiceApiVersion());
                this.mqttConnection = new MqttConnection(this.hostname, registrationId, username, requestData.getSasToken(), sslContext, this, this.useWebSockets);
                this.mqttConnection.connect();

                this.mqttConnection.subscribe(MQTT_PROVISIONING_TOPIC_NAME, MqttQos.DELIVER_AT_LEAST_ONCE);
            }
            catch (IOException ex)
            {
                this.mqttConnection = null;
                throw new ProvisioningDeviceConnectionException("Exception opening connection", ex);
            }
        }
    }