org.eclipse.rdf4j.federated.evaluation.concurrent

## Class ParallelExecutorBase<T>

- java.lang.Object
- - org.eclipse.rdf4j.common.iteration.AbstractCloseableIteration<E,X>
  - - org.eclipse.rdf4j.common.iteration.LookAheadIteration<T,QueryEvaluationException>
    - - org.eclipse.rdf4j.federated.evaluation.concurrent.ParallelExecutorBase<T>

- Type Parameters:
    `T` -
  All Implemented Interfaces:
    AutoCloseable, Runnable, CloseableIteration<T,QueryEvaluationException>, Iteration<T,QueryEvaluationException>, ParallelExecutor<T>
  Direct Known Subclasses:
    JoinExecutorBase, UnionExecutorBase

      public abstract class ParallelExecutorBase<T>
      extends LookAheadIteration<T,QueryEvaluationException>
      implements ParallelExecutor<T>

  Base class for common parallel executors such as `JoinExecutorBase` and `UnionExecutorBase`.
  Author:
    Andreas Schwarte
  See Also:
    `JoinExecutorBase`, `UnionExecutorBase`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Thread` | `evaluationThread`
    `protected long` | `executorId`
    `protected boolean` | `finished`
    `protected static org.slf4j.Logger` | `log`
    `protected static AtomicLong` | `NEXT_EXECUTOR_ID`
    `protected QueryInfo` | `queryInfo`
    `protected CloseableIteration<T,QueryEvaluationException>` | `rightIter`
    `protected FedXQueueCursor<T>` | `rightQueue`
    `protected FederationEvalStrategy` | `strategy`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ParallelExecutorBase(FederationEvalStrategy strategy, QueryInfo queryInfo)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addResult(CloseableIteration<T,QueryEvaluationException> res)` Handle the result appropriately, e.g.
    `protected void` | `checkTimeout()` Checks whether the query execution has run into a timeout.
    `void` | `done()` Inform the controlling instance that some job is done from a different thread.
    `String` | `getDisplayId()`
    `protected String` | `getExecutorType()`
    `protected String` | `getId()`
    `T` | `getNextElement()` Gets the next element.
    `QueryInfo` | `getQueryInfo()` Return the query info of the associated query
    `void` | `handleClose()` Called by `AbstractCloseableIteration.close()` when it is called for the first time.
    `boolean` | `isFinished()` Return true if this executor is finished or aborted
    `protected abstract void` | `performExecution()` Perform the parallel execution.
    `void` | `run()`
    `void` | `toss(Exception e)` Toss some exception to the controlling instance
    `String` | `toString()`

    - ### Methods inherited from class org.eclipse.rdf4j.common.iteration.LookAheadIteration

      `hasNext, next, remove`

    - ### Methods inherited from class org.eclipse.rdf4j.common.iteration.AbstractCloseableIteration

      `close, isClosed`

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

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

    - ### Methods inherited from interface org.eclipse.rdf4j.common.iteration.Iteration

      `stream`

- - ### Field Detail

    - #### log

          protected static final org.slf4j.Logger log

    - #### NEXT_EXECUTOR_ID

          protected static final AtomicLong NEXT_EXECUTOR_ID

    - #### strategy

          protected final FederationEvalStrategy strategy

    - #### executorId

          protected final long executorId

    - #### queryInfo

          protected final QueryInfo queryInfo

    - #### evaluationThread

          protected volatile Thread evaluationThread

    - #### rightQueue

          protected FedXQueueCursor<T> rightQueue

    - #### rightIter

          protected volatile CloseableIteration<T,QueryEvaluationException> rightIter

    - #### finished

          protected volatile boolean finished

  - ### Constructor Detail

    - #### ParallelExecutorBase

          public ParallelExecutorBase(FederationEvalStrategy strategy,
                                      QueryInfo queryInfo)
                               throws QueryEvaluationException

      Throws:
        `QueryEvaluationException`

  - ### Method Detail

    - #### run

          public final void run()

      Specified by:
        `run` in interface `Runnable`

    - #### performExecution

          protected abstract void performExecution()
                                            throws Exception

      Perform the parallel execution. Note that this method must block until the execution is completed.
      Throws:
        `Exception`

    - #### addResult

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

      Description copied from interface: `ParallelExecutor`
      Handle the result appropriately, e.g. add it to the result iteration. Take care for synchronization in a multithreaded environment
      Specified by:
        `addResult` in interface `ParallelExecutor<T>`

    - #### done

          public void done()

      Description copied from interface: `ParallelExecutor`
      Inform the controlling instance that some job is done from a different thread. In most cases this is a no-op.
      Specified by:
        `done` in interface `ParallelExecutor<T>`

    - #### toss

          public void toss(Exception e)

      Description copied from interface: `ParallelExecutor`
      Toss some exception to the controlling instance
      Specified by:
        `toss` in interface `ParallelExecutor<T>`

    - #### getNextElement

          public T getNextElement()
                           throws QueryEvaluationException

      Description copied from class: `LookAheadIteration`
      Gets the next element. Subclasses should implement this method so that it returns the next element.
      Specified by:
        `getNextElement` in class `LookAheadIteration<T,QueryEvaluationException>`
      Returns:
        The next element, or `null` if no more elements are available.
      Throws:
        `QueryEvaluationException`

    - #### checkTimeout

          protected void checkTimeout()
                               throws QueryInterruptedException

      Checks whether the query execution has run into a timeout. If so, a `QueryInterruptedException` is thrown.
      Throws:
        `QueryInterruptedException`

    - #### handleClose

          public void handleClose()
                           throws QueryEvaluationException

      Description copied from class: `AbstractCloseableIteration`
      Called by `AbstractCloseableIteration.close()` when it is called for the first time. This method is only called once on each iteration. By default, this method does nothing.
      Overrides:
        `handleClose` in class `LookAheadIteration<T,QueryEvaluationException>`
      Throws:
        `QueryEvaluationException`

    - #### isFinished

          public boolean isFinished()

      Return true if this executor is finished or aborted
      Specified by:
        `isFinished` in interface `ParallelExecutor<T>`
      Returns:
        whether the executor is finished

    - #### getQueryInfo

          public QueryInfo getQueryInfo()

      Description copied from interface: `ParallelExecutor`
      Return the query info of the associated query
      Specified by:
        `getQueryInfo` in interface `ParallelExecutor<T>`
      Returns:
        the query info

    - #### getId

          protected String getId()

      Returns:
        a unique identifier of this execution

    - #### getDisplayId

          public String getDisplayId()

    - #### getExecutorType

          protected String getExecutorType()

      Returns:
        the executor type, e.g. "Join". Default "Executor"

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

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