MultiplexingClient Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.device.MultiplexingClient

public class MultiplexingClient

A client for creating multiplexed connections to IoT hub. A multiplexed connection allows for multiple device clients to communicate to the service through a single AMQPS connection.

A given AMQPS connection requires a TLS connection, so multiplexing may be worthwhile if you want to limit the number of TLS connections needed to connect multiple device clients to IoT hub.

A given multiplexing client also has a fixed amount of worker threads regardless of how many device clients are being multiplexed. Comparatively, every non-multiplexed device client instance has its own set of worker threads. Multiplexing may be worthwhile if you want fewer worker threads.

Only AMQPS and AMQPS_WS support multiplexing, and only symmetric key authenticated devices can be multiplexed.

ModuleClient instances cannot be multiplexed.

Field Summary

Modifier and Type Field and Description
final int MAX_MULTIPLEX_DEVICE_COUNT_AMQPS

The maximum number of devices that can be multiplexed together on a single multiplexed AMQPS connection

final int MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS

The maximum number of devices that can be multiplexed together on a single multiplexed AMQPS_WS connection

Constructor Summary

Constructor Description
MultiplexingClient(String hostName, IotHubClientProtocol protocol)

Instantiate a new MultiplexingClient that will establish a multiplexed connection through a proxy.

MultiplexingClient(String hostName, IotHubClientProtocol protocol, MultiplexingClientOptions options)

Instantiate a new MultiplexingClient that will establish a multiplexed connection through a proxy.

Method Summary

Modifier and Type Method and Description
void close()

Close this multiplexing client. This will close all active device sessions as well as the AMQP connection.

If this client is already closed, then this method will do nothing.

Once closed, this client can be re-opened. It will preserve all previously registered device clients.

int getRegisteredDeviceCount()

Get the number of currently registered devices on this multiplexing client.

boolean isDeviceRegistered(String deviceId)

Returns if a device client for the provided device Id is already registered to this multiplexing client.

void open(boolean withRetry)

Opens this multiplexing client. This may be done before or after registering any number of device clients.

This call behaves synchronously, so if it returns without throwing, then all registered device clients were successfully opened.

If this client is already open, then this method will do nothing.

void registerDeviceClient(DeviceClient deviceClient)

Register a device client to this multiplexing client. This method may be called before or after opening the multiplexed connection.

Users should use registerDeviceClients(Iterable) for registering multiple devices as it has some performance improvements over repeatedly calling this method for individual device registrations. This method blocks on each registration, whereas registerDeviceClients(Iterable) blocks on all of the registrations after starting them all asynchronously.

A device client can be unregistered using unregisterDeviceClient(DeviceClient deviceClient), unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds), unregisterDeviceClients(Iterable), or unregisterDeviceClients(Iterable, long). A device client will not be unregistered automatically if it encounters a non-retryable exception, so users are responsible for unregistering a device client when they no longer want it in this multiplexing client.

Up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS devices can be registered on a multiplexed AMQPS connection, and up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS devices can be registered on a multiplexed AMQPS_WS connection.

If the multiplexing client is already open, then this device client will automatically be opened, too. If the multiplexing client is not open yet, then this device client will not be opened until open(boolean withRetry) is called.

If the multiplexed connection is already open, then this call will add this device client to the multiplexed connection, and then will block until the registration has been completed.

Any proxy settings set to the provided device clients will be overwritten by the proxy settings of this multiplexing client.

The registered device client must use the same transport protocol (AMQPS or AMQPS_WS) that this multiplexing client uses.

Each registered device client may have its own retry policy and its own SAS token expiry time, separate from every other registered device client.

The registered device client must use symmetric key based authentication.

The registered device client must belong to the same IoT hub as all previously registered device clients.

If the provided device client is already registered to this multiplexing client, then then this method will do nothing.

Any subscriptions (twin, methods, cloud to device messages) set on this device client from when it was previously registered to any multiplexing client will need to be set again as subscriptions and their callbacks are not preserved.

void registerDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds)

Register a device client to this multiplexing client. This method may be called before or after opening the multiplexed connection.

Users should use registerDeviceClients(Iterable) for registering multiple devices as it has some performance improvements over repeatedly calling this method for individual device registrations. This method blocks on each registration, whereas registerDeviceClients(Iterable) blocks on all of the registrations after starting them all asynchronously.

