Thanks for the follow up -- the idea you posted is related, but not quite
it.
I wrote a self-contained working example below. What I do in this example
is manually materialize a graph, and wrap it as a future, making it usable
by mapAsync.
*Ideal: to define an entire graph such that the materialized subgraphs in
lineRewriter are instantiated and managed by akka itself.*
Can the code below be converted to do such a thing? (Scala responses also
great, but this happens to be java.)
b
---
// materialize entire subgraph as an async func
public static CompletionStage<String> lineRewriter(Materializer mat,
String line) {
return Source
.from(Arrays.asList(line.split(" "))) // unroll
.via(Flow.fromFunction(String::toUpperCase)) // per-item
processing
.runReduce((acc, w) -> acc + " " + w, mat); // rollup
}
public static void main(String[] args) {
final String batchesStr = "a word or two\nseparated by
newlines\nmakes for a simple\nstreaming batch test.";
final Source<String, NotUsed> batches =
Source.from(Arrays.asList(batchesStr.split("\n")));
final Sink<String, CompletionStage<Done>> printResp =
Sink.foreach(System.out::println);
batches.mapAsync(1, line -> lineRewriter(materializer,
line)).toMat(printResp, Keep.right())
.run(materializer)
.thenApply(d -> { system.terminate(); return d; })
.exceptionally(t -> { system.terminate(); return
Done.getInstance(); });
}
On Wednesday, May 10, 2017 at 1:53:43 PM UTC+2, Julian Howarth wrote:
>
> I may have misunderstood what you're trying to do but I think you can
> probably use expand for this. In builder pseudocode, something like:
>
> Flow ~> Unzip ~> <the processing you need producing n items> ~> Zip
> ~> Flow.expand(Iterator.continually(_)) ~>
>
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.