Search in sources :

Example 1 with Task

use of org.onosproject.store.service.Task in project onos by opennetworkinglab.

the class WorkQueueTestCommand method doExecute.

@Override
protected void doExecute() {
    StorageService storageService = get(StorageService.class);
    Serializer serializer = Serializer.using(KryoNamespaces.BASIC);
    queue = storageService.getWorkQueue(name, serializer);
    if ("add".equals(operation)) {
        if (value1 == null) {
            print("Usage: add <value1>");
        } else {
            get(queue.addOne(value1));
            print("Done");
        }
    } else if ("addMultiple".equals(operation)) {
        if (value1 == null || value2 == null) {
            print("Usage: addMultiple <value1> <value2>");
        } else {
            get(queue.addMultiple(Arrays.asList(value1, value2)));
            print("Done");
        }
    } else if ("takeAndComplete".equals(operation)) {
        int maxItems = value1 != null ? Integer.parseInt(value1) : 1;
        Collection<Task<String>> tasks = get(queue.take(maxItems));
        tasks.forEach(task -> get(queue.complete(task.taskId())));
        print("Done");
    } else if ("totalPending".equals(operation)) {
        WorkQueueStats stats = get(queue.stats());
        print("%d", stats.totalPending());
    } else if ("totalInProgress".equals(operation)) {
        WorkQueueStats stats = get(queue.stats());
        print("%d", stats.totalInProgress());
    } else if ("totalCompleted".equals(operation)) {
        WorkQueueStats stats = get(queue.stats());
        print("%d", stats.totalCompleted());
    } else if ("destroy".equals(operation)) {
        get(queue.destroy());
    } else {
        print("Invalid operation name. Valid operations names are:" + " [add, addMultiple takeAndComplete, totalPending, totalInProgress, totalCompleted, destroy]");
    }
}
Also used : Task(org.onosproject.store.service.Task) WorkQueueStats(org.onosproject.store.service.WorkQueueStats) StorageService(org.onosproject.store.service.StorageService) Serializer(org.onosproject.store.service.Serializer)

Aggregations

Serializer (org.onosproject.store.service.Serializer)1 StorageService (org.onosproject.store.service.StorageService)1 Task (org.onosproject.store.service.Task)1 WorkQueueStats (org.onosproject.store.service.WorkQueueStats)1