A device client can be unregistered using unregisterDeviceClient(DeviceClient deviceClient), unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds), unregisterDeviceClients(Iterable), or unregisterDeviceClients(Iterable, long). A device client will not be unregistered automatically if it encounters a non-retryable exception, so users are responsible for unregistering a device client when they no longer want it in this multiplexing client.

Up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS devices can be registered on a multiplexed AMQPS connection, and up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS devices can be registered on a multiplexed AMQPS_WS connection.

If the multiplexing client is already open, then this device client will automatically be opened, too. If the multiplexing client is not open yet, then this device client will not be opened until open(boolean withRetry) is called.

If the multiplexed connection is already open, then this call will add this device client to the multiplexed connection, and then will block until the registration has been completed.

Any proxy settings set to the provided device clients will be overwritten by the proxy settings of this multiplexing client.

The registered device client must use the same transport protocol (AMQPS or AMQPS_WS) that this multiplexing client uses.

Each registered device client may have its own retry policy and its own SAS token expiry time, separate from every other registered device client.

The registered device client must use symmetric key based authentication.

The registered device client must belong to the same IoT hub as all previously registered device clients.

If the provided device client is already registered to this multiplexing client, then then this method will do nothing.

Any subscriptions (twin, methods, cloud to device messages) set on this device client from when it was previously registered to any multiplexing client will need to be set again as subscriptions and their callbacks are not preserved.

void registerDeviceClients(Iterable<DeviceClient> deviceClients)

Register multiple device clients to this multiplexing client. This method may be called before or after opening the multiplexed connection.

Up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS devices can be registered on a multiplexed AMQPS connection, and up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS devices can be registered on a multiplexed AMQPS_WS connection.

A device client can be unregistered using unregisterDeviceClient(DeviceClient deviceClient), unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds), unregisterDeviceClients(Iterable), or unregisterDeviceClients(Iterable, long). A device client will not be unregistered automatically if it encounters a non-retryable exception, so users are responsible for unregistering a device client when they no longer want it in this multiplexing client.

If the multiplexing client is already open, then these device clients will automatically be opened, too. If the multiplexing client is not open yet, then these device clients will not be opened until open(boolean withRetry) is called.

If the multiplexed connection is already open, then this call will asynchronously add each device client to the multiplexed connection, and then will block until all registrations have been completed.

Any proxy settings set to the provided device clients will be overwritten by the proxy settings of this multiplexing client.

The registered device clients must use the same transport protocol (AMQPS or AMQPS_WS) that this multiplexing client uses.

Each registered device client may have its own retry policy and its own SAS token expiry time, separate from every other registered device client.

The registered device clients must use symmetric key based authentication.

The registered device clients must belong to the same IoT hub as all previously registered device clients.

If any of these device clients are already registered to this multiplexing client, then then this method will not do anything to that particular device client. All other provided device clients will still be registered though.

Any subscriptions (twin, methods, cloud to device messages) set on these device clients from when it was previously registered to any multiplexing client will need to be set again as subscriptions and their callbacks are not preserved.

void registerDeviceClients(Iterable<DeviceClient> deviceClients, long timeoutMilliseconds)

Register multiple device clients to this multiplexing client. This method may be called before or after opening the multiplexed connection.

Up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS devices can be registered on a multiplexed AMQPS connection, and up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS devices can be registered on a multiplexed AMQPS_WS connection.

A device client can be unregistered using unregisterDeviceClient(DeviceClient deviceClient), unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds), unregisterDeviceClients(Iterable), or unregisterDeviceClients(Iterable, long). A device client will not be unregistered automatically if it encounters a non-retryable exception, so users are responsible for unregistering a device client when they no longer want it in this multiplexing client.

If the multiplexing client is already open, then these device clients will automatically be opened, too. If the multiplexing client is not open yet, then these device clients will not be opened until open(boolean withRetry) is called.

If the multiplexed connection is already open, then this call will asynchronously add each device client to the multiplexed connection, and then will block until all registrations have been completed.

Any proxy settings set to the provided device clients will be overwritten by the proxy settings of this multiplexing client.

The registered device clients must use the same transport protocol (AMQPS or AMQPS_WS) that this multiplexing client uses.

Each registered device client may have its own retry policy and its own SAS token expiry time, separate from every other registered device client.

The registered device clients must use symmetric key based authentication.

The registered device clients must belong to the same IoT hub as all previously registered device clients.

If any of these device clients are already registered to this multiplexing client, then then this method will not do anything to that particular device client. All other provided device clients will still be registered though.

Any subscriptions (twin, methods, cloud to device messages) set on these device clients from when it was previously registered to any multiplexing client will need to be set again as subscriptions and their callbacks are not preserved.

void setConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext)

Registers a callback to be executed when the connection status of the multiplexed connection as a whole changes. The callback will be fired with a status and a reason why the multiplexed connection's status changed. When the callback is fired, the provided context will be provided alongside the status and reason.

Note that this callback will not be fired for device specific connection status changes. In order to be notified when a particular device's connection status changes, you will need to register a connection status change callback on that device client instance using setConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext).

Note that the thread used to deliver this callback should not be used to call open()/close() on the client that this callback belongs to. All open()/close() operations should be done on a separate thread

void setRetryPolicy(RetryPolicy retryPolicy)

Sets the given retry policy for the multiplexing client level connection management. See more details about the default retry policy and about using custom retry policies here

void unregisterDeviceClient(DeviceClient deviceClient)

Unregister a device client from this multiplexing client. This method may be called before or after opening the multiplexed connection.

Users should use unregisterDeviceClients(Iterable) for unregistering multiple devices as it has some performance improvements over repeatedly calling this method for individual device unregistrations. This method blocks on each unregistration, whereas registerDeviceClients(Iterable) blocks on all of the unregistrations after starting them all asynchronously.

If the multiplexed connection is already open, then this call will close the AMQP device session associated with this device, but it will not close any other registered device sessions or the multiplexing client itself.

If the multiplexed connection is already open, and this call would unregister the last device client, the multiplexed connection will remain open. The multiplexed connection can only be closed by calling close()

Once a device client is unregistered, it may be re-registered to this or any other multiplexing client. It cannot be used in non-multiplexing scenarios.

Any subscriptions set on this device client for twin/methods/cloud to device messages will need to be set again after this device is re-registered.

void unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds)

Unregister a device client from this multiplexing client. This method may be called before or after opening the multiplexed connection.

Users should use unregisterDeviceClients(Iterable) for unregistering multiple devices as it has some performance improvements over repeatedly calling this method for individual device unregistrations. This method blocks on each unregistration, whereas registerDeviceClients(Iterable) blocks on all of the unregistrations after starting them all asynchronously.

If the multiplexed connection is already open, then this call will close the AMQP device session associated with this device, but it will not close any other registered device sessions or the multiplexing client itself.

If the multiplexed connection is already open, and this call would unregister the last device client, the multiplexed connection will remain open. The multiplexed connection can only be closed by calling close()

Once a device client is unregistered, it may be re-registered to this or any other multiplexing client. It cannot be used in non-multiplexing scenarios.

Any subscriptions set on this device client for twin/methods/cloud to device messages will need to be set again after this device is re-registered.

void unregisterDeviceClients(Iterable<DeviceClient> deviceClients)

Unregister multiple device clients from this multiplexing client. This method may be called before or after opening the multiplexed connection.

If the multiplexed connection is already open, then this call will close the AMQP device session associated with this device, but it will not close any other registered device sessions or the multiplexing client itself.

If the multiplexed connection is already open, and this call would unregister the last device clients, the multiplexed connection will remain open. The multiplexed connection can only be closed by calling close()

Once a device client is unregistered, it may be re-registered to this or any other multiplexing client. It cannot be used in non-multiplexing scenarios.

Any subscriptions set on these device clients for twin/methods/cloud to device messages will need to be set again after these devices are re-registered.

void unregisterDeviceClients(Iterable<DeviceClient> deviceClients, long timeoutMilliseconds)

Unregister multiple device clients from this multiplexing client. This method may be called before or after opening the multiplexed connection.

If the multiplexed connection is already open, then this call will close the AMQP device session associated with this device, but it will not close any other registered device sessions or the multiplexing client itself.

If the multiplexed connection is already open, and this call would unregister the last device clients, the multiplexed connection will remain open. The multiplexed connection can only be closed by calling close()

Once a device client is unregistered, it may be re-registered to this or any other multiplexing client. It cannot be used in non-multiplexing scenarios.

Any subscriptions set on these device clients for twin/methods/cloud to device messages will need to be set again after these devices are re-registered.

Field Details

MAX_MULTIPLEX_DEVICE_COUNT_AMQPS

public static final int MAX_MULTIPLEX_DEVICE_COUNT_AMQPS= 1000

The maximum number of devices that can be multiplexed together on a single multiplexed AMQPS connection

MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS

public static final int MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS= 500

The maximum number of devices that can be multiplexed together on a single multiplexed AMQPS_WS connection

Constructor Details

MultiplexingClient

public MultiplexingClient(String hostName, IotHubClientProtocol protocol)

Instantiate a new MultiplexingClient that will establish a multiplexed connection through a proxy.

Parameters:

hostName - The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
protocol - The transport protocol that this client will build the multiplexed connection on. Must be either IotHubClientProtocol#AMQPS or IotHubClientProtocol#AMQPS_WS.

MultiplexingClient

public MultiplexingClient(String hostName, IotHubClientProtocol protocol, MultiplexingClientOptions options)

Instantiate a new MultiplexingClient that will establish a multiplexed connection through a proxy.

Parameters:

hostName - The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
protocol - The transport protocol that this client will build the multiplexed connection on. Must be IotHubClientProtocol#AMQPS_WS since using IotHubClientProtocol#AMQPS does not support proxies.
options - The optional parameters to configure this client to use.

Method Details

close

public void close()

Close this multiplexing client. This will close all active device sessions as well as the AMQP connection.

If this client is already closed, then this method will do nothing.

Once closed, this client can be re-opened. It will preserve all previously registered device clients.

getRegisteredDeviceCount

public int getRegisteredDeviceCount()

Get the number of currently registered devices on this multiplexing client.

Returns:

The number of currently registered devices on this multiplexing client.

isDeviceRegistered

public boolean isDeviceRegistered(String deviceId)

Returns if a device client for the provided device Id is already registered to this multiplexing client.

Parameters:

deviceId - The Id of the device client to look for.

Returns:

True if a device client is already registered with this Id. False otherwise.

open

public void open(boolean withRetry)

Opens this multiplexing client. This may be done before or after registering any number of device clients.

This call behaves synchronously, so if it returns without throwing, then all registered device clients were successfully opened.

If this client is already open, then this method will do nothing.

Parameters:

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:

IotHubClientException - If any IO or authentication errors occur while opening the multiplexed connection.
MultiplexingClientRegistrationException - If one or many of the registered devices failed to authenticate. Any devices not found in the map of registration exceptions provided by 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.

registerDeviceClient

public void registerDeviceClient(DeviceClient deviceClient)

Register a device client to this multiplexing client. This method may be called before or after opening the multiplexed connection.

Users should use registerDeviceClients(Iterable) for registering multiple devices as it has some performance improvements over repeatedly calling this method for individual device registrations. This method blocks on each registration, whereas registerDeviceClients(Iterable) blocks on all of the registrations after starting them all asynchronously.

A device client can be unregistered using unregisterDeviceClient(DeviceClient deviceClient), unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds), unregisterDeviceClients(Iterable), or unregisterDeviceClients(Iterable, long). A device client will not be unregistered automatically if it encounters a non-retryable exception, so users are responsible for unregistering a device client when they no longer want it in this multiplexing client.

Up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS devices can be registered on a multiplexed AMQPS connection, and up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS devices can be registered on a multiplexed AMQPS_WS connection.

If the multiplexing client is already open, then this device client will automatically be opened, too. If the multiplexing client is not open yet, then this device client will not be opened until open(boolean withRetry) is called.

If the multiplexed connection is already open, then this call will add this device client to the multiplexed connection, and then will block until the registration has been completed.

Any proxy settings set to the provided device clients will be overwritten by the proxy settings of this multiplexing client.

The registered device client must use the same transport protocol (AMQPS or AMQPS_WS) that this multiplexing client uses.

Each registered device client may have its own retry policy and its own SAS token expiry time, separate from every other registered device client.

The registered device client must use symmetric key based authentication.

The registered device client must belong to the same IoT hub as all previously registered device clients.

If the provided device client is already registered to this multiplexing client, then then this method will do nothing.

Any subscriptions (twin, methods, cloud to device messages) set on this device client from when it was previously registered to any multiplexing client will need to be set again as subscriptions and their callbacks are not preserved.

Parameters:

deviceClient - The device client to associate with this multiplexing client.

Throws:

InterruptedException - If the thread gets interrupted while waiting for the registration to succeed. This will never be thrown if the multiplexing client is not open yet.
MultiplexingClientRegistrationException - If the device failed to register. Details for this failure can be found nested within the map given by getRegistrationExceptions(). If this exception is thrown, the device was not registered, and therefore it does not need to be unregistered.
IotHubClientException - If this operation takes longer than the default timeout allows.

