Class TiledProcess.Task

java.lang.Object
org.apache.sis.internal.processing.image.TiledProcess.Task
All Implemented Interfaces:
Callable<R>
Direct Known Subclasses:
Parallelized.Tile
Enclosing class:
TiledProcess<R>

protected abstract class TiledProcess.Task extends Object implements Callable<R>
A task to be executed in TiledProcess for a sub-region of the image to process.

This class implements Callable for TiledProcess convenience. This implementation details should be ignored; it may change in any future version.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int
    Index of this Task instance in the TiledProcess.tasks array.
    protected final PixelIterator
    Iterator over the pixels in the sub-region explored by this task.
    Synchronization lock during the merge phase.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a new sub-task to be executed in a sub-area of a two-dimensional plane.
  • Method Summary

    Modifier and Type
    Method
    Description
    final R
    Executes this sub-task, then tries to merge it with all neighbor sub-tasks that are completed.
    protected abstract void
    Executes this sub-task.
    protected abstract void
    merge(TiledProcess<R>.Task neighbor)
    Merges the result of given sub-task into this one.
    protected abstract R
    Returns the computation result.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • index

      private final int index
      Index of this Task instance in the TiledProcess.tasks array.
    • iterator

      protected final PixelIterator iterator
      Iterator over the pixels in the sub-region explored by this task.
    • merging

      private ReentrantLock merging
      Synchronization lock during the merge phase. Created only before merge attempts. This reference shall be considered final after initialization.
  • Constructor Details

    • Task

      protected Task()
      Creates a new sub-task to be executed in a sub-area of a two-dimensional plane.
  • Method Details

    • execute

      protected abstract void execute() throws Exception
      Executes this sub-task. This method is invoked by TiledProcess.execute() in a background thread. Implementation should store the result in this Task instance for future merge.
      Throws:
      Exception - if an error occurred during sub-task execution.
    • merge

      protected abstract void merge(TiledProcess<R>.Task neighbor) throws Exception
      Merges the result of given sub-task into this one. The given Task will be a neighbor tile (located on top, left, right or bottom of this tile) on a best-effort basis (no guarantee). After this method call, all data should be in this and the neighbor sub-task will be discarded.
      Parameters:
      neighbor - the other sub-task to merge with this one.
      Throws:
      Exception - if an error occurred during merge operation.
    • result

      protected abstract R result() throws Exception
      Returns the computation result. This method is invoked by TiledProcess only once, on the last Task instance after all other instances have been merged on this.
      Returns:
      the computation result.
      Throws:
      Exception - if final result cannot be computed.
    • call

      public final R call() throws Exception
      Executes this sub-task, then tries to merge it with all neighbor sub-tasks that are completed. This method is public as an implementation side-effect and should not be invoked directly; it will typically be invoked by Executor instead.
      Specified by:
      call in interface Callable<R>
      Returns:
      value computed by this sub-task, or null if this is not the last task.
      Throws:
      Exception - if an error occurred during sub-task execution or merge operation.
      See Also: