In the age of cloud computing and highly demanding systems, some new approaches for application architectures such as the event-driven model have been proposed and successfully implemented with Node.js. With the Nashorn JavaScript engine, it is possible to run JavaScript applications directly in the JVM, enabling access to the latest Node.js frameworks while taking advantage of the Java platform’s scalability, manageability, tools, and extensive collection of Java libraries and middleware. This session demonstrates how to use Nashorn to create highly scalable JavaScript applications leveraging the full power of the JVM by using the projects Avatar and Node.js with Avatar.js and Vert.x, highlighting their key benefits, issues, and challenges.
3. Agenda
● Why JS in the server
● Why the JVM
● Nashorn ecosystem
● Vert.x and Avatar/Avatar.js
● Q&A
4. Why JS in the server
● Asynchronous by nature
● Native JSON support
● Language reuse
● Easier developer transition
5. Why the JVM
● Multilanguage
● APM Tools
● Access to the Java ecosystem
○ Domain models already implemented
○ Java EE
○ Core and third parties Java libraries
21. Vert.x
● http://vertx.io/
● Based on Netty
● Sponsored by Red Hat
● Winner of JAX Innovation Awards 2014
@timfox: Writing Highly Concurrent Polyglot Applications with Vert.x
[CON7902] Thursday, Oct 2, 11:30 AM
24. Vert.x
● Key benefits
○ Easy deployment
■ CLI, API, mods, runtime deps resolution
○ Good build tools support (fat jar, auto-redeploy)
○ Native Cluster & HA with Hazelcast
○ Tons of extensions available
25. Vert.x
● Challenges
○ Updated documentation
○ Verticle monitoring
○ Limited transactions support
○ Doesn’t have distributed maps yet (2.x)
○ Nashorn debugging support (PR to be merged)
26. Vert.x
● Vert.x 3 highlights
○ JDK 8+ with Nashorn & Lambda
○ No more module system*
○ Clustered shared data
○ Event bus proxies & codecs
○ Ext stack (MongoDB, SockJS, Route, Rx)
27. Demo
● Real-time notification service using
websockets over nashorn integrating with
a legacy Java EE app
28. Avatar.js
● https://avatar-js.java.net
● Oracle sponsored
● Focus on bringing the node programming
model, APIs and module ecosystem to the
Java platform
30. Avatar
● https://avatar.java.net
● Oracle sponsored
● Focus on Thin Server Architecture
○ Supports REST, WebSocket and Server-Sent
Events
● Built on Avatar.js
35. Avatar
● Deploying an application on Glassfish 4
○ asadmin deploy ~/projects/<app-folder-name>
● Running the application
○ http://localhost:8080/<app-folder-name>
36. Avatar/Avatar.js
● Key benefits
○ Avatar Services use an Actor-like concurrency
model
○ NPM modules support
○ Strong Java EE integration
○ Debugging
37. Avatar/Avatar.js
● Challenges
○ Weak community involvement
○ Low activity and no stable release
○ Glassfish / Weblogic only
○ Model Store API supports only Oracle NoSQL for
schemaless database
38. Benchmark
● Some simple and naive scenarios
○ Posting and querying from database
○ Returning a simple JSON response
○ String concatenation
○ Fibonacci calculation