private IAmqpConnectionHolder GetLeastUsedConnection(ISet <IAmqpConnectionHolder> amqpConnectionHolders) { if (Logging.IsEnabled) { Logging.Enter(this, $"{nameof(GetLeastUsedConnection)}"); } int count = MaxSpan; IAmqpConnectionHolder amqpConnectionHolder = null; foreach (IAmqpConnectionHolder value in amqpConnectionHolders) { int clientCount = value.GetNumberOfUnits(); if (clientCount < count) { amqpConnectionHolder = value; count = clientCount; if (count == 0) { break; } } } if (Logging.IsEnabled) { Logging.Exit(this, $"{nameof(GetLeastUsedConnection)}"); } return(amqpConnectionHolder); }
public MoqableAmqpUnit(DeviceIdentity deviceIdentity, IAmqpConnectionHolder amqpConnectionHolder, Func <MethodRequestInternal, Task> onMethodCallback = null, Action <Twin, string, TwinCollection, IotHubException> twinMessageListener = null, Func <string, Message, Task> onModuleMessageReceivedCallback = null, Func <Message, Task> onDeviceMessageReceivedCallback = null, Action onUnitDisconnected = null) : base(deviceIdentity, amqpConnectionHolder, onMethodCallback, twinMessageListener, onModuleMessageReceivedCallback, onDeviceMessageReceivedCallback, onUnitDisconnected) { }
public AmqpUnit( DeviceIdentity deviceIdentity, IAmqpConnectionHolder amqpConnectionHolder, Func <MethodRequestInternal, Task> onMethodCallback, Action <Twin, string, TwinCollection, IotHubException> twinMessageListener, Func <string, Message, Task> onModuleMessageReceivedCallback, Func <Message, Task> onDeviceMessageReceivedCallback, Action onUnitDisconnected) { _deviceIdentity = deviceIdentity; _onMethodCallback = onMethodCallback; _twinMessageListener = twinMessageListener; _onModuleMessageReceivedCallback = onModuleMessageReceivedCallback; _onDeviceMessageReceivedCallback = onDeviceMessageReceivedCallback; _amqpConnectionHolder = amqpConnectionHolder; _onUnitDisconnected = onUnitDisconnected; Logging.Associate(this, _deviceIdentity, nameof(_deviceIdentity)); }
public AmqpUnit( DeviceIdentity deviceIdentity, IAmqpConnectionHolder amqpConnectionHolder, Func <MethodRequestInternal, Task> methodHandler, Action <Twin, string, TwinCollection> twinMessageListener, Func <string, Message, Task> eventListener, Action onUnitDisconnected) { _deviceIdentity = deviceIdentity; _methodHandler = methodHandler; _twinMessageListener = twinMessageListener; _eventListener = eventListener; _amqpConnectionHolder = amqpConnectionHolder; _onUnitDisconnected = onUnitDisconnected; if (Logging.IsEnabled) { Logging.Associate(this, _deviceIdentity, $"{nameof(_deviceIdentity)}"); } }
private void RemoveConnection(ISet <IAmqpConnectionHolder> amqpConnectionHolders, IAmqpConnectionHolder amqpConnectionHolder) { lock (Lock) { bool removed = amqpConnectionHolder.GetNumberOfUnits() == 0 && amqpConnectionHolders.Remove(amqpConnectionHolder); if (Logging.IsEnabled) { Logging.Info(this, $"Remove ConnectionHolder {amqpConnectionHolder}: {removed}"); } } }