by Ivan St. Ivanov
The last day at JavaOne started as usual with the community keynote. I didn’t go to it, because I wanted to have a rest after the Aerosmith and Macklemore & Ryan Lewis concert last night and also wanted to catch up with my blogs. However, the people that I follow on twitter were kind enough to update me with the most interesting bits of the session. Additionally, there’s already a blog from Ben Evans about it.
Basically Oracle understood their mistake from the opening keynote on Sunday and let Mark Reinhold and Brian Goetz on the stage to do their technical talk that was cut so abruptly a few days ago. Apparently Java 9 was the central topic. Modularity, value types, primitive types in generics, native data and code access, array rework, etc. are the most prominent things that will hopefully come with the next Java release.
The keynote continued with a panel moderated by Mark Reinhold, having Brian Goetz as well as James Gosling (the father of Java), Charles Nutter (the JRuby guy, from RedHat), John Rose (JVM Architect, known for things like invokedynamic and the value types in Java) and Brian Oliver (Oracle’s in memory data grid architect). They answered various questions marked hashed with #j1qa on Twitter (BTW, it was trending in top 10 on the Thursday morning). The most tweeted statement from the conversion was that James Gosling was not sorry for introducing null in the language.
The final part of the keynote was dedicated to the community (at the end, this was the community keynote). The most important news was that like last year all the JavaOne 2014 sessions will be on Parleys.
I don’t know whether there is a reader of this blog that does not know what JBoss Forge is (check out its new cool website). But still: it is a rapid application development enabler tool, built on extensible platform and as of its second version with abstraction over its user input. Yes, as of Forge 2 you can run the tool both on the command line as well as with wizards in your favorite IDE. Actually a Forge generated or managed project doesn’t have any dependency to the tool. It builds all the knowledge from the pom.xml for Maven projects and build.gradle for Gradle projects. The extensibility of Forge is because of its modularity. No, it’s not OSGi, Forge is based on JBoss modules and has quite some machinery based on Maven on top.
Where does Forge help, you would ask? In any areas, I would answer:
- Figure out for you the right dependency that you have to add to a Java (EE) project
- Put the right entry for your JPA provider in the persistence.xml
- Help you declare a bi-directional one-to-many dependency
- Plumb for you the boring CRUD classes
- Prepare a mock UI (a.k.a. a scaffold) out of your domain model
This is done by already existing Forge addons, but you can very easily create one of your own to help you in your daily job activities. If you have a tedious task, where you constantly copy and paste artifacts from one project to another, then you can think of implementing your own addon. It’s built with Maven and you can use dependency injection for the dependencies from the Forge core that your addon might require (CDI or the service loader). Once you have developed your addon Forge gives you a way to test it in the Arquillian way, i.e. in-container without any need to mock anything, and then deploy it on the Forge runtime. You can also develop listeners to observe events before and after Forge command executions.
Be reactive with Java 8
The next logical step after applying functional programming practices to your APIs is to make your modules containing those APIs reactive. Well, this might sound as the next buzzword, but in fact it is not. The reactive programming style was something that was invented long ago, we forgot it and now we found how cool it is.
How does your program become reactive? Well, if it serves requests from external clients and if these requests take longer than expected, the call on the client side should not block on one side and on the other side the server should respond in timely manner that it is processing the request. It is very important to not spawn a separate thread for every request – if the client retries the request again and again, the threads may quickly expire and the memory could be filled up. Using futures is not a solution to that: yes, they seem asynchronous, but at the end you have to wait on their get() method. Callbacks seem a neat solution, but the problem with them is that they cannot be nested.
So, how do you achieve the efficiency of the reactive programming style in Java 8? There are quite a few libraries, but the last session that I happened to visit at JavaOne (by Venkat Subramaniam) focused on one of them: RxJava library from Netflix.
Its API is built around the Observable class. You create an instance of that class on the server side. It receives kind of recipe as a parameter, telling the RxJava library what to do upon an event happening on the server side. This recipe is an implementation of the Observer interface and you can call any of its methods inside the create() method body. Then the client can call one of the subscribe() methods of the received Observable to pass lambdas that will react on a given event happening on the server side. The types of events that the client can react upon are success (the onNext event), error (onError) and completion (onComplete). For each one of them there is a special subscribe overloading method, as well as a method receiving a full blown extension of the Subscribed abstract class.
You can call the unsubscribe method of the Observable on the client side to stop “receiving” updates from the server part. Besides those, Observable class has lots of other methods that make it look like a real [functional] lazy abstraction: skip() and skipWhile() for skipping the first events happening on the server, take() to take some of the events and then stop observing, combine() to combine this with other Observlables, etc.
The RxJava library provides APIs for other languages on the JVM besides Java: Groovy, Scala, Clojure to name a few. I guess that this is a really great new topic as of Java 8, so it deserves much more exploration than these few paragraphs.
Java2Days preparation instead of map, flatmap and reduce
I was really interested to visit another functional talk as well. It would go at another level comparing others that I’ve seen in the recent couple of years. It promised to not only go through the usual stream collectors and reduce methods, not stop at forEach and filter or at the simplest map methods. It would go into other functional terms like flatmap or more complex reduction (foldleft probably?). All in the Java world.
However, this was the only slot when I could meet Reza Rahman from Oracle to discuss what we are going to prepare for the Java2Days conference that we are running in Sofia the week after Devoxx. So I decided to watch that talk on Parleys later and had a beer with Reza during the closing ours at the Duke’s caf?. I can promise you that if everything goes fine, we’ll have a really cool agenda for our Bulgarian conference: hands on labs covering the latest Java SE 8 and Java EE 7 technologies plus tools like Forge and Arquillian, Java SE 9 hacking, talks on Java EE 8, etc. Can’t wait it to happen!