Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

33

Share

Download to read offline

Reactive programming using rx java & akka actors - pdx-scala - june 2014

Download to read offline

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Reactive programming using rx java & akka actors - pdx-scala - june 2014

  1. 1. Reactive Programming using RxJava & Akka Actors Thomas Lockney (@tlockney) PDXScala June 14, 2014
  2. 2. What is reactive programming?
  3. 3. Reactive programming is… ● A programming paradigm ● About data-flow ● Not really anything new
  4. 4. Reactive programming is... ● Event-driven ● Scalable ● Resilient ● Responsive (the definition via the manifesto, anyway)
  5. 5. Reorganizing our thoughts a bit... ● Think in terms of discrete events ● Code in terms of behaviors ○ reacting to events ● The system state changes over time based on the flow of events
  6. 6. A brief digression... Amdahl’s law (paraphrased): The maximum increase in speed of a program is limited by the sequential portions of the code.
  7. 7. A brief digression... Amdahl’s law (paraphrased): If you have a program that runs for 4 hours, but 1 hour of runtime is necessarily serial, your program will have at most a 4x speedup with parallelization.
  8. 8. Amdahl’s law
  9. 9. The thing about Amdahl’s law This is death by a thousand cuts. Every line of code is subject to this rule!
  10. 10. Some principles... ● Keep your data immutable ● Share nothing ● Blocking is bad!
  11. 11. Another brief digression...
  12. 12. ● Immutable data structures ● Referential transparency ● First-class functions … this gives you ... Once you have:
  13. 13. Functional Programming
  14. 14. well... Functional Programming in the small
  15. 15. RxJava “a library for composing asynchronous and event-based programs using observable sequences for the Java VM”
  16. 16. My translation: RxJava A library for composing behaviors applied to event streams. note: when I say behaviors, think referentially-transparent functions.
  17. 17. Marble Diagrams
  18. 18. Observable ● The “dual” of Iterable ● Or an Observer for sequences ● Somewhat similar to a Future ○ but, again, supports sequences
  19. 19. Observable Basic mechanics ● onNext() ● onError() ● onComplete()
  20. 20. Functional Composition ● map() ● flatMap() ● filter()
  21. 21. map()
  22. 22. flatMap()
  23. 23. filter()
  24. 24. Creating Observables ● Observable.from(...), Observable.just(...), Observable.range(...), etc. ● Implement the Observable interface ○ explicit calls to onNext(), onError(), onComplete()
  25. 25. Observer & Subscriber Observer ● interface for handling Observables onNext, onError, onComplete Subscriber ● represents a subscription to an observable
  26. 26. Demo time!
  27. 27. RxJava is Reactive ● event-based (data-flows) ● scalable* ● resilient* (???) ● responsive* (???) * - requires some additional work on your end ??? - the story here is not entirely clear or potentially even available in current releases
  28. 28. Akka & the actor model
  29. 29. Actors (the Actor model) Defined by three traits ● a behavior (reacts to events) ● an state model ● send/receive (immutable) messages
  30. 30. Actors ● messages are processed sequentially ● multiple actors can be working at the same time ● actors are not threads ● an actor can block (but should avoid it) ● no shared state
  31. 31. Actor System ● actors interact ● actors exist together within an actor system ● the system defines the outermost bounds
  32. 32. Akka ● Scala-based actor model toolkit ● Provides a lot of extras ● We won’t be talking about those
  33. 33. Akka ● Supervisors ○ provide exception handling ○ “let it crash” ○ orthogonal to actor behavior ● Location transparency ○ abstracts the idea of “where” an actor lives
  34. 34. Akka ● Mailboxes ● Routing ○ e.g., round-robin, smallest mailbox, etc. ● Dispatching ○ essentially how to allocate thread resources
  35. 35. Demo time!
  36. 36. Akka is Reactive ● event-based ● resilient/fault-tolerant ● easily scalable* ● responsive* * - requires some additional work on your end
  37. 37. Reactive Streams
  38. 38. Reactive Streams … I wish I had time … ;~)
  • changhwanhan1

    Nov. 18, 2016
  • LoveHasija

    Sep. 28, 2016
  • vovche

    Nov. 17, 2015
  • DanielZhelyazkov1

    Nov. 2, 2015
  • alexeyshockov

    Oct. 15, 2015
  • ismailover

    Sep. 28, 2015
  • tvhung

    Sep. 24, 2015
  • BerndGtz

    Sep. 14, 2015
  • ClumsyShark

    Aug. 9, 2015
  • ziyasal

    Jul. 13, 2015
  • DejanIli

    Jun. 26, 2015
  • AlbertSerrallRos

    May. 12, 2015
  • yth1

    May. 10, 2015
  • mohanmca

    May. 5, 2015
  • kwangyongkim

    Apr. 21, 2015
  • MartinWeidner

    Apr. 6, 2015
  • unizune

    Feb. 22, 2015
  • joobn

    Feb. 13, 2015
  • tantrieuf31

    Feb. 5, 2015
  • bunkertor

    Feb. 5, 2015

Views

Total views

8,958

On Slideshare

0

From embeds

0

Number of embeds

280

Actions

Downloads

183

Shares

0

Comments

0

Likes

33

×