Package com.ocient.util

# Class Iterators.LazyFanInPriorityQueue

java.lang.Object
com.ocient.util.Iterators.LazyFanInPriorityQueue

All Implemented Interfaces:
  `com.ibm.asyncutil.iteration.AsyncIterator<CompletableFutures.SQLResult<List<Row>>>`, `com.ibm.asyncutil.util.AsyncCloseable`, `QueuePermit`

Enclosing class:
  Iterators

public static final class Iterators.LazyFanInPriorityQueue extends Object implements com.ibm.asyncutil.iteration.AsyncIterator<CompletableFutures.SQLResult<List<Row>>>, QueuePermit
A priority queue for sequenced, asynchronous processing of `CompletableFutures.SQLResult<RowBatch>` elements.

## Nested Class Summary

## Nested classes/interfaces inherited from interface com.ibm.asyncutil.iteration.AsyncIterator

`com.ibm.asyncutil.iteration.AsyncIterator.End`

## Constructor Summary

Constructors
Constructor
Description
`LazyFanInPriorityQueue(int width, int capacity, SortMode sortMode, String queryId, Consumer<CompletableFutures.SQLResult<RowBatch>> onAdd, BiConsumer<CompletableFutures.SQLResult<RowBatch>,QueuePermit> onRemove, Executor executor)`
Constructs a LazyFanInPriorityQueue with the specified parameters.

## Method Summary

Modifier and Type
Method
Description
`CompletionStage<QueuePermit>`
`acquirePermit()`
Acquires a permit for the queue.
`void`
`init(int streamIndex)`
Initializes the queue at the specified index.
`CompletionStage<com.ibm.asyncutil.util.Either<com.ibm.asyncutil.iteration.AsyncIterator.End,CompletableFutures.SQLResult<List<Row>>>>`
`nextStage()`
`void`
`releasePermit()`
Releases the permit associated with a queue operation.
`boolean`
`send(int streamIndex, CompletableFutures.SQLResult<RowBatch> batchOrEx, QueuePermit permit)`
Sends an item to the specified stream index.
`void`
`terminate()`
Terminates the queue, disabling send.

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

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

### Methods inherited from interface com.ibm.asyncutil.iteration.AsyncIterator

`batch, batch, close, collect, collect, consume, exceptionally, filter, filterApply, filterCompose, find, fold, fold, forEach, fuse, take, takeWhile, thenApply, thenApplyAsync, thenApplyAsync, thenCompose, thenComposeAhead, thenComposeAsync, thenComposeAsync, thenFlatten, thenFlattenAhead`

## Constructor Details

### LazyFanInPriorityQueue

public LazyFanInPriorityQueue(int width, int capacity, SortMode sortMode, String queryId, Consumer<CompletableFutures.SQLResult<RowBatch>> onAdd, BiConsumer<CompletableFutures.SQLResult<RowBatch>,QueuePermit> onRemove, Executor executor)
Constructs a LazyFanInPriorityQueue with the specified parameters.

Parameters:
  `width` - The width of the queue.
  `capacity` - The capacity of the queue.
  `sortMode` - When SortMode.UNSORTED, only the the first stream is used.
  `queryId` - The query ID associated with the queue.
  `onAdd` - Callback to invoke when an element is added.
  `onRemove` - Callback to invoke when an element is removed.
  `executor` - Executor to offload prefetch tasks from the consuming thread.

## Method Details

### init

public void init(int streamIndex)
Initializes the queue at the specified index.

### acquirePermit

public CompletionStage<QueuePermit> acquirePermit()
Acquires a permit for the queue.

### releasePermit

public void releasePermit()
Description copied from interface: `QueuePermit`
Releases the permit associated with a queue operation.

Implementations of this method should release the permit, allowing other operations to proceed. The exact behavior of releasing a permit may vary depending on the specific queue or synchronization mechanism in use.

Specified by:
  `releasePermit` in interface `QueuePermit`

### nextStage

public CompletionStage<com.ibm.asyncutil.util.Either<com.ibm.asyncutil.iteration.AsyncIterator.End,CompletableFutures.SQLResult<List<Row>>>> nextStage()

Specified by:
  `nextStage` in interface `com.ibm.asyncutil.iteration.AsyncIterator<CompletableFutures.SQLResult<List<Row>>>`

### send

public boolean send(int streamIndex, CompletableFutures.SQLResult<RowBatch> batchOrEx, QueuePermit permit)
Sends an item to the specified stream index.

Parameters:
  `streamIndex` - The index of the queue to which the item is to be sent.
  `batchOrEx` - The SQL result batch or exception to enqueue.
  `permit` - The queue permit associated with the item.
Returns:
  True if the item was successfully added to the queue; false if the queue is full.

### terminate

public void terminate()
Terminates the queue, disabling send.