Class InMemoryIndexTaskQueue<T extends IndexTask>

  • All Implemented Interfaces:
    IndexTaskQueue<T>

    @NotThreadSafe
    public class InMemoryIndexTaskQueue<T extends IndexTask>
    extends Object
    implements IndexTaskQueue<T>
    An in memory implementation of the Index Task Queue.
    • Constructor Detail

      • InMemoryIndexTaskQueue

        public InMemoryIndexTaskQueue()
    • Method Detail

      • getSize

        public int getSize()
        Description copied from interface: IndexTaskQueue
        Retrieve the number of elements in the queue.
        Specified by:
        getSize in interface IndexTaskQueue<T extends IndexTask>
        Returns:
        size of the queue.
      • getQueuedEntries

        public List<T> getQueuedEntries​(int limit)
        Description copied from interface: IndexTaskQueue
        Retrieve a list of the N of queued entries.
        Specified by:
        getQueuedEntries in interface IndexTaskQueue<T extends IndexTask>
        Parameters:
        limit - first N entries to retrieve.
        Returns:
        a list of IndexTask instances.
      • flushQueue

        public List<T> flushQueue​(int numberOfEntries)
        Returns ALL entries in the queue.
        Specified by:
        flushQueue in interface IndexTaskQueue<T extends IndexTask>
        Parameters:
        numberOfEntries - the maximum number of entries to return. This should return the n first entries in the queue.
        Returns:
        the list of entries on the queue when it was flushed.
      • flushQueue

        public List<T> flushQueue()
        Description copied from interface: IndexTaskQueue
        Flush the contents of the queue, returning those elements currently queued as the result.

        This method waits until tasks that we added immediately before calling this method are available. See IndexTaskQueue.flushQueue(int) for an alternative.

        Specified by:
        flushQueue in interface IndexTaskQueue<T extends IndexTask>
        Returns:
        the list of entries on the queue when it was flushed.
      • flushAndExecute

        public int flushAndExecute​(Consumer<T> action)
        Description copied from interface: IndexTaskQueue
        Flush the contents of the queue, applying the given action to each flushed entry.

        This method waits until tasks that we added immediately before calling this method are available. See IndexTaskQueue.flushAndExecute(Consumer, int) for an alternative.

        Specified by:
        flushAndExecute in interface IndexTaskQueue<T extends IndexTask>
        Parameters:
        action - action to perform for each entry
        Returns:
        the number of entries that were flushed.
      • flushAndExecute

        public int flushAndExecute​(Consumer<T> action,
                                   int numberOfEntries)
        Description copied from interface: IndexTaskQueue
        Flush the contents of the queue, applying the given action to each flushed entry.

        Tasks that were added immediately before calling this method are not returned. See IndexTaskQueue.flushAndExecute(Consumer) for an alternative.

        Specified by:
        flushAndExecute in interface IndexTaskQueue<T extends IndexTask>
        Parameters:
        action - action to perform for each entry
        numberOfEntries - the maximum number of entries to flush. This should flush the n first entries in the queue.
        Returns:
        the number of entries that were flushed.
      • flushQueueWithActionOnIterableOfTasks

        public int flushQueueWithActionOnIterableOfTasks​(Consumer<Iterable<T>> actionOnIterableOfTasks,
                                                         int numberOfTasks)
        Description copied from interface: IndexTaskQueue
        Flush the contents of the queue, applying the given action to an iterable of tasks.

        IndexTaskQueue.flushQueue(Effect, int) applys an action to an individual task. In contrast, this method applies an action to an iterable of tasks.

        If the specified action throws a RuntimeException, tasks are returned to the queue so that they can be processed again. The exception will be propagated so clients must handle it accordingly.

        Specified by:
        flushQueueWithActionOnIterableOfTasks in interface IndexTaskQueue<T extends IndexTask>
        Parameters:
        actionOnIterableOfTasks - action on iterable of tasks
        numberOfTasks - the maximum number of tasks to retrieve from the queue
        Returns:
        the number of tasks that were flushed to the index.