Search in sources :

Example 1 with ReadRecordContainer

use of org.openmuc.framework.dataaccess.ReadRecordContainer in project OpenMUC by isc-konstanz.

the class DataManager method read.

@Override
public void read(List<ReadRecordContainer> readContainers) {
    Map<Device, List<ChannelRecordContainerImpl>> containersByDevice = new HashMap<>();
    for (ReadRecordContainer container : readContainers) {
        if (container instanceof ChannelRecordContainerImpl == false) {
            throw new IllegalArgumentException("Only use ReadRecordContainer created by Channel.getReadContainer()");
        }
        ChannelImpl channel = (ChannelImpl) container.getChannel();
        List<ChannelRecordContainerImpl> containersOfDevice = containersByDevice.get(channel.config.deviceParent.device);
        if (containersOfDevice == null) {
            containersOfDevice = new LinkedList<>();
            containersByDevice.put(channel.config.deviceParent.device, containersOfDevice);
        }
        containersOfDevice.add((ChannelRecordContainerImpl) container);
    }
    CountDownLatch readTasksFinishedSignal = new CountDownLatch(containersByDevice.size());
    synchronized (newReadTasks) {
        for (Entry<Device, List<ChannelRecordContainerImpl>> channelRecordContainers : containersByDevice.entrySet()) {
            ReadTask readTask = new ReadTask(this, channelRecordContainers.getKey(), channelRecordContainers.getValue(), readTasksFinishedSignal);
            newReadTasks.add(readTask);
        }
    }
    interrupt();
    try {
        readTasksFinishedSignal.await();
    } catch (InterruptedException e) {
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LogicalDevice(org.openmuc.framework.dataaccess.LogicalDevice) CountDownLatch(java.util.concurrent.CountDownLatch) ScanInterruptedException(org.openmuc.framework.config.ScanInterruptedException) ReadRecordContainer(org.openmuc.framework.dataaccess.ReadRecordContainer) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScanInterruptedException (org.openmuc.framework.config.ScanInterruptedException)1 LogicalDevice (org.openmuc.framework.dataaccess.LogicalDevice)1 ReadRecordContainer (org.openmuc.framework.dataaccess.ReadRecordContainer)1