Hi,
I'm using akka http with Java DSL and I'm trying to handle a get request
with an actor and map my actor's response to the HTTP response as follows:
private Route getTasksRoute(){
return
path("tasks").route(pathEndOrSingleSlash().route(get(this.handleWith(
(ctx) -> ctx.completeWith(handleGetTask(ctx))
))));
}
private Future<RouteResult> handleGetTask(RequestContext ctx){
return Patterns.ask(actorSystem.actorFor("myActor"), buildMessage(),
1000)
.map(o -> ctx.completeAs(Jackson.json(), o), ctx.executionContext());
}
This code does not compile in Java 8 because the API enforces to use scala
futures
Error:(74, 17) java: method map in interface scala.concurrent.Future<T>
cannot be applied to given types;
required:
scala.Function1<java.lang.Object,S>,scala.concurrent.ExecutionContext
found: (o)->ctx.c[...]), o),scala.concurrent.ExecutionContext
reason: cannot infer type-variable(s) S
(argument mismatch; scala.Function1 is not a functional interface
multiple non-overriding abstract methods found in interface
scala.Function1)
I could not find any relevant code example illustrating this use case in
java.
Can you suggest a code pattern to illustrate how the completeWith method is
intended to be used in Java 8 in conjonction with actors' ask pattern ?
Thanks for your help.
Benoit
--
>>>>>>>>>> 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 http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.