Class AsyncMapWriterPipe<T,​K,​V>

  • Type Parameters:
    T - The type of items in the input pipe
    K - The key type in the output map. Must be suitable as a key map (i.e. equal items must have the same hashcode).
    V - The value type in the output map
    All Implemented Interfaces:
    Closeable, AutoCloseable, BasePipe

    public class AsyncMapWriterPipe<T,​K,​V>
    extends TerminalPipe
    A terminal async pipe writing all contents from an input pipe into a given Map. Thread safety: It's the responsibility of the caller to use a thread safe map object!
    Author:
    Eyal Schneider
    • Constructor Detail

      • AsyncMapWriterPipe

        public AsyncMapWriterPipe​(AsyncPipe<T> inputPipe,
                                  FailableFunction<T,​K,​ValidationPipeException> keyExtractor,
                                  FailableFunction<T,​V,​ValidationPipeException> valueExtractor,
                                  Map<K,​V> outputMap)
        Constructor
        Parameters:
        inputPipe - The input pipe to consume
        keyExtractor - The logic for extracting the map key from an input item. In case that two different items produce the same key, an arbitrary item will take precedence and override the results on the other.
        valueExtractor - The logic for extracting the map value from an input item
        outputMap - The map to populate
      • AsyncMapWriterPipe

        public AsyncMapWriterPipe​(AsyncPipe<T> inputPipe,
                                  FailableFunction<T,​K,​ValidationPipeException> keyExtractor,
                                  FailableFunction<T,​V,​ValidationPipeException> valueExtractor)
        Constructor Collects items into a ConcurrentHashMap created internally.
        Parameters:
        inputPipe - The input pipe to consume
        keyExtractor - The logic for extracting the map key from an input item. In case that two different items produce the same key, an arbitrary item will take precedence and override the results on the other.
        valueExtractor - The logic for extracting the map value from an input item
    • Method Detail

      • start

        public void start()
                   throws PipeException,
                          InterruptedException
        Description copied from interface: BasePipe
        Performs pre-processing prior to item flow throw the pipe. Implementations must call the same method for all their input pipes before accessing their items. This is typically done here.
        Throws:
        PipeException - In case of pipe errors in this pipe or somewhere up-stream.
        InterruptedException - In case that the operation has been interrupted by another thread.
      • getItems

        public Map<K,​V> getItems()
        Returns:
        The output map