in iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/MultiplexingClient.java [80:150]
public MultiplexingClient(String hostName, IotHubClientProtocol protocol, MultiplexingClientOptions options)
{
Objects.requireNonNull(hostName);
Objects.requireNonNull(protocol);
switch (protocol)
{
case AMQPS:
case AMQPS_WS:
break;
default:
throw new IllegalArgumentException("Multiplexing is only supported for AMQPS and AMQPS_WS");
}
// Deliberately using HashMap instead of ConcurrentHashMap here. HashMap is faster for several operations such
// .size() and we can control the adding/removing of elements to it with synchronization within this client.
this.multiplexedDeviceClients = new HashMap<>();
this.hostName = hostName;
this.protocol = protocol;
this.proxySettings = options != null ? options.getProxySettings() : null;
long sendPeriod = options != null ? options.getSendInterval() : DEFAULT_SEND_PERIOD_MILLIS;
long receivePeriod = options != null ? options.getReceiveInterval() : DEFAULT_RECEIVE_PERIOD_MILLIS;
int sendMessagesPerThread = options != null ? options.getMaxMessagesSentPerSendInterval() : DEFAULT_MAX_MESSAGES_TO_SEND_PER_THREAD;
int keepAliveInterval = options != null ? options.getKeepAliveInterval() : DEFAULT_KEEP_ALIVE_INTERVAL_IN_SECONDS;
int sendInterval = (int) (options != null ? options.getSendInterval() : DEFAULT_SEND_INTERVAL_IN_MILLISECONDS);
String threadNamePrefix = options != null ? options.getThreadNamePrefix() : null;
String threadNameSuffix = options != null ? options.getThreadNameSuffix() : null;
boolean useIdentifiableThreadNames = options == null || options.isUsingIdentifiableThreadNames();
long messageExpiredCheckPeriod = options != null ? options.getMessageExpirationCheckPeriod() : DEFAULT_MESSAGE_EXPIRATION_CHECK_PERIOD;
if (sendPeriod < 0)
{
throw new IllegalArgumentException("Send period cannot be negative");
}
else if (sendPeriod == 0) //default builder value for this option, signals that user didn't set a value
{
sendPeriod = DEFAULT_SEND_PERIOD_MILLIS;
}
if (receivePeriod < 0)
{
throw new IllegalArgumentException("Receive period cannot be negative");
}
else if (receivePeriod == 0) //default builder value for this option, signals that user didn't set a value
{
receivePeriod = DEFAULT_RECEIVE_PERIOD_MILLIS;
}
if (sendMessagesPerThread == 0) //default builder value for this option, signals that user didn't set a value
{
sendMessagesPerThread = DEFAULT_MAX_MESSAGES_TO_SEND_PER_THREAD;
}
// Optional settings from MultiplexingClientOptions
SSLContext sslContext = options != null ? options.getSslContext() : null;
this.deviceIO = new DeviceIO(
hostName,
protocol,
sslContext,
proxySettings,
keepAliveInterval,
sendInterval,
useIdentifiableThreadNames,
threadNamePrefix,
threadNameSuffix,
messageExpiredCheckPeriod);
this.deviceIO.setMaxNumberOfMessagesSentPerSendThread(sendMessagesPerThread);
this.deviceIO.setSendPeriodInMilliseconds(sendPeriod);
this.deviceIO.setReceivePeriodInMilliseconds(receivePeriod);
}