I'm confortable with Scala, but for reasons outside my control, Java was mandated for this project. We're using streams for another part of the application, in a somewhat simpler scenario. This conversation has been very helpful. The gems are these, I think:
a) Treat the refresh flow as normal program operation, not an exception b) Encapsulate the refresh flow so that all of the timeout, scheduling, retrying, and so on happens away from the components that actually use the access tokens c) Agents are useful as a mechanism for coordinating the distribution of the refreshed tokens d) Have the agents contain promises to prevent client code from using expired tokens I've now implemented the auto-refresh part without using streams. It's not as elegant as yours, but it does the job. Thanks heaps, Lance. You've been an enormous help. On 13 August 2015 at 02:06, Lance Arlaus <lance.arl...@gmail.com> wrote: > Oh, jeez. Yeah, that's entirely hideous. > > You know there's a cure for this disease. It's called Scala. However, side > effects may include crawling compiles, awkward builds, and speaking > optionally in futures :-) > > Seriously, if I'd known you were approaching this from Java, I'd advised > against using Streams. > You need the right language features and a good DSL to make this stuff > accessible and maintainable (which the Akka guys have done a great job with > so far, IMHO). > > You're right on about the Future contained in an Agent. That's the key > interface between the two components (access and request). Like any > software, as long as you get the interfaces right, the implementation > should be swappable. > > Good luck! > > > On Tuesday, August 11, 2015 at 10:32:57 AM UTC-4, David Pinn wrote: > >> Lance, I've been translating your autoRefresh method into Java. >> >> Kill. Me. Now. >> >> You wrote this: >> >> val auto = Sink( >> Flow[(RefreshToken, Promise[AccessToken])], >> Merge[(RefreshToken, Promise[AccessToken])](2), >> request, >> Unzip[RefreshToken, Promise[AccessToken]], >> Zip[Future[RefreshResponse], Promise[AccessToken]], >> Broadcast[(RefreshResponse, Promise[AccessToken])](3) >> )((mat, _, _, _, _, _) => mat) { >> implicit b => (initial, merge, request, unzip, zip, bcast) => >> ... >> } >> >> >> >> ... which translates into Java 7 like this: >> >> Sink<Pair<RefreshToken, F.Promise<OAuth2Info>>, BoxedUnit> auto = >> Sink.factory().create6( >> Flow.<Pair<RefreshToken, F.Promise<OAuth2Info>>>create(), >> Merge.<Pair<RefreshToken, F.Promise<OAuth2Info>>>create(2), >> request, >> Unzip.<RefreshToken, F.Promise<OAuth2Info>>create(), >> Zip.<Future<RefreshResponse>, F.Promise<OAuth2Info>>create(), >> Broadcast.<Pair<RefreshResponse, F.Promise<OAuth2Info>>>create(3 >> ), >> new Function6<BoxedUnit, BoxedUnit, BoxedUnit, BoxedUnit, >> BoxedUnit, BoxedUnit, BoxedUnit>() { >> @Override >> public BoxedUnit apply(BoxedUnit m1, BoxedUnit m2, BoxedUnit >> m3, BoxedUnit m4, BoxedUnit m5, BoxedUnit m6) { >> return m1; >> } >> }, >> new Function7<FlowGraph.Builder<BoxedUnit>, >> FlowShape<Pair<RefreshToken, F.Promise<OAuth2Info>>, Pair< >> RefreshToken, F.Promise<OAuth2Info>>>, >> UniformFanInShape<Pair<RefreshToken, F.Promise<OAuth2Info>>, >> Pair<RefreshToken, F.Promise<OAuth2Info>>>, >> FlowShape<RefreshToken, F.Promise<RefreshResponse>>, >> FanOutShape2<Pair<RefreshToken, F.Promise<OAuth2Info>>, >> RefreshToken, F.Promise<OAuth2Info>>, >> FanInShape2<Future<RefreshResponse>, >> >> ... > > -- > >>>>>>>>>> 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 a topic in the > Google Groups "Akka User List" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/akka-user/qh1ktrdbjbE/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > akka-user+unsubscr...@googlegroups.com. > To post to this group, send email to akka-user@googlegroups.com. > Visit this group at http://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. > -- >>>>>>>>>> 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+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.