use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class RouteManager method activate.
@Activate
protected void activate() {
routeMonitor = new RouteMonitor(this, clusterService, storageService);
routeResolver = new RouteResolver(this, hostService);
threadFactory = groupedThreads("onos/route", "listener-%d", log);
hostEventExecutors = new PredictableExecutor(DEFAULT_BUCKETS, groupedThreads("onos/route-manager", "event-host-%d", log));
resolvedRouteStore = new DefaultResolvedRouteStore();
routeStore.setDelegate(delegate);
hostService.addListener(hostListener);
routeStore.getRouteTables().stream().flatMap(id -> routeStore.getRoutes(id).stream()).forEach(routeSet -> routeResolver.resolve(routeSet));
}
use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class CounterTestCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
atomicCounter = storageService.getAsyncAtomicCounter(counter).asAtomicCounter();
if ("get".equals(operation)) {
print("%d", atomicCounter.get());
} else if ("set".equals(operation)) {
atomicCounter.set(value1);
} else if ("incrementAndGet".equals(operation)) {
print("%d", atomicCounter.incrementAndGet());
} else if ("getAndIncrement".equals(operation)) {
print("%d", atomicCounter.getAndIncrement());
} else if ("getAndAdd".equals(operation)) {
print("%d", atomicCounter.getAndAdd(value1));
} else if ("addAndGet".equals(operation)) {
print("%d", atomicCounter.addAndGet(value1));
} else if ("compareAndSet".equals(operation)) {
print("%b", atomicCounter.compareAndSet(value1, value2));
} else if ("destroy".equals(operation)) {
atomicCounter.destroy();
}
}
use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class CounterTestIncrementCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
atomicCounter = storageService.getAsyncAtomicCounter(counter);
CompletableFuture<Long> result;
if (delta != null) {
if (getFirst) {
result = atomicCounter.getAndAdd(delta);
} else {
result = atomicCounter.addAndGet(delta);
}
} else {
if (getFirst) {
result = atomicCounter.getAndIncrement();
} else {
result = atomicCounter.incrementAndGet();
}
}
try {
print("%s was updated to %d", counter, result.get(3, TimeUnit.SECONDS));
} catch (InterruptedException e) {
return;
} catch (ExecutionException | TimeoutException e) {
print("Error executing command");
log.error("Error executing command counter-test-increment", e);
}
}
use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class SetTestGetCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
set = storageService.<String>setBuilder().withName(setName).withSerializer(serializer).build().asDistributedSet();
// Print the set size
if (size) {
print("There are %d items in set %s:", set.size(), setName);
} else {
print("Items in set %s:", setName);
}
// Print the set
if (set.isEmpty()) {
print("[]");
} else {
for (String e : set.toArray(new String[set.size()])) {
if (output.isEmpty()) {
output += e;
} else {
output += ", " + e;
}
}
print("[%s]", output);
}
// Check if given values are in the set
if (values == null) {
return;
} else if (values.length == 1) {
// contains
if (set.contains(values[0])) {
print("Set %s contains the value %s", setName, values[0]);
} else {
print("Set %s did not contain the value %s", setName, values[0]);
}
} else if (values.length > 1) {
// containsAll
if (set.containsAll(Arrays.asList(values))) {
print("Set %s contains the the subset %s", setName, Arrays.asList(values));
} else {
print("Set %s did not contain the the subset %s", setName, Arrays.asList(values));
}
}
}
use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class SetTestRemoveCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
set = storageService.<String>setBuilder().withName(setName).withSerializer(serializer).build().asDistributedSet();
if (clear) {
set.clear();
print("Set %s cleared", setName);
return;
}
if (values == null) {
print("Error executing command: No value given");
return;
}
if (retain) {
// Keep only the given values
if (set.retainAll(Arrays.asList(values))) {
print("%s was pruned to contain only elements of set %s", setName, Arrays.asList(values));
} else {
print("%s was not changed by retaining only elements of the set %s", setName, Arrays.asList(values));
}
} else if (values.length == 1) {
// Remove a single element from the set
if (set.remove(values[0])) {
print("[%s] was removed from the set %s", values[0], setName);
} else {
print("[%s] was not in set %s", values[0], setName);
}
} else if (values.length > 1) {
// Remove multiple elements from a set
if (set.removeAll(Arrays.asList(values))) {
print("%s was removed from the set %s", Arrays.asList(values), setName);
} else {
print("No element of %s was in set %s", Arrays.asList(values), setName);
}
}
}
Aggregations