Nashorn, Node.jar and Java Persistence BOF¶
Node.jar, Akhil Arora¶
Implemented Node’s evented APIs
Using the Grizzly Framework under the hood (GlassFish)
Can run on any Nashorn platform
- Including Java SE Embedded
Node port will always be single-threaded/evented, but Java part can take advantage of threads/multi-core
Only on Java SE 7 and above
Access to BigDecimal/BigInteger on JVM (and others etc. etc.)
Mapping from Node modules to Java APIs used in their implementation (incomplete list)
buffer Grizzly ByteBuffer (nio ByteBuffer) child_process ProcessBuilder dns InetAddress etc. fs nio.File http(s) Grizzly stream Grizzly nio Stream
WIP based on Node v0.8.2
Redirecting to Java APIs where required in _wrap implementation modules
Using the Node.js unit tests to test
Lists of modules which were “Mostly Working”, “Partial”, “TBD”, I only got these ones down:
crypto, cluster, dns, readline, repl, tty, zlib
fs, http, net, os
Running on a Raspberry PI
- java -jar node-0.1.jar fortune.js
- Serving up a
- Serving up a
- Writing a date to the response every second, using Java Date
- Not getting into it vs Mozilla and Google engines, but faster and smaller than Rhino already.
- Can Node modules retrieved via
- Yes, but can’t load modules which require native extensions
- Are there any plans to provide wrap modules for popular modules which have
native deps, like Socket.IO?
- Socket.IO support will be an add-on (i.e. later), wrapping Grizzly implementations.
- Node API is compact and powerful, with smaller code size
- Make use of Java APIs
- Secured with Java security
JPA & Node.jar, Doug Clarke¶
Implementation details and JS code samples of 4 ways to use JPA persistence with Nashorn/Node.jar.
Wrapped JPA, XML + annotated Java¶
- Access Java EE with SSJS
- Node wrapped JPA
- Annotated Java classes and XML config file
- app.js & jpa.js
Wrapped dynamic JPA¶
- Access Java EE with SSJS without Java
- No Java source classes
- Persistence XML
- EclipseLink offers dynamic persistence, spinning up classes at runtime
+----------------------+ +-------+ +-------+ | | | | | | | | | | | | | Node.jar | |Nashorn| |Eclipse| | | | | |Link | | +-------+ +-------+ | | | | | | | | | | | | | | | | | app.js| | jpa.js| | | | | | | | | | | | | | | | | +-------+ +-------+ | | | | | +----------------------+ +-------+ +-------+
JS JPA & JS/JSON Config¶
- Factories required for creation of new objects, still early days on this front.
+----------------------+ +-------+ | | | | | | | | | Node.jar | |Nashorn| | | | | | +-------+ +-------+ | | | | | | | | | | | | | app.js| | jpa.js| | | | | | | | | | | | | +-------+ +-------+ | | | +----------------------+ +-------+
JS Database JPA¶
- Types and mappings from DB
- Types creted based on the schema
- Names mapped to database table names
- Use case for Nashorn/Node could be scripted service chunks leveraging EE capabilities.
- (Paraphrasing) Sample JS code is synchronous, WTF?
- Code put together to demonstrate use, not a JS API
- EntityManager can transparently be made asynchronous to support writing in the standard Node async way.
- (Adam Bien) Can we do annotations?
- Not part of the JS language
- After this question there was a bit of discussion back and forth about ways you could annotate, use cases for using EE components in JS, but it’s clear that it’s possible to use chunks of EE with Node.jar and all the specifics are up for grabs right now.
- It sounds like it’s hard to even get a hold of Node.jar if you work for Oracle, and there are no plans to open source it.
- Which is a pity, because more people who know Node.js and use EE could be of use here. I know I’d like to start playing with it yesterday!