Search in sources :

Example 1 with WriteValueContainer

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

the class DataManager method write.

@Override
public void write(List<WriteValueContainer> values) {
    HashMap<Device, List<WriteValueContainerImpl>> containersByDevice = new LinkedHashMap<>();
    for (WriteValueContainer value : values) {
        WriteValueContainerImpl valueContainerImpl = (WriteValueContainerImpl) value;
        if (valueContainerImpl.getValue() == null) {
            valueContainerImpl.setFlag(Flag.CANNOT_WRITE_NULL_VALUE);
            continue;
        }
        Device device = valueContainerImpl.getChannel().config.deviceParent.device;
        List<WriteValueContainerImpl> writeValueContainers = containersByDevice.get(device);
        if (writeValueContainers == null) {
            writeValueContainers = new LinkedList<>();
            containersByDevice.put(device, writeValueContainers);
        }
        writeValueContainers.add(valueContainerImpl);
    }
    CountDownLatch writeTasksFinishedSignal = new CountDownLatch(containersByDevice.size());
    synchronized (newWriteTasks) {
        for (Entry<Device, List<WriteValueContainerImpl>> writeValueContainers : containersByDevice.entrySet()) {
            WriteTask writeTask = new WriteTask(this, writeValueContainers.getKey(), writeValueContainers.getValue(), writeTasksFinishedSignal);
            newWriteTasks.add(writeTask);
        }
    }
    interrupt();
    try {
        writeTasksFinishedSignal.await();
    } catch (InterruptedException e) {
    }
}
Also used : WriteValueContainer(org.openmuc.framework.dataaccess.WriteValueContainer) LogicalDevice(org.openmuc.framework.dataaccess.LogicalDevice) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CountDownLatch(java.util.concurrent.CountDownLatch) ScanInterruptedException(org.openmuc.framework.config.ScanInterruptedException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ArrayList (java.util.ArrayList)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 WriteValueContainer (org.openmuc.framework.dataaccess.WriteValueContainer)1