registerDeviceClient

public void registerDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds)

Register a device client to this multiplexing client. This method may be called before or after opening the multiplexed connection.

Users should use registerDeviceClients(Iterable) for registering multiple devices as it has some performance improvements over repeatedly calling this method for individual device registrations. This method blocks on each registration, whereas registerDeviceClients(Iterable) blocks on all of the registrations after starting them all asynchronously.

A device client can be unregistered using unregisterDeviceClient(DeviceClient deviceClient), unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds), unregisterDeviceClients(Iterable), or unregisterDeviceClients(Iterable, long). A device client will not be unregistered automatically if it encounters a non-retryable exception, so users are responsible for unregistering a device client when they no longer want it in this multiplexing client.

Up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS devices can be registered on a multiplexed AMQPS connection, and up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS devices can be registered on a multiplexed AMQPS_WS connection.

If the multiplexing client is already open, then this device client will automatically be opened, too. If the multiplexing client is not open yet, then this device client will not be opened until open(boolean withRetry) is called.

If the multiplexed connection is already open, then this call will add this device client to the multiplexed connection, and then will block until the registration has been completed.

Any proxy settings set to the provided device clients will be overwritten by the proxy settings of this multiplexing client.

The registered device client must use the same transport protocol (AMQPS or AMQPS_WS) that this multiplexing client uses.

Each registered device client may have its own retry policy and its own SAS token expiry time, separate from every other registered device client.

The registered device client must use symmetric key based authentication.

The registered device client must belong to the same IoT hub as all previously registered device clients.

If the provided device client is already registered to this multiplexing client, then then this method will do nothing.

Any subscriptions (twin, methods, cloud to device messages) set on this device client from when it was previously registered to any multiplexing client will need to be set again as subscriptions and their callbacks are not preserved.

Parameters:

deviceClient - The device client to associate with this multiplexing client.
timeoutMilliseconds - How long (in milliseconds) to let this operation wait for all registrations to complete. If this threshold is passed, a IotHubClientException with status code IotHubStatusCode#DEVICE_OPERATION_TIMED_OUT is thrown.

Throws:

InterruptedException - If the thread gets interrupted while waiting for the registration to succeed. This will never be thrown if the multiplexing client is not open yet.
MultiplexingClientRegistrationException - If the device failed to register. Details for this failure can be found nested within the map given by getRegistrationExceptions(). If this exception is thrown, the device was not registered, and therefore it does not need to be unregistered.
IotHubClientException - If this operation takes longer than the provided timeout allows.

registerDeviceClients

public void registerDeviceClients(Iterable deviceClients)

Register multiple device clients to this multiplexing client. This method may be called before or after opening the multiplexed connection.

Up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS devices can be registered on a multiplexed AMQPS connection, and up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS devices can be registered on a multiplexed AMQPS_WS connection.

A device client can be unregistered using unregisterDeviceClient(DeviceClient deviceClient), unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds), unregisterDeviceClients(Iterable), or unregisterDeviceClients(Iterable, long). A device client will not be unregistered automatically if it encounters a non-retryable exception, so users are responsible for unregistering a device client when they no longer want it in this multiplexing client.

If the multiplexing client is already open, then these device clients will automatically be opened, too. If the multiplexing client is not open yet, then these device clients will not be opened until open(boolean withRetry) is called.

If the multiplexed connection is already open, then this call will asynchronously add each device client to the multiplexed connection, and then will block until all registrations have been completed.

Any proxy settings set to the provided device clients will be overwritten by the proxy settings of this multiplexing client.

The registered device clients must use the same transport protocol (AMQPS or AMQPS_WS) that this multiplexing client uses.

Each registered device client may have its own retry policy and its own SAS token expiry time, separate from every other registered device client.

The registered device clients must use symmetric key based authentication.

The registered device clients must belong to the same IoT hub as all previously registered device clients.

If any of these device clients are already registered to this multiplexing client, then then this method will not do anything to that particular device client. All other provided device clients will still be registered though.

Any subscriptions (twin, methods, cloud to device messages) set on these device clients from when it was previously registered to any multiplexing client will need to be set again as subscriptions and their callbacks are not preserved.

Parameters:

deviceClients - The device clients to associate with this multiplexing client.

Throws:

