1
votes

Now I'm reading the document of Play Java. And I don't understand these sentences which explain what is the exactly apply(RequestHeader header) in Play.

The return type of the method is an Accumulator. An accumulator is a thin layer around an Akka Streams Sink. An accumulator asynchronously accumulates streams of elements into a result, it can be run by passing in an Akka Streams Source, this will return a CompletionStage that will be redeemed when the accumulator is complete. It is essentially the same thing as a Sink>, in fact it is nothing more than a wrapper around this type, but the big difference is that Accumulator provides convenient methods such as map, mapFuture, recover etc. for working with the result as if it were a promise, where Sink requires all such operations to be wrapped in a mapMaterializedValue call.

Do this mean that Accumulator can be the argument of Akka Streams Source? But when I have checked, I couldn't find the method one of whose parameters is equal to Accumulator. And I couldn't do CompletionStage in it. What in the world they want to tell?

1

1 Answers

0
votes

Do this mean that Accumulator can be the argument of Akka Streams Source?

No, it just mean that Accumulator is created over a Akka Streams source. It runs and accumulate on that Akka stream source and returns a Future object i.e. CompletionStage once the accumulation is complete.

Accumulator need Akka Stream source, not vice versa.