Hi

I have to do a class cast to ge able to get a typed outlet from a flow that 
I used in a FlowGraph. 

   1. I'm wondering if I'm using the API wrong below, can I get the outlet 
   in a different way?
   2. Other suggestions for improvement apart from the single line is 
   welcome, perhaps my whole approach is off?

Code background: I'm forking off a call to a cache service, which in turn 
is an actor that periodically fetches a fresh token from Gcloud and caches 
it for the duration of the token validity. If I got a token returned then 
enrich the HttpRequest with an Authorization header.

val addAuthenticationToken:Flow[HttpRequest, Option[HttpRequest]] = Flow() 
{ implicit b ⇒
  import FlowGraph.Implicits._

  val bcast = b.add( Broadcast[HttpRequest]( 2 ) )
  val zip = b.add( Zip[Option[Token], HttpRequest] )
  val fetchToken:FlowShape[HttpRequest, Option[Token]] = b.add( 
fetchTokenService )
  val addToken:FlowShape[(Option[Token], HttpRequest)] = b.add( 
mapTokenRequest )
  
  bcast ~> fetchToken ~> zip.in0
  bcast ~> zip.in1
  zip.out ~> addToken
  
  // THIS CLASS CAST IS BUGGING ME. AM I USING THE API WRONG HERE?
  val output = 
addToken.outlets.head.asInstanceOf[Outlet[Option[HttpRequest]]]
  ( bcast.in, output )
}

This is the reason the class cast is necessary, below shows what the source 
code for FlowShape in Akka looks like this:

final case class FlowShape[-I, +O](inlet: Inlet[I], outlet: Outlet[O]) 
extends Shape {
  override val inlets: immutable.Seq[Inlet[_]] = List(inlet)  // <=== NO 
TYPES HERE
  override val outlets: immutable.Seq[Outlet[_]] = List(outlet) // <=== NO 
TYPES HERE

  ...
}


Suggestions appreciated, thanks!

/Magnus

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