org.eclipse.rdf4j.federated.evaluation.concurrent

## Class ControlledWorkerScheduler<T>

- java.lang.Object
- - org.eclipse.rdf4j.federated.evaluation.concurrent.ControlledWorkerScheduler<T>

- All Implemented Interfaces:
    Scheduler<T>, TaskWrapperAware

      public class ControlledWorkerScheduler<T>
      extends Object
      implements Scheduler<T>, TaskWrapperAware

  ControlledWorkerScheduler is a task scheduler that uses a FIFO queue for managing its process. Each instance has a pool with a fixed number of worker threads. Once notified a worker picks the next task from the queue and executes it. The results is then returned to the controlling instance retrieved from the task.
  Author:
    Andreas Schwarte
  See Also:
    `ControlledWorkerUnion`, `ControlledWorkerJoin`, `ControlledWorkerBoundJoin`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `ControlledWorkerScheduler.ControlStatus` Structure to maintain the status for a given control instance.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ControlledWorkerScheduler()` Deprecated. use `ControlledWorkerScheduler(int, String)`. Scheduled to be removed in 4.0
    `ControlledWorkerScheduler(int nWorkers, String name)` Construct a new instance with the specified number of workers and the given name.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `abort()` Abort the execution of running and queued tasks.
    `void` | `done()` Inform the scheduler that a certain task is done.
    `int` | `getNumberOfTasks()`
    `int` | `getTotalNumberOfWorkers()`
    `void` | `handleResult(CloseableIteration<T,QueryEvaluationException> res)` Callback to handle the result.
    `void` | `informFinish()` Inform the scheduler that no more tasks will be scheduled.
    `void` | `informFinish(ParallelExecutor<T> control)` Inform this scheduler that the specified control instance will no longer submit tasks.
    `boolean` | `isRunning()` Determine if the scheduler has unfinished tasks.
    `boolean` | `isRunning(ParallelExecutor<T> control)` Determine if there are still task running or queued for the specified control.
    `void` | `schedule(ParallelTask<T> task)` Schedule the specified parallel task.
    `void` | `scheduleAll(List<ParallelTask<T>> tasks, ParallelExecutor<T> control)` Schedule the given tasks and inform about finish using the same lock, i.e.
    `void` | `setTaskWrapper(TaskWrapper taskWrapper)` Set the `TaskWrapper` to the respective instance
    `void` | `shutdown()`
    `void` | `toss(Exception e)` Toss an exception to the scheduler.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ControlledWorkerScheduler

          @Deprecated
          public ControlledWorkerScheduler()

      Deprecated. use `ControlledWorkerScheduler(int, String)`. Scheduled to be removed in 4.0
      Construct a new instance with 20 workers.

    - #### ControlledWorkerScheduler

          public ControlledWorkerScheduler(int nWorkers,
                                           String name)

      Construct a new instance with the specified number of workers and the given name.
      Parameters:
        `nWorkers` -
        `name` -

  - ### Method Detail

    - #### schedule

          public void schedule(ParallelTask<T> task)

      Schedule the specified parallel task.
      Specified by:
        `schedule` in interface `Scheduler<T>`
      Parameters:
        `task` - the task to schedule

    - #### scheduleAll

          public void scheduleAll(List<ParallelTask<T>> tasks,
                                  ParallelExecutor<T> control)

      Schedule the given tasks and inform about finish using the same lock, i.e. all tasks are scheduled one after the other.
      Parameters:
        `tasks` -
        `control` -

    - #### getTotalNumberOfWorkers

          public int getTotalNumberOfWorkers()

    - #### getNumberOfTasks

          public int getNumberOfTasks()

    - #### abort

          public void abort()

      Description copied from interface: `Scheduler`
      Abort the execution of running and queued tasks.
      Specified by:
        `abort` in interface `Scheduler<T>`

    - #### done

          public void done()

      Description copied from interface: `Scheduler`
      Inform the scheduler that a certain task is done.
      Specified by:
        `done` in interface `Scheduler<T>`

    - #### handleResult

          public void handleResult(CloseableIteration<T,QueryEvaluationException> res)

      Description copied from interface: `Scheduler`
      Callback to handle the result.
      Specified by:
        `handleResult` in interface `Scheduler<T>`

    - #### informFinish

          public void informFinish()

      Description copied from interface: `Scheduler`
      Inform the scheduler that no more tasks will be scheduled.
      Specified by:
        `informFinish` in interface `Scheduler<T>`

    - #### informFinish

          public void informFinish(ParallelExecutor<T> control)

      Inform this scheduler that the specified control instance will no longer submit tasks.
      Parameters:
        `control` -

    - #### isRunning

          public boolean isRunning()

      Description copied from interface: `Scheduler`
      Determine if the scheduler has unfinished tasks.
      Specified by:
        `isRunning` in interface `Scheduler<T>`
      Returns:
        whether the scheduler is running

    - #### isRunning

          public boolean isRunning(ParallelExecutor<T> control)

      Determine if there are still task running or queued for the specified control.
      Parameters:
        `control` -
      Returns:
        true, if there are unfinished tasks, false otherwise

    - #### toss

          public void toss(Exception e)

      Description copied from interface: `Scheduler`
      Toss an exception to the scheduler.
      Specified by:
        `toss` in interface `Scheduler<T>`

    - #### shutdown

          public void shutdown()

      Specified by:
        `shutdown` in interface `Scheduler<T>`

    - #### setTaskWrapper

          public void setTaskWrapper(TaskWrapper taskWrapper)

      Description copied from interface: `TaskWrapperAware`
      Set the `TaskWrapper` to the respective instance
      Specified by:
        `setTaskWrapper` in interface `TaskWrapperAware`

Copyright © 2015-2021 Eclipse Foundation. All Rights Reserved.