Hi,
Playing around with the receive pipeline pattern
<http://doc.akka.io/docs/akka/2.4.2/contrib/receive-pipeline.html> I put
together the following example to do some sort of user credentials
validation composition with an actor.
Problem is that only with the synchronous blocking semantics I managed to
get the code compiling and running. With the other two alternatives for
asynchronous nonblocking composition I get compilation error (about not
having the proper response type por the pipeline).
So my questions are: Am I missing something here? Does the receive pipeline
pattern only play well with blocking synchronous compositions? Is there a
way to have non-blocking asynchronous compositions with pipelines?
/**
* Pipeline pattern for client validation, intercepts Query messages between
actors to authorize requests.
*/
trait ClientValidationPipeline {
this: ReceivePipeline =>
def clientService: ActorRef
pipelineInner {
case query @ Query(ctx: QueryContext, body: QueryBody) =>
implicit val timeout = Timeout(200 milliseconds)
*/** synchronous *await impl */
val clientValidationFuture = clientService ?
CheckClient(ctx.clientName, ctx.clientPasswd)
val clientValidation = Await.result(clientValidationFuture,
timeout.duration)
clientValidation match {
case validClient: ValidClient =>
body.principal = Some(validClient.client)
Inner(query)
case invalidClient: InvalidClient =>
sender() ! invalidClient
HandledCompletely
}
/** a*synchronous *callback impl */
(clientService ? CheckClient(ctx.clientName,
ctx.clientPasswd)).onComplete {
case Success(validClient: ValidClient) =>
body.principal = Some(validClient.client)
Inner(query)
case Success(invalidClient: InvalidClient) =>
sender() ! invalidClient
HandledCompletely
case Failure(status) =>
sender() ! status
HandledCompletely
}
/** a*synchronous *for comprehension impl */
val clientValidationFuture = clientService ?
CheckClient(ctx.clientName, ctx.clientPasswd)
for {
clientValidation <- clientValidationFuture
} yield {
clientValidation match {
case validClient: ValidClient =>
body.principal = Some(validClient.client)
Inner(query)
case invalidClient: InvalidClient =>
sender() ! invalidClient
HandledCompletely
}
}
case x =>
Inner(x)
}
}
Thanks,
Javier
--
>>>>>>>>>> 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.