Search in sources :

Example 6 with DataEvent

use of org.kie.kogito.taskassigning.service.event.DataEvent in project kogito-apps by kiegroup.

the class TaskAssigningService method executeSolutionChange.

synchronized void executeSolutionChange(TaskAssigningSolution solution) {
    if (isNotOperative()) {
        LOGGER.warn(SERVICE_INOPERATIVE_MESSAGE, context.getStatus());
        return;
    }
    try {
        LOGGER.debug("process the next generated solution, applyingPlanningExecutionResult: {}", applyingPlanningExecutionResult.get());
        if (LOGGER.isTraceEnabled()) {
            traceSolution(LOGGER, solution);
        }
        clearWaitForImprovedSolutionTimer();
        currentSolution.set(solution);
        List<ProblemFactChange<TaskAssigningSolution>> pendingEventsChanges = null;
        if (applyingPlanningExecutionResult.get()) {
            // solution is the result of applying the pinning changes corresponding to the last executed plan,
            // prioritize events that could have arrived in the middle if any.
            applyingPlanningExecutionResult.set(false);
            List<DataEvent<?>> pendingEvents = pollEvents();
            List<TaskDataEvent> pendingTaskDataEvents = filterNewestTaskEventsInContext(context, pendingEvents);
            UserDataEvent pendingUserDataEvent = filterNewestUserEvent(pendingEvents);
            if (!pendingTaskDataEvents.isEmpty() || pendingUserDataEvent != null) {
                pendingEventsChanges = SolutionChangesBuilder.create().forSolution(solution).withContext(context).withUserServiceConnector(userServiceConnectorDelegate).withProcessors(processorRegistry).fromTasksData(fromTaskDataEvents(pendingTaskDataEvents)).fromUserDataEvent(pendingUserDataEvent).build();
            }
        }
        if (pendingEventsChanges != null && !pendingEventsChanges.isEmpty()) {
            LOGGER.debug("executeSolutionChange - we have pendingEventsChanges: {} to apply", pendingEventsChanges.size());
            cancelScheduledImproveSolutionOnBackgroundTimer();
            solverExecutor.addProblemFactChanges(pendingEventsChanges);
        } else {
            executePlanOrResumeEvents(solution);
        }
    } catch (Exception e) {
        failFast(e);
    }
}
Also used : TaskDataEvent(org.kie.kogito.taskassigning.service.event.TaskDataEvent) TaskDataEvent(org.kie.kogito.taskassigning.service.event.TaskDataEvent) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) SolutionUpdatedOnBackgroundDataEvent(org.kie.kogito.taskassigning.service.event.SolutionUpdatedOnBackgroundDataEvent) DataEvent(org.kie.kogito.taskassigning.service.event.DataEvent) AssignTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) ProblemFactChange(org.optaplanner.core.api.solver.ProblemFactChange) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent)

Aggregations

DataEvent (org.kie.kogito.taskassigning.service.event.DataEvent)6 SolutionUpdatedOnBackgroundDataEvent (org.kie.kogito.taskassigning.service.event.SolutionUpdatedOnBackgroundDataEvent)6 TaskDataEvent (org.kie.kogito.taskassigning.service.event.TaskDataEvent)6 UserDataEvent (org.kie.kogito.taskassigning.service.event.UserDataEvent)6 Test (org.junit.jupiter.api.Test)4 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)2 AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)2 ProblemFactChange (org.optaplanner.core.api.solver.ProblemFactChange)2 Handler (io.vertx.core.Handler)1 AddTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)1 AddUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)1 RemoveTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)1 TaskAssigningServiceContext (org.kie.kogito.taskassigning.service.TaskAssigningServiceContext)1