Package org.pipecraft.pipes.terminal
Class AsyncMapWriterPipe<T,K,V>
- java.lang.Object
-
- org.pipecraft.pipes.terminal.TerminalPipe
-
- org.pipecraft.pipes.terminal.AsyncMapWriterPipe<T,K,V>
-
- Type Parameters:
T- The type of items in the input pipeK- 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 givenMap. Thread safety: It's the responsibility of the caller to use a thread safe map object!- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description AsyncMapWriterPipe(AsyncPipe<T> inputPipe, FailableFunction<T,K,ValidationPipeException> keyExtractor, FailableFunction<T,V,ValidationPipeException> valueExtractor)Constructor Collects items into aConcurrentHashMapcreated internally.AsyncMapWriterPipe(AsyncPipe<T> inputPipe, FailableFunction<T,K,ValidationPipeException> keyExtractor, FailableFunction<T,V,ValidationPipeException> valueExtractor, Map<K,V> outputMap)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Map<K,V>getItems()voidstart()Performs pre-processing prior to item flow throw the pipe.-
Methods inherited from class org.pipecraft.pipes.terminal.TerminalPipe
getProgress
-
-
-
-
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 consumekeyExtractor- 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 itemoutputMap- The map to populate
-
AsyncMapWriterPipe
public AsyncMapWriterPipe(AsyncPipe<T> inputPipe, FailableFunction<T,K,ValidationPipeException> keyExtractor, FailableFunction<T,V,ValidationPipeException> valueExtractor)
Constructor Collects items into aConcurrentHashMapcreated internally.- Parameters:
inputPipe- The input pipe to consumekeyExtractor- 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
-
close
public void close() throws IOException- Throws:
IOException
-
start
public void start() throws PipeException, InterruptedExceptionDescription copied from interface:BasePipePerforms 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.
-
-