예제 #1
0
        public void RemoveAmqpUnit(AmqpUnit amqpUnit)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, amqpUnit, $"{nameof(RemoveAmqpUnit)}");
            }

            DeviceIdentity deviceIdentity = amqpUnit.GetDeviceIdentity();

            if (deviceIdentity.IsPooling())
            {
                AmqpConnectionHolder amqpConnectionHolder;
                lock (_lock)
                {
                    AmqpConnectionHolder[] amqpConnectionHolders = ResolveConnectionGroup(deviceIdentity);
                    amqpConnectionHolder = ResolveConnectionByHashing(amqpConnectionHolders, deviceIdentity);
                }
                amqpConnectionHolder.RemoveAmqpUnit(amqpUnit);
            }

            if (Logging.IsEnabled)
            {
                Logging.Exit(this, amqpUnit, $"{nameof(RemoveAmqpUnit)}");
            }
        }
        public AmqpUnit CreateAmqpUnit(
            DeviceIdentity deviceIdentity,
            Func <MethodRequestInternal, Task> onMethodCallback,
            Action <Twin, string, TwinCollection, IotHubException> twinMessageListener,
            Func <string, Message, Task> onModuleMessageReceivedCallback,
            Func <Message, Task> onDeviceMessageReceivedCallback,
            Action onUnitDisconnected)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, deviceIdentity, nameof(CreateAmqpUnit));
            }

            var amqpUnit = new AmqpUnit(
                deviceIdentity,
                this,
                onMethodCallback,
                twinMessageListener,
                onModuleMessageReceivedCallback,
                onDeviceMessageReceivedCallback,
                onUnitDisconnected);

            lock (_unitsLock)
            {
                _amqpUnits.Add(amqpUnit);
            }
            if (Logging.IsEnabled)
            {
                Logging.Exit(this, deviceIdentity, nameof(CreateAmqpUnit));
            }

            return(amqpUnit);
        }
        public void RemoveAmqpUnit(AmqpUnit amqpUnit)
        {
            amqpUnit.Dispose();
            IAmqpUnitManager amqpConnectionPool = ResolveConnectionPool(amqpUnit.GetDeviceIdentity().IotHubConnectionString.HostName);

            amqpConnectionPool.RemoveAmqpUnit(amqpUnit);
        }
        internal AmqpTransportHandler(
            PipelineContext context,
            IotHubConnectionString connectionString,
            AmqpTransportSettings transportSettings,
            Func <MethodRequestInternal, Task> onMethodCallback          = null,
            Action <TwinCollection> onDesiredStatePatchReceivedCallback  = null,
            Func <string, Message, Task> onModuleMessageReceivedCallback = null,
            Func <Message, Task> onDeviceMessageReceivedCallback         = null)
            : base(context, transportSettings)
        {
            _operationTimeout            = transportSettings.OperationTimeout;
            _onDesiredStatePatchListener = onDesiredStatePatchReceivedCallback;
            IDeviceIdentity deviceIdentity = new DeviceIdentity(connectionString, transportSettings, context.ProductInfo, context.ClientOptions);

            _amqpUnit = AmqpUnitManager.GetInstance().CreateAmqpUnit(
                deviceIdentity,
                onMethodCallback,
                TwinMessageListener,
                onModuleMessageReceivedCallback,
                onDeviceMessageReceivedCallback,
                OnDisconnected);

            if (Logging.IsEnabled)
            {
                Logging.Associate(this, _amqpUnit, nameof(_amqpUnit));
            }
        }
        internal AmqpTransportHandler(
            IPipelineContext context,
            IotHubConnectionString connectionString,
            AmqpTransportSettings transportSettings,
            Func <MethodRequestInternal, Task> methodHandler = null,
            Action <TwinCollection> desiredPropertyListener  = null,
            Func <string, Message, Task> eventListener       = null)
            : base(context, transportSettings)
        {
            _operationTimeout        = transportSettings.OperationTimeout;
            _desiredPropertyListener = desiredPropertyListener;
            DeviceIdentity deviceIdentity = new DeviceIdentity(connectionString, transportSettings, context.Get <ProductInfo>());

            _amqpUnit = AmqpUnitManager.GetInstance().CreateAmqpUnit(
                deviceIdentity,
                methodHandler,
                TwinMessageListener,
                eventListener,
                OnDisconnected
                );

            if (Logging.IsEnabled)
            {
                Logging.Associate(this, _amqpUnit, $"{nameof(_amqpUnit)}");
            }
        }
        public AmqpUnit CreateAmqpUnit(
            DeviceIdentity deviceIdentity,
            Func <MethodRequestInternal, Task> methodHandler,
            Action <Twin, string, TwinCollection> twinMessageListener,
            Func <string, Message, Task> eventListener,
            Action onUnitDisconnected)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, deviceIdentity, $"{nameof(CreateAmqpUnit)}");
            }

            AmqpUnit amqpUnit = new AmqpUnit(
                deviceIdentity,
                this,
                methodHandler,
                twinMessageListener,
                eventListener,
                onUnitDisconnected);

            lock (_unitsLock)
            {
                _amqpUnits.Add(amqpUnit);
            }
            if (Logging.IsEnabled)
            {
                Logging.Exit(this, deviceIdentity, $"{nameof(CreateAmqpUnit)}");
            }
            return(amqpUnit);
        }
