Interface AutoConsumer<T>

All Superinterfaces:
AutoCloseable, AutoFunctional, Consumer<T>
All Known Subinterfaces:
ScoredDualConsumer<T>, ToFileWriter<T>
All Known Implementing Classes:
DataWriter, ManagedConsumer, MappedConsumer, QueuedConsumer, ShardedConsumer, ShardedConsumer.GeneralShardedConsumer, ShardedConsumer.PowerOf2ShardedConsumer, TextLineWriter
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface AutoConsumer<T> extends AutoCloseable, Consumer<T>, AutoFunctional
Utilities for AutoCloseable Consumer:s
  • Field Details

  • Method Details

    • managed

      static <T> AutoConsumer<T> managed(String name, Consumer<T> consumer)
      Will create a JMX bean, with the given name, that keeps track of the consumer's throughput.
    • managed

      static <T> AutoConsumer<T> managed(Throughput manager, Consumer<T> consumer)
      If you want that throughput manager to be registered as a JMX bean, that's up to you.
    • mapped

      static <S, T> AutoConsumer<S> mapped(Function<S,T> mapper, Consumer<T> consumer)
      Map/transform and then consume
    • queued

      static <T> AutoConsumer<T> queued(ExecutorService executor, BlockingQueue<T> queue, Consumer<T>... consumers)
      Put on the queue, and then the consumers work off that queue. There will be 1 thread (executor task) per consumer.
    • sharded

      static <T> AutoConsumer<T> sharded(ToIntFunction<T> distributor, Consumer<T>... consumers)
      Distribute to 1 of the consumers
    • accept

      default void accept(T item)
      Specified by:
      accept in interface Consumer<T>
      See Also:
    • close

      default void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • write

      void write(T item)
      Write the item to the consumer.
      Parameters:
      item - The item to be written
    • writeBatch

      default void writeBatch(Iterable<? extends T> batch)
      Write the batch (collection of items) to the consumer.
      Parameters:
      batch - The batch to be written