I have a usecase, where I have a source of data, let's say: every second, a new string is coming from that data source.
I want to create a pipeline, where if a new string arrives, it's pushed through that pipeline for processing.
I'd guess the Java 8 introduced Stream API could do exactly that, since it has convenient functions for processing data of an arbitrary collection, however I'd like to skip the part where I collect my data to a separate collection and dispatch the arriving data straight to the Stream I just created.
Is there any way to do that?
Okay, so the answer to this particular case has become a bit different.
While the answer of Tomasz Linkowski seemed like a really nice solution, the main problem with it was the fact that my function is more sequential then BlockingQueue
s would suggest, which was detrimental for readability.
So I came up with Stream.Builder
, which is actually just what I need and nothing more.