InterruptedException - If the thread gets interrupted while waiting for the registration to succeed. This will never be thrown if the multiplexing client is not open yet.
MultiplexingClientRegistrationException - If one or more devices failed to register. Details for each failure can be found in the map provided by getRegistrationExceptions(). Any devices not found in the map of registration exceptions provided by this exception have registered successfully. Any devices that are found in the map of registration exceptions provided by this exception were not registered, and therefore do not need to be unregistered.
IotHubClientException - If this operation takes longer than the default timeout allows.

registerDeviceClients

public void registerDeviceClients(Iterable deviceClients, long timeoutMilliseconds)

Register multiple device clients to this multiplexing client. This method may be called before or after opening the multiplexed connection.

Up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS devices can be registered on a multiplexed AMQPS connection, and up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS devices can be registered on a multiplexed AMQPS_WS connection.

A device client can be unregistered using unregisterDeviceClient(DeviceClient deviceClient), unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds), unregisterDeviceClients(Iterable), or unregisterDeviceClients(Iterable, long). A device client will not be unregistered automatically if it encounters a non-retryable exception, so users are responsible for unregistering a device client when they no longer want it in this multiplexing client.

If the multiplexing client is already open, then these device clients will automatically be opened, too. If the multiplexing client is not open yet, then these device clients will not be opened until open(boolean withRetry) is called.

If the multiplexed connection is already open, then this call will asynchronously add each device client to the multiplexed connection, and then will block until all registrations have been completed.

Any proxy settings set to the provided device clients will be overwritten by the proxy settings of this multiplexing client.

The registered device clients must use the same transport protocol (AMQPS or AMQPS_WS) that this multiplexing client uses.

Each registered device client may have its own retry policy and its own SAS token expiry time, separate from every other registered device client.

The registered device clients must use symmetric key based authentication.

The registered device clients must belong to the same IoT hub as all previously registered device clients.

If any of these device clients are already registered to this multiplexing client, then then this method will not do anything to that particular device client. All other provided device clients will still be registered though.

Any subscriptions (twin, methods, cloud to device messages) set on these device clients from when it was previously registered to any multiplexing client will need to be set again as subscriptions and their callbacks are not preserved.

Parameters:

deviceClients - The device clients to associate with this multiplexing client.
timeoutMilliseconds - How long (in milliseconds) to let this operation wait for all registrations to complete. If this threshold is passed, a IotHubClientException with status code IotHubStatusCode#DEVICE_OPERATION_TIMED_OUT is thrown.

Throws:

InterruptedException - If the thread gets interrupted while waiting for the registration to succeed. This will never be thrown if the multiplexing client is not open yet.
MultiplexingClientRegistrationException - If one or more devices failed to register. Details for each failure can be found in the map provided by getRegistrationExceptions(). Any devices not found in the map of registration exceptions provided by this exception have registered successfully. Any devices that are found in the map of registration exceptions provided by this exception were not registered, and therefore do not need to be unregistered.
IotHubClientException - If this operation takes longer than the provided timeout allows.

setConnectionStatusChangeCallback

public void setConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext)

Registers a callback to be executed when the connection status of the multiplexed connection as a whole changes. The callback will be fired with a status and a reason why the multiplexed connection's status changed. When the callback is fired, the provided context will be provided alongside the status and reason.

Note that this callback will not be fired for device specific connection status changes. In order to be notified when a particular device's connection status changes, you will need to register a connection status change callback on that device client instance using setConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext).

Note that the thread used to deliver this callback should not be used to call open()/close() on the client that this callback belongs to. All open()/close() operations should be done on a separate thread

Parameters:

callback - The callback to be fired when the connection status of the multiplexed connection changes. Can be null to unset this listener as long as the provided callbackContext is also null.
callbackContext -

a context to be passed to the callback. Can benull 

</code> . </p>

setRetryPolicy

public void setRetryPolicy(RetryPolicy retryPolicy)

Sets the given retry policy for the multiplexing client level connection management. See more details about the default retry policy and about using custom retry policies here

Parameters:

retryPolicy - The policy that the multiplexing client will use when reconnecting.

unregisterDeviceClient

public void unregisterDeviceClient(DeviceClient deviceClient)

Unregister a device client from this multiplexing client. This method may be called before or after opening the multiplexed connection.

Users should use unregisterDeviceClients(Iterable) for unregistering multiple devices as it has some performance improvements over repeatedly calling this method for individual device unregistrations. This method blocks on each unregistration, whereas registerDeviceClients(Iterable) blocks on all of the unregistrations after starting them all asynchronously.

