Oct 30, 2018

Project Avatar – A JavaScript services layer on the JVM

Project Avatar provides a JavaScript services layer zeroed in on supporting REST, WebSockets and Server-Sent Events, and a rich client side framework that assumes very minor JavaScript knowledge. The services side is focused on building data services using JavaScript, while the optional client side is entirely focused on supporting HTML5 and TSA (Thin Server Architecture).

Project Avatar tackles both sides of this equation, providing a JavaScript services layer zeroed in on supporting REST, WebSocket and Server-Sent Events and a rich client side framework that assumes very minor JavaScript knowledge1. The client side is entirely focused on supporting HTML5 and TSA, while the services side is focused on building data services using JavaScript.

JavaScript services are not a replacement for Java based implementations; instead, they are an additional choice in which services can be entirely JavaScript or layered to utilize existing Java libraries. Pure Java services also work well with Avatar clients.

Avatar.js brings the node programming model, APIs and module ecosystem to the Java platform. Although written in JavaScript, these applications can take advantage of the Java platform's scalability, manageability, tools, and extensive collection of Java libraries and middleware. After downloading the Avatar.js binaries, developers can then execute their applications. For example, Tim Caswell’s article "Hello Node!" contains basic examples for hello-console.js and hello-http.js that can be used as a basic way for testing Avatar.

Nashorn, The Hidden Weapon of JDK 8 was presented at the Silicon Valley Java User Group meeting in December 2014. The available slides describe the use of Nashorn and Avatar at Netflix and provide additional Nashorn demos.
Avoid rewrites and re-use libraries

One major benefit of running serverside JavaScript applications within the JVM is access to Java libraries. Developers do not have to rewrite major libraries or functionality like SQL or NoSQL drivers, Hadoop clients, encoding libraries, etc. Additional examples are available in a previous post, Nashorn: the rhino in the room, but they are not specific to Node.js.

Niko Köbler has a two-part article about Avatar 2.0 and its Model Store API. By using this model store API, developers can more easily interact with SQL and No-SQL and benefit from many existing optimizations.
  • Part 1 explains the architecture and threading model. 
  • Part 2 covers the technology behind the Model Store API.

Additional ways of running Node.js on the JVM

Avatar is one of several ways to run Node.js applications on the JVM.
RedHat’s Nodyn project runs Node.js applications on the JVM and offers direct integration with the Vert.x framework.
Apigee provides a Trireme and enables developers to embed a NodeEnvironment within their applications , which can then execute NodeScript objects.