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(); }
private void onStarted() { ServiceConfiguration config = ServiceConfiguration.Instance; IMessageBroker broker = serviceProvider.GetService <IMessageBroker>(); for (int sensorIndex = config.sensorsRange.From; sensorIndex < config.sensorsRange.To; sensorIndex++) { string sensorName = config.sensorNamePrefix + sensorIndex; var newEvent = new SensorLifetimeEvent( config.serviceId, LifetimeStages.Startup, sensorName, config.hostIP, config.listeningPort, 0); var ret = broker.PublishLifetimeEvent(newEvent).Result; } }
public SensorLifetimeRequest(SensorLifetimeEvent newEvent) { NewEvent = newEvent; }