Interface Job

All Superinterfaces:
Runnable

public interface Job extends Runnable
A Job is a master concurrency model, which each can hold a finite amount of workers all helping to achieve a TASK.

A job is similar to standard Threads or CompletableFutures, but are more oriented towards SWT or single threaded applications. It also allows for much control over the content being run and updated.

In regards to the Halcyon Music Player, an ImageJob is used to modify images without blocking the SWT and EventQueue. The modified image will be automatically referenced once they are done.

Since:
3.3
Author:
Jack Meng
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    __assign_job_(Runnable default_fail_runner, Runnable original_task)
    This method should not be used externally as it can call for the current job (based on standard implementation) to start a new worker while keeping the old worker running, resulting in the job owning 2 workers which can lead to concurrency issues in which the implementation itself must check for, which in turn causes overhead.
    boolean
    Most likely should provide the main implementation and checks for failCurrentTask() and will return true or false based on the status.
    boolean
    Most likely used by restartLabJob() and setTask(Callable) + setTask(Runnable) to check if the current implementation allows for reference retention of the tasks that have been ran previously in order to quickly pick them up if the implementation calls for such a method.
    void
    If the current job has a task to run, this method will call a "pause" on the task but not quit the job.
    void
    Quit the current job being run.
    void
    Restart the CURRENT task.
    void
    If a retention policy is used, the user could restart the last job; however, an implementation shall not provide a retention policy in which a restart could be called for EVERY last job reference.
    default void
    run()
     
    void
    This method does not gurantee that the job will immediately do any of the following: quit the current task, add this task to the queue, start this task if there are none running, and/or quit the last job and pick up this.
    void
    setTask(Callable<?> task)
    Similar to setTask(Runnable) but the user may wish to use a standard Callable implementation.
  • Method Details

    • quit

      void quit()
      Quit the current job being run. The current job's content and runnable is completely nulled and is not kept.

      HOWEVER: The above retention method is up to the programmer's own intentions.

    • restartLabJob

      void restartLabJob()
      If a retention policy is used, the user could restart the last job; however, an implementation shall not provide a retention policy in which a restart could be called for EVERY last job reference. This retention method may result in severe memory consumptions and poor performance, which a Job is not supposed to be in most cases.
    • failCurrentTask

      void failCurrentTask()
      If the current job has a task to run, this method will call a "pause" on the task but not quit the job. This method is not necessary to be implemented and most likely with internal Java Concurrency might result in the concurrency not pausing and simply being ignored.
    • restartJob

      void restartJob()
      Restart the CURRENT task. The current job reference is dereferenced and cannot be called by restartLabJob to retart the task. This in turn results in less memory being consumed and needed to be stored.
    • setTask

      void setTask(Runnable task)
      This method does not gurantee that the job will immediately do any of the following: quit the current task, add this task to the queue, start this task if there are none running, and/or quit the last job and pick up this.

      This is used mainly to tell the job queue that a new task may be needed to be added but no gurantees shall be made in order to reduce the current task experiencing any overhead.

      Parameters:
      task - An anonymous class or function can be used here to facilitate the quick job insertion.
    • setTask

      void setTask(Callable<?> task)
      Similar to setTask(Runnable) but the user may wish to use a standard Callable implementation.

      Once again, this method makes no gurantees of the following: quiting the current task, adding this task to the queue, start this task if there are none running, and/or quit the current task and readily pick up this task.

      Parameters:
      task - A Callable implementation (wildcard)
    • __current_task_fail

      boolean __current_task_fail()
      Most likely should provide the main implementation and checks for failCurrentTask() and will return true or false based on the status.
      Returns:
      (true | | false) A true is returned if the task was able to be failed and has been failed. A false is returned if the task is unable to be checked, failed, and/or be present
    • __is_retainable

      boolean __is_retainable()
      Most likely used by restartLabJob() and setTask(Callable) + setTask(Runnable) to check if the current implementation allows for reference retention of the tasks that have been ran previously in order to quickly pick them up if the implementation calls for such a method.

      This method must be concrete and provide exact readings on whether the job can do so.

      Returns:
      (true | | false) Whether the job supports retention of task references.
    • __assign_job_

      void __assign_job_(Runnable default_fail_runner, Runnable original_task)
      This method should not be used externally as it can call for the current job (based on standard implementation) to start a new worker while keeping the old worker running, resulting in the job owning 2 workers which can lead to concurrency issues in which the implementation itself must check for, which in turn causes overhead.

      This method is primarily used with setTask(Callable), setTask(Runnable), restartJob(), quit() to force a job from the queue to be picked up. However once again, due to the concurrency model, no such gurantees are made in any way.

      Although no gurantee can be made, one can provide native implementations to allow for much more specific controls over the flow.

      Parameters:
      default_fail_runner - An anonymous that can be called if the task was failed either due to an exception, or a premature end
      original_task - The task to run which is the main task that is asked for
    • run

      default void run()
      Specified by:
      run in interface Runnable