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
ConstructorsConstructorDescriptionLazyFanInPriorityQueue(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 TypeMethodDescriptionAcquires a permit for the queue.voidinit(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>>>> voidReleases the permit associated with a queue operation.booleansend(int streamIndex, CompletableFutures.SQLResult<RowBatch> batchOrEx, QueuePermit permit) Sends an item to the specified stream index.voidTerminates the queue, disabling send.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
Acquires a permit for the queue. -
releasePermit
public void releasePermit()Description copied from interface:QueuePermitReleases 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:
releasePermitin interfaceQueuePermit
-
nextStage
public CompletionStage<com.ibm.asyncutil.util.Either<com.ibm.asyncutil.iteration.AsyncIterator.End,CompletableFutures.SQLResult<List<Row>>>> nextStage()- Specified by:
nextStagein interfacecom.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.
-