use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class ConsistentMapTestCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
map = storageService.<String, String>consistentMapBuilder().withName(name).withSerializer(Serializer.using(KryoNamespaces.BASIC)).withVersion(Version.version("1.0.0")).withCompatibilityFunction((value, version) -> version + ":" + value).build();
if ("get".equals(operation)) {
print(map.get(arg1));
} else if ("put".equals(operation)) {
print(map.put(arg1, arg2));
} else if ("size".equals(operation)) {
print("%d", map.size());
} else if ("isEmpty".equals(operation)) {
print("%b", map.isEmpty());
} else if ("putIfAbsent".equals(operation)) {
print(map.putIfAbsent(arg1, arg2));
} else if ("putAndGet".equals(operation)) {
print(map.putAndGet(arg1, arg2));
} else if ("clear".equals(operation)) {
map.clear();
} else if ("remove".equals(operation)) {
if (arg2 == null) {
print(map.remove(arg1));
} else {
print("%b", map.remove(arg1, arg2));
}
} else if ("containsKey".equals(operation)) {
print("%b", map.containsKey(arg1));
} else if ("containsValue".equals(operation)) {
print("%b", map.containsValue(arg1));
} else if ("replace".equals(operation)) {
if (arg3 == null) {
print(map.replace(arg1, arg2));
} else {
print("%b", map.replace(arg1, arg2, arg3));
}
} else if ("compatiblePut".equals(operation)) {
ConsistentMap<String, String> map = storageService.<String, String>consistentMapBuilder().withName(name).withSerializer(Serializer.using(KryoNamespaces.BASIC)).withCompatibilityFunction((value, version) -> version + ":" + value).withVersion(Version.version("2.0.0")).build();
print(map.put(arg1, arg2));
} else if ("compatibleGet".equals(operation)) {
ConsistentMap<String, String> map = storageService.<String, String>consistentMapBuilder().withName(name).withSerializer(Serializer.using(KryoNamespaces.BASIC)).withCompatibilityFunction((value, version) -> version + ":" + value).withVersion(Version.version("2.0.0")).build();
print(map.get(arg1));
}
}
use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class DocumentTreeTestCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
tree = storageService.<String>getDocumentTree(name, Serializer.using(KryoNamespaces.BASIC)).asDocumentTree();
tree.addListener(value -> {
log.debug("Received event: {}", value);
});
if ("set".equals(operation)) {
log.debug("set {} {}", DocumentPath.from(arg1), arg2);
print(tree.set(DocumentPath.from(arg1), arg2));
} else if ("get".equals(operation)) {
log.debug("get {}", DocumentPath.from(arg1));
print(tree.get(DocumentPath.from(arg1)));
} else if ("remove".equals(operation)) {
log.debug("removeNode {}", DocumentPath.from(arg1));
print(tree.removeNode(DocumentPath.from(arg1)));
} else if ("create".equals(operation)) {
log.debug("create {} {}", DocumentPath.from(arg1), arg2);
print("%b", tree.create(DocumentPath.from(arg1), arg2));
} else if ("createRecursive".equals(operation)) {
log.debug("createRecursive {} {}", DocumentPath.from(arg1), arg2);
print("%b", tree.createRecursive(DocumentPath.from(arg1), arg2));
}
}
use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class SetTestAddCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
set = storageService.<String>setBuilder().withName(setName).withSerializer(serializer).build().asDistributedSet();
// Add a single element to the set
if (values.length == 1) {
if (set.add(values[0])) {
print("[%s] was added to the set %s", values[0], setName);
} else {
print("[%s] was already in set %s", values[0], setName);
}
} else if (values.length >= 1) {
// Add multiple elements to a set
if (set.addAll(Arrays.asList(values))) {
print("%s was added to the set %s", Arrays.asList(values), setName);
} else {
print("%s was already in set %s", Arrays.asList(values), setName);
}
}
}
use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class TransactionalMapTestGetCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
TransactionContext context;
context = storageService.transactionContextBuilder().build();
context.begin();
try {
map = context.getTransactionalMap(mapName, serializer);
String response = map.get(key);
context.commit();
if (response == null) {
print("Key %s not found.", key);
} else {
print("Key-value pair (%s, %s) found.", key, response);
}
} catch (Exception e) {
context.abort();
throw e;
}
}
use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class TransactionalMapTestPutCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
TransactionContext context;
context = storageService.transactionContextBuilder().build();
context.begin();
try {
map = context.getTransactionalMap(mapName, serializer);
for (int i = 1; i <= numKeys; i++) {
String key = prefix + i;
String response = map.put(key, value);
if (response == null) {
print("Created Key %s with value %s.", key, value);
} else {
print("Put %s into key %s. The old value was %s.", value, key, response);
}
}
context.commit();
} catch (Exception e) {
context.abort();
throw e;
}
}
Aggregations