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

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

Introduction

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

Prototype

int size();

Source Link

Document

Gets the total size of the map.

Usage

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

public void reconcileWorkers(String coordinatorTaskOid, WorkersReconciliationOptions options,
        OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
    Task coordinatorTask = taskManager.getTask(coordinatorTaskOid, result);
    if (coordinatorTask.getKind() != TaskKindType.COORDINATOR) {
        throw new IllegalArgumentException("Task is not a coordinator task: " + coordinatorTask);
    }/*from w w  w.j av a  2  s. c o m*/
    List<Task> currentWorkers = new ArrayList<>(coordinatorTask.listSubtasks(true, result));
    Map<WorkerKey, WorkerTasksPerNodeConfigurationType> perNodeConfigurationMap = new HashMap<>();
    MultiValuedMap<String, WorkerKey> shouldBeWorkers = createWorkerKeys(coordinatorTask,
            perNodeConfigurationMap, result);

    int startingWorkersCount = currentWorkers.size();
    int startingShouldBeWorkersCount = shouldBeWorkers.size();

    currentWorkers.sort(Comparator.comparing(t -> {
        if (t.getExecutionStatus() == TaskExecutionStatus.RUNNABLE) {
            if (t.getNodeAsObserved() != null) {
                return 0;
            } else if (t.getNode() != null) {
                return 1;
            } else {
                return 2;
            }
        } else if (t.getExecutionStatus() == TaskExecutionStatus.SUSPENDED) {
            return 3;
        } else if (t.getExecutionStatus() == TaskExecutionStatus.CLOSED) {
            return 4;
        } else {
            return 5;
        }
    }));

    LOGGER.trace("Before reconciliation:\nCurrent workers: {}\nShould be workers: {}", currentWorkers,
            shouldBeWorkers);

    int matched = matchWorkers(currentWorkers, shouldBeWorkers);
    int renamed = renameWorkers(currentWorkers, shouldBeWorkers, result);
    int closedExecuting = closeExecutingWorkers(currentWorkers, result);
    MovedClosed movedClosed = moveWorkers(currentWorkers, shouldBeWorkers, result);
    int created = createWorkers(coordinatorTask, shouldBeWorkers, perNodeConfigurationMap, result);

    TaskWorkStateType workState = coordinatorTask.getWorkState();
    Integer closedBecauseDone = null;
    if (isCloseWorkersOnWorkDone(options) && workState != null
            && Boolean.TRUE.equals(workState.isAllWorkComplete())) {
        closedBecauseDone = closeAllWorkers(coordinatorTask, result);
    }
    result.recordStatus(OperationResultStatus.SUCCESS,
            "Worker reconciliation finished. " + "Original workers: " + startingWorkersCount + ", should be: "
                    + startingShouldBeWorkersCount + ", matched: " + matched + ", renamed: " + renamed
                    + ", closed because executing: " + closedExecuting + ", moved: " + movedClosed.moved
                    + ", closed because superfluous: " + movedClosed.closed + ", created: " + created
                    + " worker task(s)."
                    + (closedBecauseDone != null && closedBecauseDone > 0
                            ? " Closed " + closedBecauseDone + " workers because the work is done."
                            : ""));
}