Hi

Thanks Victor, you're right!

For the record I did try this before writing the post above, but it 
wouldn't work. I must have had some other type error at the same time that 
confused me. Because now it worked fine!

/Magnus

Den söndag 12 juli 2015 kl. 15:39:10 UTC+2 skrev √:
>
>
>
> On Sun, Jul 12, 2015 at 1:18 PM, Magnus Andersson <
> [email protected] <javascript:>> wrote:
>
>> 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!
>>
>>
> Use `addToken.outlet` (as per signature below)
>
> final case class FlowShape[-I, +O](inlet: Inlet[I], outlet: Outlet[O]) 
> extends Shape {
>   override val inlets: immutable.Seq[Inlet[_]] = List(inlet)
>   override val outlets: immutable.Seq[Outlet[_]] = List(outlet)
>
>   override def deepCopy(): FlowShape[I, O] = FlowShape(inlet.carbonCopy(), 
> outlet.carbonCopy())
>   override def copyFromPorts(inlets: immutable.Seq[Inlet[_]], outlets: 
> immutable.Seq[Outlet[_]]): Shape = {
>     require(inlets.size == 1, s"proposed inlets [${inlets.mkString(", ")}] do 
> not fit FlowShape")
>     require(outlets.size == 1, s"proposed outlets [${outlets.mkString(", ")}] 
> do not fit FlowShape")
>     FlowShape(inlets.head, outlets.head)
>   }
> }
>
>
>  
>
>> /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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Cheers,
> √
>  

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