Class SolutionSynchronizer

  • All Implemented Interfaces:
    Runnable

    public class SolutionSynchronizer
    extends RunnableBase
    This class manages the periodical reading (polling strategy) of current tasks from the jBPM runtime and depending on the "action" INIT_SOLVER_EXECUTOR / SYNCHRONIZE_SOLUTION determines if the solver executor must be restarted with a fully recovered solution or instead the tasks updated information is used for calculating the required changes for the proper solution update. If any changes are calculated they are notified to the resultConsumer. This class implements proper retries in case of connection issues with the target jBPM runtime, etc.
    • Method Detail

      • initSolverExecutor

        public void initSolverExecutor()
      • synchronizeSolution

        public void synchronizeSolution​(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution solution,
                                        LocalDateTime fromLastModificationDate)
        Starts the synchronization of the solution from the indicated last modification date.
        Parameters:
        solution - a non null solution instance to synchronize.
        fromLastModificationDate - filtering parameter for reading the modifications.
      • synchronizeSolution

        public void synchronizeSolution​(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution solution,
                                        LocalDateTime fromLastModificationDate,
                                        Duration unchangedPeriodTimeout)
        Starts the synchronization of the solution from the indicated last modification date.
        Parameters:
        solution - a non null solution instance to synchronize.
        fromLastModificationDate - filtering parameter for reading the modifications.
        unchangedPeriodTimeout - a non null period of time for returning from the synchronization if no changes were produced during that period. A negative or zero period is ignored.
      • destroy

        public void destroy()
        Starts the synchronizing finalization, that will be produced as soon as possible. It's a non thread-safe method, but only first invocation has effect.
        Overrides:
        destroy in class RunnableBase
      • run

        public void run()
      • isUsersSyncTime

        protected boolean isUsersSyncTime()
      • calculateNextUsersSyncTime

        protected long calculateNextUsersSyncTime()
      • isUnchangedPeriodTime

        protected boolean isUnchangedPeriodTime()
      • calculateNextUnchangedPeriodTime

        protected long calculateNextUnchangedPeriodTime​(Duration unchangedPeriodTimeoutShift)
      • getSystemTime

        protected long getSystemTime()
      • buildChanges

        protected List<org.optaplanner.core.impl.solver.ProblemFactChange<org.kie.server.services.taskassigning.core.model.TaskAssigningSolution>> buildChanges​(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution solution,
                                                                                                                                                                org.apache.commons.lang3.tuple.Pair<List<org.kie.server.api.model.taskassigning.TaskData>,​LocalDateTime> tasksUpdateResult,
                                                                                                                                                                org.apache.commons.lang3.tuple.Pair<Boolean,​List<org.kie.server.services.taskassigning.user.system.api.User>> usersUpdateResult)
      • buildChanges

        protected List<org.optaplanner.core.impl.solver.ProblemFactChange<org.kie.server.services.taskassigning.core.model.TaskAssigningSolution>> buildChanges​(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution solution,
                                                                                                                                                                List<org.kie.server.api.model.taskassigning.TaskData> updatedTaskDataList)
      • buildChanges

        protected List<org.optaplanner.core.impl.solver.ProblemFactChange<org.kie.server.services.taskassigning.core.model.TaskAssigningSolution>> buildChanges​(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution solution,
                                                                                                                                                                List<org.kie.server.api.model.taskassigning.TaskData> updatedTaskDataList,
                                                                                                                                                                List<org.kie.server.services.taskassigning.user.system.api.User> updatedUserList)
      • buildSolution

        protected org.kie.server.services.taskassigning.core.model.TaskAssigningSolution buildSolution​(List<org.kie.server.api.model.taskassigning.TaskData> taskDataList,
                                                                                                       List<org.kie.server.services.taskassigning.user.system.api.User> externalUsers)