scala - Adding a graph to a SourceQueue so we can run a endless stream -
i new akka streams library , decided learn example. trying catch keyboard events , pass through endless stream. idea divide stream in 2 separate processing , end them in different sinks.
this short example of event handler have works.
object keylistener extends org.jnativehook.keyboard.nativekeylistener { implicit val system = actorsystem("key-events-streaming-system") implicit val materializer = actormaterializer() val buffersize = 100 //if buffer fills strategy drops oldest elements //upon arrival of new element. val overflowstrategy = akka.stream.overflowstrategy.drophead val queuenativekeyevents = source.queue[nativekeyevent](buffersize, overflowstrategy) .filter(event => event.getrawcode > 0) .to(sink.foreach(println(_))) .run() def nativekeypressed(event: nativekeyevent): unit = { queuenativekeyevents.offer(event) } def nativekeytyped(event: nativekeyevent): unit = { system.out.print("test") } def nativekeyreleased(event: nativekeyevent): unit = { system.out.print("test") } } now understand want setup each key press event gets added source , travels through stream have setup.
how configure kind of source. when "run" graph have created ?
i think going wrong somewhere fundamental understanding of streams.
appreciate !
update : yes above example works fine , stream run everytime new element enters it. challenge dealing want divide filtered stream graph if takes 1 input , divides 3 streams , processes them in different paths down line. think can create graph takes 1 input , split them in different paths , result in different sinks side effecting work required of each path. cannot wrap head around how add graph source queue ?
Comments
Post a Comment