Search in sources :

Example 1 with MultiplexingDeviceUnauthorizedException

use of com.microsoft.azure.sdk.iot.device.exceptions.MultiplexingDeviceUnauthorizedException in project azure-iot-sdk-java by Azure.

the class MultiplexingClient method open.

/**
 * Opens this multiplexing client. This may be done before or after registering any number of device clients.
 * <p>
 * This call behaves synchronously, so if it returns without throwing, then all registered device clients were
 * successfully opened.
 * <p>
 * If this client is already open, then this method will do nothing.
 * <p>
 * @param withRetry if true, this open call will apply the current retry policy to allow for the open call to be
 * retried if it fails.
 *
 * @throws MultiplexingClientException If any IO or authentication errors occur while opening the multiplexed connection.
 * @throws MultiplexingClientDeviceRegistrationAuthenticationException If one or many of the registered devices failed to authenticate.
 * Any devices not found in the map of registration exceptions provided by
 * {@link MultiplexingClientDeviceRegistrationAuthenticationException#getRegistrationExceptions()} have registered successfully.
 * Even when this is thrown, the AMQPS/AMQPS_WS connection is still open, and other clients may be registered to it.
 */
public void open(boolean withRetry) throws MultiplexingClientException {
    synchronized (this.operationLock) {
        log.info("Opening multiplexing client");
        try {
            this.deviceIO.openWithoutWrappingException(withRetry);
        } catch (TransportException e) {
            // so that users don't need to look at the cause of the thrown exception to get this important information.
            if (e instanceof MultiplexingDeviceUnauthorizedException) {
                MultiplexingClientDeviceRegistrationAuthenticationException newException = new MultiplexingClientDeviceRegistrationAuthenticationException(OPEN_ERROR_MESSAGE, e);
                // Bring the exceptions map from the cause to the root level exception, so that users don't have to use
                // fields from inner exceptions.
                newException.setRegistrationExceptionsMap(((MultiplexingDeviceUnauthorizedException) e).getRegistrationExceptions());
                throw newException;
            }
            throw new MultiplexingClientException(OPEN_ERROR_MESSAGE, e);
        }
        log.info("Successfully opened multiplexing client");
    }
}
Also used : MultiplexingDeviceUnauthorizedException(com.microsoft.azure.sdk.iot.device.exceptions.MultiplexingDeviceUnauthorizedException) MultiplexingClientDeviceRegistrationAuthenticationException(com.microsoft.azure.sdk.iot.device.exceptions.MultiplexingClientDeviceRegistrationAuthenticationException) TransportException(com.microsoft.azure.sdk.iot.device.exceptions.TransportException) MultiplexingClientException(com.microsoft.azure.sdk.iot.device.exceptions.MultiplexingClientException)

Aggregations

MultiplexingClientDeviceRegistrationAuthenticationException (com.microsoft.azure.sdk.iot.device.exceptions.MultiplexingClientDeviceRegistrationAuthenticationException)1 MultiplexingClientException (com.microsoft.azure.sdk.iot.device.exceptions.MultiplexingClientException)1 MultiplexingDeviceUnauthorizedException (com.microsoft.azure.sdk.iot.device.exceptions.MultiplexingDeviceUnauthorizedException)1 TransportException (com.microsoft.azure.sdk.iot.device.exceptions.TransportException)1