Access to the state of statefulMapConcat outside of Akka Stream

Viewed 51

I have a stream that creates a state for some meta information. The state contains exactly what I need but how I can access the state after the stream is done (see statefulMapConcat.

source.via(someBusiness()).statefulMapConcat(elem -> {
   // state
   Set<Elem> state = new HashSet();
   elem -> {
       // change state
       state.add(...);
       return Collections.singletonList(elem);
   }
}

I'm aware that I can expose the state and use it as global accessible variable but then I get a race condition in terms on concurrency. A concurrent hashmap would solve that issue but I hope there is a solution without locking.

0 Answers
Related