use of org.onosproject.store.service.Versioned in project onos by opennetworkinglab.
the class DistributedDynamicConfigStore method readInner.
private void readInner(DataNode.Builder superBldr, String spath) {
CompletableFuture<Map<String, Versioned<DataNode.Type>>> ret = keystore.getChildren(DocumentPath.from(spath));
Map<String, Versioned<DataNode.Type>> entries = null;
entries = complete(ret);
log.trace(" keystore.getChildren({})", spath);
log.trace(" entries keys:{}", entries.keySet());
if (!entries.isEmpty()) {
entries.forEach((k, v) -> {
String[] names = k.split(ResourceIdParser.NM_CHK);
String name = names[0];
String nmSpc = ResourceIdParser.getNamespace(names[1]);
String keyVal = ResourceIdParser.getKeyVal(names[1]);
DataNode.Type type = v.value();
String tempPath = ResourceIdParser.appendNodeKey(spath, name, nmSpc);
if (type == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) {
LeafNode lfnode = readLeaf(tempPath);
// FIXME there should be builder for copying
superBldr.createChildBuilder(name, nmSpc, lfnode.value(), lfnode.valueNamespace()).type(type).leafType(lfnode.leafType()).exitNode();
} else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) {
String mlpath = ResourceIdParser.appendLeafList(tempPath, keyVal);
LeafNode lfnode = readLeaf(mlpath);
// FIXME there should be builder for copying
superBldr.createChildBuilder(name, nmSpc, lfnode.value(), lfnode.valueNamespace()).type(type).leafType(lfnode.leafType()).addLeafListValue(lfnode.value()).exitNode();
// TODO this alone should be sufficient and take the nm, nmspc too
} else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) {
DataNode.Builder tempBldr = superBldr.createChildBuilder(name, nmSpc).type(type);
readInner(tempBldr, tempPath);
} else if (type == DataNode.Type.MULTI_INSTANCE_NODE) {
DataNode.Builder tempBldr = superBldr.createChildBuilder(name, nmSpc).type(type);
tempPath = ResourceIdParser.appendMultiInstKey(tempPath, k);
String[] keys = k.split(ResourceIdParser.KEY_CHK);
for (int i = 1; i < keys.length; i++) {
// String curKey = ResourceIdParser.appendKeyLeaf(tempPath, keys[i]);
// LeafNode lfnd = readLeaf(curKey);
String[] keydata = keys[i].split(ResourceIdParser.NM_CHK);
tempBldr.addKeyLeaf(keydata[0], keydata[1], keydata[2]);
}
readInner(tempBldr, tempPath);
} else {
throw new FailedException("Invalid node type");
}
});
}
superBldr.exitNode();
}
use of org.onosproject.store.service.Versioned in project onos by opennetworkinglab.
the class DistributedDhcpStore method listAssignedMapping.
@Override
public Map<HostId, IpAssignment> listAssignedMapping() {
Map<HostId, IpAssignment> validMapping = new HashMap<>();
IpAssignment assignment;
for (Map.Entry<HostId, Versioned<IpAssignment>> entry : allocationMap.entrySet()) {
assignment = entry.getValue().value();
if (assignment.assignmentStatus() == Option_Assigned || assignment.assignmentStatus() == Option_RangeNotEnforced) {
validMapping.put(entry.getKey(), assignment);
}
}
return validMapping;
}
use of org.onosproject.store.service.Versioned in project fabric-tna by stratum.
the class MockConsistentMap method computeIfPresent.
@Override
public Versioned<V> computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
AtomicBoolean updated = new AtomicBoolean(false);
AtomicReference<Versioned<V>> previousValue = new AtomicReference<>();
Versioned<V> result = map.compute(key, (k, v) -> {
if (v != null) {
updated.set(true);
previousValue.set(serializer.decode(serializer.encode(v)));
return version(remappingFunction.apply(k, v.value()));
}
return v;
});
if (updated.get()) {
notifyListeners(mapName, key, result, previousValue.get());
}
return result;
}
use of org.onosproject.store.service.Versioned in project fabric-tna by stratum.
the class MockConsistentMap method computeIf.
@Override
public Versioned<V> computeIf(K key, Predicate<? super V> condition, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
AtomicBoolean updated = new AtomicBoolean(false);
AtomicReference<Versioned<V>> previousValue = new AtomicReference<>();
Versioned<V> result = map.compute(key, (k, v) -> {
if (condition.test(Versioned.valueOrNull(v))) {
previousValue.set(serializer.decode(serializer.encode(v)));
updated.set(true);
return version(remappingFunction.apply(k, Versioned.valueOrNull(v)));
}
return v;
});
if (updated.get()) {
notifyListeners(mapName, key, result, previousValue.get());
}
return result;
}
Aggregations