With the release of Java 8, not only the lambdas, stream and all those other goodies are added to the JVM, there is also something that is called Nashorn.
And that is why I find Nashorn interesting. It allows you easily to call some Java method you have written or which are defined in some library.
You can write something like
var LinkedList = Java.type("java.util.LinkedList");
var list = new LinkedList;
print(list instanceof LinkedList);
You can even mix calls, like a Java method as the JavaScrip callback function.
Of course, not every node.js module can be run by avatar.js and the JVM. If it makes use of some V8 engine specific features, it will not run of course since they are not available on Nashorn.
But the site lists quite some of the most important modules which are tested and run smoothly. They guess that up to 95% of the modules work.
Another addition is that with avatar-js, you can use the full power of your machine. node.js event loop runs in a single thread. But with avatar.js you can easily spawn other threads and do some work over there.
For example when you have a task which may take a while and for which you don’t need the result in the current request.
And you can even have multiple threads, each of them running the event loop and they are connected with an event bus to communicate between each other.
There used to be also a project avatar. It was an extension on top of avatar.js which had some kind of view layer and access points to Java EE technologies like JPA and JMS.
So there would be a strong integration with the Java EE stack and it should be deployed on Java EE Servers.
But at JavaOne 2014, they announced that they have abandoned this path.
Based on some JSON schema dialect, you can define the mapping between the properties and the database fields. You can even define some relations like foreign keys.
Why interesting ?
So maybe you ask yourself, why I find this interesting and place this text on the statelessprime blog?
But if you want to split up a project, you put services, data access and model in one project. And controller (like JAX-RS controllers) and view technology (if any) in another project.
And by using for example the BeanManagerProvider from DeltaSpike, it should theoretically be possible to call into the Java EE components.
BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();
For now, it is maybe a wild idea, but I’m willing to give it a try. In any case, the results will be posted here some day.