use of org.openmuc.framework.driver.spi.DriverService in project OpenMUC by isc-konstanz.
the class DataManager method handleInterruptEvent.
private void handleInterruptEvent() {
if (stopFlag) {
prepareStop();
return;
}
long currentTime = 0;
if (newRootConfigWithoutDefaults != null) {
currentTime = System.currentTimeMillis();
applyConfiguration(newRootConfigWithoutDefaults, currentTime);
newRootConfigWithoutDefaults = null;
newConfigSignal.countDown();
}
synchronized (receivedRecordContainers) {
List<ChannelRecordContainer> recordContainers;
LoggingController loggingController = new LoggingController(activeDataLoggers);
List<ChannelRecordContainerImpl> channelRecordContainerList = new ArrayList<>();
while ((recordContainers = receivedRecordContainers.poll()) != null) {
recordContainers.stream().map(recContainer -> (ChannelRecordContainerImpl) recContainer).filter(containerImpl -> containerImpl.getChannel().getChannelState() == ChannelState.LISTENING || containerImpl.getChannel().getDriverId().equals(DriverOptionsFactory.VIRTUAL)).forEach(containerImpl -> {
containerImpl.getChannel().setNewRecord(containerImpl.getRecord());
if (containerImpl.getChannel().isLoggingEvent())
channelRecordContainerList.add(containerImpl);
});
}
loggingController.deliverLogsToEventBasedLogServices(channelRecordContainerList);
}
synchronized (samplingTaskFinished) {
SamplingTask samplingTask;
while ((samplingTask = samplingTaskFinished.poll()) != null) {
samplingTask.storeValues();
samplingTask.device.taskFinished();
}
}
synchronized (tasksFinished) {
DeviceTask deviceTask;
while ((deviceTask = tasksFinished.poll()) != null) {
deviceTask.device.taskFinished();
}
}
synchronized (newDrivers) {
// Needed to synchronize with getRunningDrivers
synchronized (activeDrivers) {
activeDrivers.putAll(newDrivers);
}
for (Entry<String, DriverService> newDriverEntry : newDrivers.entrySet()) {
String driverId = newDriverEntry.getKey();
logger.info("Registered driver: " + driverId);
DriverConfigImpl driverConfig = rootConfig.driverConfigsById.get(driverId);
if (driverConfig == null) {
continue;
}
driverConfig.activeDriver = newDriverEntry.getValue();
for (DeviceConfigImpl deviceConfig : driverConfig.deviceConfigsById.values()) {
deviceConfig.device.driverRegisteredSignal();
}
}
newDrivers.clear();
}
synchronized (newServers) {
if (!newServers.isEmpty()) {
activeServers.addAll(newServers);
for (ServerService server : newServers) {
logger.info("Registered server: {}", server.getId());
notifyServer(server);
}
newServers.clear();
}
}
synchronized (newDataLoggers) {
if (!newDataLoggers.isEmpty()) {
activeDataLoggers.addAll(newDataLoggers);
for (DataLoggerService dataLogger : newDataLoggers) {
logger.info("Registered data logger: {}", dataLogger.getId());
dataLogger.setChannelsToLog(rootConfig.logChannels);
}
newDataLoggers.clear();
}
}
if (driverToBeRemovedId != null) {
DriverService removedDriver;
synchronized (activeDrivers) {
removedDriver = activeDrivers.remove(driverToBeRemovedId);
}
if (removedDriver == null) {
// drivers was removed before it was added to activeDrivers
newDrivers.remove(driverToBeRemovedId);
driverRemovedSignal.countDown();
} else {
DriverConfigImpl driverConfig = rootConfig.driverConfigsById.get(driverToBeRemovedId);
if (driverConfig != null) {
activeDeviceCountDown = driverConfig.deviceConfigsById.size();
if (activeDeviceCountDown > 0) {
// all devices have to be given a chance to finish their current task and disconnect:
for (DeviceConfigImpl deviceConfig : driverConfig.deviceConfigsById.values()) {
deviceConfig.device.driverDeregisteredSignal();
}
synchronized (driverRemovedSignal) {
if (activeDeviceCountDown == 0) {
driverRemovedSignal.countDown();
}
}
} else {
driverRemovedSignal.countDown();
}
} else {
driverRemovedSignal.countDown();
}
}
driverToBeRemovedId = null;
}
if (serverToBeRemoved != null) {
if (!activeServers.remove(serverToBeRemoved)) {
newServers.remove(serverToBeRemoved);
}
serverToBeRemoved = null;
serverRemovedSignal.countDown();
}
if (dataLoggerToBeRemoved != null) {
if (!activeDataLoggers.remove(dataLoggerToBeRemoved)) {
newDataLoggers.remove(dataLoggerToBeRemoved);
}
dataLoggerToBeRemoved = null;
dataLoggerRemovedSignal.countDown();
}
synchronized (connectionFailures) {
if (currentTime == 0) {
currentTime = System.currentTimeMillis();
}
Device connectionFailureDevice;
while ((connectionFailureDevice = connectionFailures.poll()) != null) {
connectionFailureDevice.connectFailureSignal(currentTime);
}
}
synchronized (connectedDevices) {
if (currentTime == 0) {
currentTime = System.currentTimeMillis();
}
Device connectedDevice;
while ((connectedDevice = connectedDevices.poll()) != null) {
connectedDevice.connectedSignal(currentTime);
}
}
synchronized (newWriteTasks) {
addTasksAndClear(newWriteTasks);
}
synchronized (newReadTasks) {
addTasksAndClear(newReadTasks);
}
synchronized (disconnectedDevices) {
Device connectedDevice;
while ((connectedDevice = disconnectedDevices.poll()) != null) {
connectedDevice.disconnectedSignal();
}
}
}
use of org.openmuc.framework.driver.spi.DriverService in project OpenMUC by isc-konstanz.
the class DataManager method scanForChannels.
@Override
public List<ChannelScanInfo> scanForChannels(String deviceId, String settings) throws DriverNotAvailableException, UnsupportedOperationException, ArgumentSyntaxException, ScanException {
// TODO this function is probably not thread safe
DeviceConfigImpl config = (DeviceConfigImpl) this.rootConfig.getDevice(deviceId);
if (config == null) {
throw new ScanException("No device with ID \"" + deviceId + "\" found.");
}
DriverService activeDriver = activeDrivers.get(config.driverParent.id);
if (activeDriver == null) {
throw new DriverNotAvailableException();
}
waitTilDeviceIsConnected(config.device);
try {
return config.device.connection.scanForChannels(settings);
} catch (ConnectionException e) {
config.device.disconnectedSignal();
throw new ScanException(e.getMessage(), e);
}
}
use of org.openmuc.framework.driver.spi.DriverService in project OpenMUC by isc-konstanz.
the class DataManager method interruptDeviceScan.
@Override
public void interruptDeviceScan(String driverId) throws DriverNotAvailableException, UnsupportedOperationException {
DriverService driver = activeDrivers.get(driverId);
if (driver == null) {
throw new DriverNotAvailableException();
}
driver.interruptDeviceScan();
}
use of org.openmuc.framework.driver.spi.DriverService in project OpenMUC by isc-konstanz.
the class DataManager method scanForDevices.
@Override
public void scanForDevices(String driverId, String settings, DeviceScanListener scanListener) throws DriverNotAvailableException {
DriverService driver = activeDrivers.get(driverId);
if (driver == null) {
throw new DriverNotAvailableException();
}
executor.execute(new ScanForDevicesTask(driver, settings, scanListener));
}
use of org.openmuc.framework.driver.spi.DriverService in project OpenMUC by isc-konstanz.
the class DataManager method scanForDevices.
@Override
public List<DeviceScanInfo> scanForDevices(String driverId, String settings) throws DriverNotAvailableException, ArgumentSyntaxException, ScanException, ScanInterruptedException {
DriverService driver = activeDrivers.get(driverId);
if (driver == null) {
throw new DriverNotAvailableException();
}
BlockingScanListener blockingScanListener = new BlockingScanListener();
try {
driver.scanForDevices(settings, blockingScanListener);
} catch (RuntimeException e) {
if (e instanceof UnsupportedOperationException) {
throw e;
}
throw new ScanException(e);
}
return blockingScanListener.scanInfos;
}
Aggregations