Netflix Brings Reactive Extensions to Java
Netflix has created and open sourced a Java implementation of MS Open Tech’s Reactive Extensions. But to say RxJava is just for Java would be misleading, as it has been designed to be used from other JVM languages as well. “The first languages supported (beyond Java itself) are Groovy, Clojure, Scala and JRuby.”
Netflix created RxJava to simplify server-side concurrency. Their goal is to allow the client to invoke a single "heavy" client request that is executed in parallel on the server. Ben Christensen and Jafar Husain explain,
Server-side concurrency is needed to effectively reduce network chattiness. Without concurrent execution on the server, a single "heavy" client request might not be much better than many "light" requests because each network request from a device naturally executes in parallel with other network requests. If the server-side execution of a collapsed "heavy" request does not achieve a similar level of parallel execution it may be slower than the multiple "light" requests even accounting for saved network latency.
According to Ben and Jafar, the functional reactive is superior to the futures and callbacks because “Functional reactive offers efficient execution and composition by providing a collection of operators capable of filtering, selecting, transforming, combining and composing Observable's”.
By making the service layer API return an Observable<T> for all methods, developers are isolated from the implementation of those methods. The methods may be invoked asynchronously today, but return synchronously tomorrow. The service method is also free to choose between blocking and non-blocking I/O, the former being used when resources are constrained.
RxJava supports “Java 5 (to include Android support) and higher with an eventual goal to target a build for Java 8 with its lambda support.” Like the original Rx, Netflix’s RxJava is offered under the Apache License. You can get RxJava from github.
Anatole Tresch Mar 03, 2015