Is it possible with Java8 stream API to create interface like Message pullNext()
plumbed on top of a delimited input stream with the logical steps as below?
- Delimited tokens are read from the character input stream
- Tokens fed to parallel unmarshaller (one token -> one Message)
- Messages are reordered back to retain the original incoming order
- Messages are pullable with aforementioned
pullNext()
Somewhat a disruptor with unmarshal stage served by concurrent pool. Similar to this, maybe (implementation of stash
on top of InputStream is the one to sort out):
Iterable<String> stash = Iterables.cycle("one", "two", "three");
Iterator<String> sink = StreamSupport.stream(stash.spliterator(), true).
.parallel().map((x)->x+"-unmarshalled").iterator();
while (sink.hasNext()) process(sink.next()); // do something with decoded message