If the multiplexed connection is already open, then this call will close the AMQP device session associated with this device, but it will not close any other registered device sessions or the multiplexing client itself.

If the multiplexed connection is already open, and this call would unregister the last device client, the multiplexed connection will remain open. The multiplexed connection can only be closed by calling close()

Once a device client is unregistered, it may be re-registered to this or any other multiplexing client. It cannot be used in non-multiplexing scenarios.

Any subscriptions set on this device client for twin/methods/cloud to device messages will need to be set again after this device is re-registered.

Parameters:

deviceClient - The device client to unregister from this multiplexing client.

Throws:

InterruptedException - If the thread gets interrupted while waiting for the unregistration to succeed.
IotHubClientException - If the unregistration takes longer than the default timeout allows.

unregisterDeviceClient

public void unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds)

Unregister a device client from this multiplexing client. This method may be called before or after opening the multiplexed connection.

Users should use unregisterDeviceClients(Iterable) for unregistering multiple devices as it has some performance improvements over repeatedly calling this method for individual device unregistrations. This method blocks on each unregistration, whereas registerDeviceClients(Iterable) blocks on all of the unregistrations after starting them all asynchronously.

If the multiplexed connection is already open, then this call will close the AMQP device session associated with this device, but it will not close any other registered device sessions or the multiplexing client itself.

If the multiplexed connection is already open, and this call would unregister the last device client, the multiplexed connection will remain open. The multiplexed connection can only be closed by calling close()

Once a device client is unregistered, it may be re-registered to this or any other multiplexing client. It cannot be used in non-multiplexing scenarios.

Any subscriptions set on this device client for twin/methods/cloud to device messages will need to be set again after this device is re-registered.

Parameters:

deviceClient - The device client to unregister from this multiplexing client.
timeoutMilliseconds - How long (in milliseconds) to let this operation wait for all registrations to complete. If this threshold is passed, a IotHubClientException with status code IotHubStatusCode#DEVICE_OPERATION_TIMED_OUT is thrown.

Throws:

InterruptedException - If the thread gets interrupted while waiting for the unregistration to succeed.
IotHubClientException - If the unregistration takes longer than the provided timeout allows.

unregisterDeviceClients

public void unregisterDeviceClients(Iterable deviceClients)

Unregister multiple device clients from this multiplexing client. This method may be called before or after opening the multiplexed connection.

If the multiplexed connection is already open, then this call will close the AMQP device session associated with this device, but it will not close any other registered device sessions or the multiplexing client itself.

If the multiplexed connection is already open, and this call would unregister the last device clients, the multiplexed connection will remain open. The multiplexed connection can only be closed by calling close()

Once a device client is unregistered, it may be re-registered to this or any other multiplexing client. It cannot be used in non-multiplexing scenarios.

Any subscriptions set on these device clients for twin/methods/cloud to device messages will need to be set again after these devices are re-registered.

Parameters:

deviceClients - The device clients to unregister from this multiplexing client.

Throws:

InterruptedException - If the thread gets interrupted while waiting for the unregistration to succeed.
IotHubClientException - If the unregistration takes longer than the default timeout allows.

unregisterDeviceClients

public void unregisterDeviceClients(Iterable deviceClients, long timeoutMilliseconds)

Unregister multiple device clients from this multiplexing client. This method may be called before or after opening the multiplexed connection.

If the multiplexed connection is already open, then this call will close the AMQP device session associated with this device, but it will not close any other registered device sessions or the multiplexing client itself.

If the multiplexed connection is already open, and this call would unregister the last device clients, the multiplexed connection will remain open. The multiplexed connection can only be closed by calling close()

Once a device client is unregistered, it may be re-registered to this or any other multiplexing client. It cannot be used in non-multiplexing scenarios.

Any subscriptions set on these device clients for twin/methods/cloud to device messages will need to be set again after these devices are re-registered.

Parameters:

deviceClients - The device clients to unregister from this multiplexing client.
timeoutMilliseconds - How long (in milliseconds) to let this operation wait for all registrations to complete. If this threshold is passed, a IotHubClientException with status code IotHubStatusCode#DEVICE_OPERATION_TIMED_OUT is thrown.

Throws:

InterruptedException - If the thread gets interrupted while waiting for the unregistration to succeed.
IotHubClientException - If the unregistration takes longer than the provided timeout allows.

Applies to