Example usage for org.apache.commons.collections4 MultiValuedMap values

List of usage examples for org.apache.commons.collections4 MultiValuedMap values

Introduction

In this page you can find the example usage for org.apache.commons.collections4 MultiValuedMap values.

Prototype

Collection<V> values();

Source Link

Document

Gets a Collection view of all values contained in this multi-valued map.

Usage

From source file:com.evolveum.midpoint.task.quartzimpl.work.workers.WorkersManager.java

/**
 * Moving workers to correct groups (and renaming them if needed).
 * We assume none of the workers are currently being executed.
 *///from  w ww.j  a v a2 s .com
private MovedClosed moveWorkers(List<Task> currentWorkers, MultiValuedMap<String, WorkerKey> shouldBeWorkers,
        OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
    int moved = 0, closed = 0;
    Iterator<WorkerKey> shouldBeIterator = shouldBeWorkers.values().iterator();
    for (Task worker : new ArrayList<>(currentWorkers)) {
        if (shouldBeIterator.hasNext()) {
            WorkerKey shouldBeNext = shouldBeIterator.next();
            moveWorker(worker, shouldBeNext, result);
            currentWorkers.remove(worker);
            shouldBeIterator.remove();
            moved++;
        } else {
            if (worker.getExecutionStatus() != TaskExecutionStatus.CLOSED) {
                LOGGER.info("Closing superfluous worker task {}", worker);
                taskManager.suspendAndCloseTask(worker, TaskManager.DO_NOT_WAIT, result);
                closed++;
            }
        }
    }
    LOGGER.trace("After moveWorkers (result: {} moved, {} closed):\nCurrent workers: {}\nShould be workers: {}",
            moved, closed, currentWorkers, shouldBeWorkers);
    return new MovedClosed(moved, closed);
}

From source file:com.evolveum.midpoint.task.quartzimpl.work.workers.WorkersManager.java

/**
 * Finally, create remaining workers./* w w  w.  ja  v a2  s  .  com*/
 */
private int createWorkers(Task coordinatorTask, MultiValuedMap<String, WorkerKey> keysToCreate,
        Map<WorkerKey, WorkerTasksPerNodeConfigurationType> perNodeConfigurationMap, OperationResult result)
        throws SchemaException, ObjectAlreadyExistsException {

    TaskExecutionStatusType workerExecutionStatus;
    if (coordinatorTask.getExecutionStatus() == null) {
        throw new IllegalStateException("Null executionStatus of " + coordinatorTask);
    }
    switch (coordinatorTask.getExecutionStatus()) {
    case WAITING:
        workerExecutionStatus = TaskExecutionStatusType.RUNNABLE;
        break;
    case SUSPENDED:
        workerExecutionStatus = TaskExecutionStatusType.SUSPENDED;
        break;
    case CLOSED:
        workerExecutionStatus = TaskExecutionStatusType.CLOSED;
        break; // not very useful
    case RUNNABLE:
        workerExecutionStatus = TaskExecutionStatusType.SUSPENDED;
        break;
    default:
        throw new IllegalStateException("Unsupported executionStatus of " + coordinatorTask + ": "
                + coordinatorTask.getExecutionStatus());
    }

    int count = 0;
    TaskType coordinatorTaskBean = coordinatorTask.getTaskType();
    TaskWorkManagementType wsCfg = coordinatorTask.getWorkManagement();
    WorkersManagementType workersCfg = wsCfg.getWorkers();

    for (WorkerKey keyToCreate : keysToCreate.values()) {
        TaskType worker = new TaskType(prismContext);
        worker.setName(PolyStringType.fromOrig(keyToCreate.name));
        if (keyToCreate.group != null) {
            worker.beginExecutionConstraints().group(keyToCreate.group).end();
        }
        worker.setHandlerUri(workersCfg.getHandlerUri());

        applyDeltas(worker, workersCfg.getOtherDeltas());
        applyDeltas(worker, perNodeConfigurationMap.get(keyToCreate).getOtherDeltas());

        worker.setExecutionStatus(workerExecutionStatus);
        worker.setOwnerRef(CloneUtil.clone(coordinatorTaskBean.getOwnerRef()));
        worker.setCategory(coordinatorTask.getCategory());
        worker.setObjectRef(CloneUtil.clone(coordinatorTaskBean.getObjectRef()));
        worker.setRecurrence(TaskRecurrenceType.SINGLE);
        worker.setParent(coordinatorTask.getTaskIdentifier());
        worker.beginWorkManagement().taskKind(TaskKindType.WORKER);
        PrismContainer<Containerable> coordinatorExtension = coordinatorTaskBean.asPrismObject()
                .findContainer(TaskType.F_EXTENSION);
        if (coordinatorTaskBean.getExtension() != null) {
            worker.asPrismObject().add(coordinatorExtension.clone());
        }
        LOGGER.info("Creating worker task on {}: {}", keyToCreate.group, keyToCreate.name);
        taskManager.addTask(worker.asPrismObject(), result);
        count++;
    }
    return count;
}