Beispiel #1
0
        private void onShutDown()
        {
            this.serviceProvider
            .GetService <ILogger>()?.logMessage("Sensor is going down ... ");

            ServiceConfiguration config = ServiceConfiguration.Instance;
            IMessageBroker       broker = serviceProvider.GetService <IMessageBroker>();
            IDataCacheManager    cache  = serviceProvider.GetService <IDataCacheManager>();

            for (int sensorIndex = config.sensorsRange.From;
                 sensorIndex < config.sensorsRange.To;
                 sensorIndex++)
            {
                string sensorName = config.sensorNamePrefix + sensorIndex;
                var    newEvent   = new SensorLifetimeEvent(
                    config.serviceId,
                    LifetimeStages.Shutdown,
                    sensorName,
                    config.hostIP,
                    config.listeningPort,
                    cache.GetLastReadIndex(sensorName));

                var res = broker.PublishLifetimeEvent(newEvent).Result;
            }


            // next line will unregister this sensor using sensorRegistry restAPI
            // it is not necessary because sensor is gonna be unregistered once
            // registry receives it's lifetime event with shutdown 'flag'

            // result is not used (potential exception is handled inside the method)
            // bool unregResult = this.unregisterSensors();
        }
Beispiel #2
0
        public IActionResult getInfo([FromQuery] string sensorName)
        {
            var info = new SensorReaderInfo(
                sensorName,
                config.hostIP,
                config.listeningPort,
                dataCache.GetLastReadIndex(sensorName));

            return(new ObjectResult(info));
        }