Search in sources :

Example 1 with ConfigChangeListener

use of org.openmuc.framework.config.ConfigChangeListener in project OpenMUC by isc-konstanz.

the class DataManager method applyConfiguration.

private void applyConfiguration(RootConfigImpl configWithoutDefaults, long currentTime) {
    RootConfigImpl newRootConfig = configWithoutDefaults.cloneWithDefaults();
    List<LogChannel> logChannels = new LinkedList<>();
    for (DriverConfigImpl oldDriverConfig : rootConfig.driverConfigsById.values()) {
        DriverConfigImpl newDriverConfig = newRootConfig.driverConfigsById.get(oldDriverConfig.id);
        if (newDriverConfig != null) {
            newDriverConfig.activeDriver = oldDriverConfig.activeDriver;
        }
        for (DeviceConfigImpl oldDeviceConfig : oldDriverConfig.deviceConfigsById.values()) {
            DeviceConfigImpl newDeviceConfig = null;
            if (newDriverConfig != null) {
                newDeviceConfig = newDriverConfig.deviceConfigsById.get(oldDeviceConfig.getId());
            }
            if (newDeviceConfig == null) {
                // Device was deleted in new config
                oldDeviceConfig.device.deleteSignal();
            } else {
                // Device exists in new and old config
                oldDeviceConfig.device.configChangedSignal(newDeviceConfig, currentTime, logChannels);
            }
        }
    }
    for (DriverConfigImpl newDriverConfig : newRootConfig.driverConfigsById.values()) {
        DriverConfigImpl oldDriverConfig = rootConfig.driverConfigsById.get(newDriverConfig.id);
        if (oldDriverConfig == null) {
            newDriverConfig.activeDriver = activeDrivers.get(newDriverConfig.id);
        }
        for (DeviceConfigImpl newDeviceConfig : newDriverConfig.deviceConfigsById.values()) {
            DeviceConfigImpl oldDeviceConfig = null;
            if (oldDriverConfig != null) {
                oldDeviceConfig = oldDriverConfig.deviceConfigsById.get(newDeviceConfig.getId());
            }
            if (oldDeviceConfig == null) {
                // Device is new
                newDeviceConfig.device = new Device(this, newDeviceConfig, currentTime, logChannels);
                if (newDeviceConfig.device.getState() == DeviceState.CONNECTING) {
                    newDeviceConfig.device.connectRetrySignal();
                }
            }
        }
    }
    for (ChannelConfigImpl oldChannelConfig : rootConfig.channelConfigsById.values()) {
        ChannelConfigImpl newChannelConfig = newRootConfig.channelConfigsById.get(oldChannelConfig.getId());
        if (newChannelConfig == null) {
            // oldChannelConfig does not exist in the new configuration
            if (oldChannelConfig.state == ChannelState.SAMPLING) {
                removeFromSamplingCollections(oldChannelConfig.channel);
            }
            oldChannelConfig.state = ChannelState.DELETED;
            oldChannelConfig.channel.setFlag(Flag.CHANNEL_DELETED);
        // note: disabling SampleTasks and such has to be done at the
        // Device level
        }
    }
    updateLogChannelsInDataLoggers(logChannels);
    newRootConfig.logChannels = logChannels;
    synchronized (configChangeListeners) {
        rootConfig = newRootConfig;
        rootConfigWithoutDefaults = configWithoutDefaults;
        for (final ConfigChangeListener configChangeListener : configChangeListeners) {
            if (configChangeListener == null) {
                continue;
            }
            executor.execute(configChangeListener::configurationChanged);
        }
    }
    notifyServers();
}
Also used : ConfigChangeListener(org.openmuc.framework.config.ConfigChangeListener) LogicalDevice(org.openmuc.framework.dataaccess.LogicalDevice) LogChannel(org.openmuc.framework.datalogger.spi.LogChannel) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 ConfigChangeListener (org.openmuc.framework.config.ConfigChangeListener)1 LogicalDevice (org.openmuc.framework.dataaccess.LogicalDevice)1 LogChannel (org.openmuc.framework.datalogger.spi.LogChannel)1