Class SolverExecutor

  • All Implemented Interfaces:
    Runnable

    public class SolverExecutor
    extends RunnableBase
    This class is intended to manage the solver life-cycle in a multi-threaded environment.
    • Field Summary

      • Fields inherited from class org.kie.server.services.taskassigning.planning.RunnableBase

        status
    • Constructor Summary

      Constructors 
      Constructor Description
      SolverExecutor​(SolverDef solverDef, org.kie.server.services.api.KieServerRegistry registry, org.optaplanner.core.api.solver.event.SolverEventListener<org.kie.server.services.taskassigning.core.model.TaskAssigningSolution> eventListener)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addProblemFactChanges​(List<org.optaplanner.core.impl.solver.ProblemFactChange<org.kie.server.services.taskassigning.core.model.TaskAssigningSolution>> changes)
      Thread-safe method that adds a list of ProblemFactChanges to the current solver.
      protected org.optaplanner.core.api.solver.Solver<org.kie.server.services.taskassigning.core.model.TaskAssigningSolution> buildSolver​(SolverDef solverDef, org.kie.server.services.api.KieServerRegistry registry)  
      void destroy()
      This method programmes the subsequent finalization of the solver (if it was started) that will be produced as soon as possible by invoking the solver.terminateEarly() method.
      boolean isStarted()  
      boolean isStopped()  
      void run()  
      void start​(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution solution)
      This method is invoked from a different thread for starting the solver and must be invoked only one time.
      void stop()
      Stops the solver.
    • Constructor Detail

      • SolverExecutor

        public SolverExecutor​(SolverDef solverDef,
                              org.kie.server.services.api.KieServerRegistry registry,
                              org.optaplanner.core.api.solver.event.SolverEventListener<org.kie.server.services.taskassigning.core.model.TaskAssigningSolution> eventListener)
    • Method Detail

      • start

        public void start​(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution solution)
        This method is invoked from a different thread for starting the solver and must be invoked only one time. If the solver was already started an exception is thrown so callers of this method should call the isStarted() method to verify. This method is not thread-safe so it's expected that any synchronization required between the isStarted(), start() and stop() methods is performed by the callers. However it's normally not expected that multiple threads might try to start the same solver runner instance.
        Parameters:
        solution - a valid solution for starting the solver with.
      • buildSolver

        protected org.optaplanner.core.api.solver.Solver<org.kie.server.services.taskassigning.core.model.TaskAssigningSolution> buildSolver​(SolverDef solverDef,
                                                                                                                                             org.kie.server.services.api.KieServerRegistry registry)
      • isStarted

        public boolean isStarted()
        Returns:
        true if the solver has been started, false in any other case.
      • isStopped

        public boolean isStopped()
      • stop

        public void stop()
        Stops the solver.
      • destroy

        public void destroy()
        This method programmes the subsequent finalization of the solver (if it was started) that will be produced as soon as possible by invoking the solver.terminateEarly() method. If the solver wasn't started it just finalizes current thread.
        Overrides:
        destroy in class RunnableBase
      • addProblemFactChanges

        public void addProblemFactChanges​(List<org.optaplanner.core.impl.solver.ProblemFactChange<org.kie.server.services.taskassigning.core.model.TaskAssigningSolution>> changes)
        Thread-safe method that adds a list of ProblemFactChanges to the current solver. If the solver has not been started an exception is thrown, so it's expected that callers of this method should call isStarted() method to verify.
        Parameters:
        changes - a list of problem fact changes to program in current solver.
      • run

        public void run()