How can I convert a listener pattern into a stream with akka streams?

85 views
Skip to first unread message

Mark Hammons

unread,
Aug 28, 2016, 5:26:34 PM8/28/16
to akka...@googlegroups.com

I am writing a scheduler for mesos, and I'd like to construct it completely from streams instead of the listener functions it currently uses. How would I create a source and emit items when the listening hooks are called?

 

Thanks
--

Mark Hammons - +33 06 03 69 56 56

Research Engineer @ BioEmergences

Lab Phone: 01 69 82 34 19

signature.asc

Tal Pressman

unread,
Aug 29, 2016, 2:33:31 AM8/29/16
to Akka User List
Hi,

You could use an ActorPublisher (Source.actorPublisher) and send it messages from the listener. Just remember to handle backpressure - what do you do if the listener is called but the stream isn't ready to accept messages yet?

Tal

Mark Hammons

unread,
Aug 29, 2016, 8:51:18 AM8/29/16
to Akka User List
Hmm, Ok. As for backpressure, with these there should be none because only the latest values emitted by the listener are useful. So I guess I would set them to have a buffer of size 1 and to drop the oldest elements in the buffer for that effect right?

Endre Varga

unread,
Aug 29, 2016, 8:57:44 AM8/29/16
to akka...@googlegroups.com
I am not sure a simple listener pattern warrants a full Akka Stream to be involved. Streams starts to shine when you need backpressure, but if you don't need any (because events are rare, or there is no way to meaningfully backpressure) then it might be just too heavyweight and lead to frustrations. You can just use plain actors for the simple cases. Of course I don't know what is the context of your problem so streams might be a good idea, I just warn against unconditional use of them.

-Endre

--
>>>>>>>>>> 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 akka-user+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages