> 26 maj 2015 kl. 16:02 skrev Sam Halliday <[email protected]>:
> 
> To maybe try and formalise this a little bit more, and abstract away from 
> WebSockets (that will only muddy the water).
> 
> Lets say we have an Actor already that looks like this
> 
> sealed trait Incoming
> sealed trait Outgoing
> class SimpleActor(upstream: ActorRef) extends Actor {
>   def receive = {
>     case in: Incoming =>
>        // work, including some upstream ! outgoing
>     case Ack =>
>        // ack for the last message upstream
>     case other =>
>        // work, including some upstream ! outgoing
>   }
> }
> 
> How do I wrap that as a Flow[Incoming, Outgoing, Unit] ?

Short answer: by converting it to a PushPullStage (see the docs 
<http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-RC3/scala/stream-customize.html>;
 and here are the implementations 
<https://github.com/akka/akka/blob/release-2.3-dev/akka-stream/src/main/scala/akka/stream/impl/fusing/Ops.scala>
 of the common combinators)

Long answer: the flow control protocol described by Reactive Streams 
<http://www.reactive-streams.org/> is a lot more involved than your simplistic 
Ack protocol, there are failure conditions and corner cases to be considered to 
make it work reliably. Implementing that protocol yourself is a non-trivial 
task, we do not consider Publisher/Subscriber to be end-user API for that 
reason. Please trust me when I report that we spent 1.5 years together with 
some really bright engineers hammering out the details and trying to find the 
minimal specification that works, so the reason for the complexity is not that 
we complicated things, it lies within the subject matter itself.

Regards,

Roland

> 
> 
> On Tuesday, 26 May 2015 14:09:45 UTC+1, Sam Halliday wrote:
> Re: asyncyMap. I don't think that is going to work, there is no implied 
> single response to each query (which I gather is what you're suggesting)? And 
> I need some way of receiving new messages from upstream.
> 
> The existing Actor is both a sink (i.e. it consumes messages from upstream, 
> not necessarily responding to each one) and a source (i.e. it can send an 
> effectively infinite number of messages). It is using backpressure, but only 
> using its own `Ack` message.
> 
> For some context, I'm retrofitting some code that is using this WebSockets 
> layer around wandoulabs, e.g. 
> https://github.com/smootoo/simple-spray-websockets/blob/master/src/test/scala/org/suecarter/websocket/WebSocketSpec.scala#L150
>  
> <https://github.com/smootoo/simple-spray-websockets/blob/master/src/test/scala/org/suecarter/websocket/WebSocketSpec.scala#L150>
> 
> But the newly released akka-io layer expects a Flow.
> 
> The `Ack` is being received when messages were sent directly to the I/O 
> layer. Presumably, the backpressure is implemented differently now... 
> although I am not sure how yet. That's the second problem once I can actually 
> get everything hooked up.
> 
> 
> On Tuesday, 26 May 2015 13:57:43 UTC+1, √ wrote:
> Not knowing what your actor is trying to do, what about Flow.mapAsync + ask?
> 
> -- 
> Cheers,
> √
> 
> On 26 May 2015 14:54, "Sam Halliday" <[email protected] <>> wrote:
> Hi all,
> 
> I need to interface an Actor with an API that requires a Flow.
> 
> The actor can receive a sealed trait family of inputs and will only send (a 
> different) sealed family of outputs to upstream, so I suspect that will help 
> matters.
> 
> Looking in FlowOps, it looks like I can create a Flow from a partial 
> function, but there isn't anything that would just simply take an ActorRef.
> 
> Am I missing something trivial to just upgrade an ActoRef to a Flow? 
> (Obviously there is a bunch of extra messages the actor will have to handle, 
> such as backpressure messages etc... but assume that's all taken care of)
> 
> Best regards,
> Sam
> 
> -- 
> >>>>>>>>>> Read the docs: http://akka.io/docs/ <http://akka.io/docs/>
> >>>>>>>>>> Check the FAQ: 
> >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html 
> >>>>>>>>>> <http://doc.akka.io/docs/akka/current/additional/faq.html>
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user 
> >>>>>>>>>> <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 
> <http://groups.google.com/group/akka-user>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> 
> -- 
> >>>>>>>>>> Read the docs: http://akka.io/docs/ <http://akka.io/docs/>
> >>>>>>>>>> Check the FAQ: 
> >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html 
> >>>>>>>>>> <http://doc.akka.io/docs/akka/current/additional/faq.html>
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user 
> >>>>>>>>>> <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] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/akka-user 
> <http://groups.google.com/group/akka-user>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe <http://typesafe.com/> – Reactive apps on the JVM.
twitter: @rolandkuhn
 <http://twitter.com/#!/rolandkuhn>

-- 
>>>>>>>>>>      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.

Reply via email to