예제 #7
0
        public AmqpUnit CreateAmqpUnit(
            DeviceIdentity deviceIdentity,
            Func <MethodRequestInternal, Task> methodHandler,
            Action <AmqpMessage> twinMessageListener,
            Func <string, Message, Task> eventListener)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, deviceIdentity, $"{nameof(CreateAmqpUnit)}");
            }
            AmqpUnit amqpUnit = new AmqpUnit(
                deviceIdentity,
                AmqpSessionCreator,
                AuthenticationRefresherCreator,
                methodHandler,
                twinMessageListener,
                eventListener);

            amqpUnit.OnUnitDisconnected += (o, args) =>
            {
                bool gracefulDisconnect = (bool)o;
                RemoveDevice(deviceIdentity, gracefulDisconnect);
            };

            AmqpUnits.Remove(deviceIdentity);
            AmqpUnits.Add(deviceIdentity, amqpUnit);
            if (Logging.IsEnabled)
            {
                Logging.Exit(this, deviceIdentity, $"{nameof(CreateAmqpUnit)}");
            }
            return(amqpUnit);
        }
        public void RemoveAmqpUnit(AmqpUnit amqpUnit)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, amqpUnit, nameof(RemoveAmqpUnit));
            }

            IDeviceIdentity deviceIdentity = amqpUnit.GetDeviceIdentity();

            if (deviceIdentity.IsPooling())
            {
                AmqpConnectionHolder amqpConnectionHolder;
                lock (_lock)
                {
                    AmqpConnectionHolder[] amqpConnectionHolders = ResolveConnectionGroup(deviceIdentity);
                    amqpConnectionHolder = ResolveConnectionByHashing(amqpConnectionHolders, deviceIdentity);

                    amqpConnectionHolder.RemoveAmqpUnit(amqpUnit);

                    // If the connection holder does not have any more units, the entry needs to be nullified.
                    if (amqpConnectionHolder.IsEmpty())
                    {
                        int index = GetDeviceIdentityIndex(deviceIdentity, amqpConnectionHolders.Length);
                        amqpConnectionHolders[index] = null;
                        amqpConnectionHolder?.Dispose();
                    }
                }
            }

            if (Logging.IsEnabled)
            {
                Logging.Exit(this, amqpUnit, nameof(RemoveAmqpUnit));
            }
        }
 public void RemoveAmqpUnit(AmqpUnit amqpUnit)
 {
     if (Logging.IsEnabled)
     {
         Logging.Enter(this, amqpUnit, $"{nameof(RemoveAmqpUnit)}");
     }
     lock (_unitsLock)
     {
         _amqpUnits.Remove(amqpUnit);
         if (_amqpUnits.Count == 0)
         {
             // TODO #887: handle gracefulDisconnect
             Shutdown();
         }
     }
     if (Logging.IsEnabled)
     {
         Logging.Exit(this, amqpUnit, $"{nameof(RemoveAmqpUnit)}");
     }
 }