SlideShare a Scribd company logo
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Project 
Avatar 
Server-­‐side 
JavaScript 
on 
the 
JVM 
! 
JAX 
London 
-­‐ 
Oct. 
2014 
David 
Delabassee 
(@delabassee) 
Oracle
Safe 
Harbor 
Statement 
The 
following 
is 
intended 
to 
outline 
our 
general 
product 
direction. 
It 
is 
intended 
for 
information 
purposes 
only, 
and 
may 
not 
be 
incorporated 
into 
any 
contract. 
It 
is 
not 
a 
commitment 
to 
deliver 
any 
material, 
code, 
or 
functionality, 
and 
should 
not 
be 
relied 
upon 
in 
making 
purchasing 
decisions. 
The 
development, 
release, 
and 
timing 
of 
any 
features 
or 
functionality 
described 
for 
Oracle’s 
products 
remains 
at 
the 
sole 
discretion 
of 
Oracle. 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
2
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Agenda 
Setting 
the 
Context 
Avatar 
– 
Enterprise 
Node 
on 
the 
JVM 
Demo 
1 
3 
3 
2
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Agenda 
Setting 
the 
Context 
Avatar 
– 
Enterprise 
Node 
on 
the 
JVM 
Demo 
1 
2 
3 
4
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Node.js 
• Server-­‐side 
JavaScript 
based 
on 
Chrome 
v8 
engine 
• Created 
in 
2009, 
Open 
Source 
• Designed 
for 
scalable 
Internet 
applications 
• Melting 
pot 
community 
– Java, 
.NET, 
Browser, 
PHP, 
etc, 
experience 
• Node 
Packaged 
Modules 
– Very 
active, 
with 
+98,000 
modules 
(YMMV) 
5 
Server 
Side 
JavaScript
Node.js 
Programming 
Model 
• Multi-­‐threading 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
is 
hard 
– Thousands 
of 
concurrent 
connections 
– Deal 
with 
deadlocks 
and 
race 
conditions 
• Blocking 
on 
I/O 
is 
bad 
• Event 
Loop 
– Reactive 
Model 
– Non-­‐blocking 
I/O 
calls 
• Application 
code 
executes 
in 
a 
single 
thread 
6 
Event 
Clients Loop 
Non-­‐blocking 
Worker
Node.js 
Programming 
Model 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
7 
var http = require("http");! 
! 
http.createServer( … ).listen(80);
Node.js 
Programming 
Model 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
8 
var http = require("http");! 
! 
http.createServer(function(request, response) {! 
! response.writeHead(200, {"Content-type": "text/plain"});! 
! response.write("Hello World";)! 
! response.end();! 
}).listen(80);
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Nashorn 
! 
• Bundled 
with 
Java 
7 
and 
8 
• ECMAScript 
5.1 
compatibility 
• Performance 
(vs 
Rhino) 
• Java 
Interoperability 
9 
6 
4,5 
3 
1,5 
0 
crypto earley-­‐boyer mandreel pdas regexp splay 
rhino 
nashorn 
jdk8 
nashorn 
jdk9 
JavaScript 
Engine
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Nashorn 
Quick 
Demo 
10
Scaling 
Server-­‐Side 
JavaScript 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
11
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
What 
If 
I’m 
in 
a 
Java 
Shop? 
• Java 
Developer 
Investments 
– In-­‐house 
Java-­‐based 
frameworks 
– 3rd 
party 
commercial 
and/or 
open 
source 
libraries 
– Lots 
of 
experience 
with 
Java 
development 
• Investment 
in 
Java 
infrastructure 
– Java 
EE 
application 
servers 
– JMX-­‐based 
monitoring 
and 
management 
– Established 
data 
center 
processes 
and 
best 
practices 
– “We 
are 
a 
Java 
company”, 
or 
“We 
already 
do 
Java 
and 
.NET” 
12
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Project 
Avatar 
13 
Bridging 
the 
gap 
Avatar 
Node 
on 
the 
JVM 
! 
Thousands 
of 
Node 
libraries 
! 
Thousands 
of 
Java 
libraries 
Java 
EE 
Interoperability 
! 
Leverage 
Existing 
Infrastructure 
! 
Build 
Enterprise 
Applications 
in 
JavaScript 
!
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Agenda 
Setting 
the 
context 
Avatar 
– 
Enterprise 
Node 
on 
the 
JVM 
Demo 
1 
2 
3 
14
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Avatar 
2.0 
• 95% 
Node 
compatibility 
provided 
by 
Avatar.js 
• Uses 
same 
C 
portability 
libraries 
as 
Node.js 
– libuv, 
http-­‐parser 
• No 
Chrome 
v8 
native 
APIs! 
• Run 
popular 
packages 
– Express, 
async, 
commander, 
etc. 
15
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Avatar 
2.0 
• Enterprise 
Features 
– Advanced 
multithreading 
– State 
sharing 
– Avatar 
Persistence 
– Java 
EE 
Interoperability 
(EJB, 
JMS) 
16
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Avatar 
2.0 
-­‐ 
What’s 
new 
• Runs 
standalone 
– Out 
of 
the 
box, 
no 
application 
server 
required 
• Run 
from 
command 
line 
• Use 
your 
favorite 
Node 
framework(s) 
• Use 
your 
favorite 
client 
framework 
17
Avatar 
Process 
Application JavaScript Modules & Java Jars 
Bundled Third-Party JavaScript Modules 
Avatar API Modules 
WLS T3 thin client 
EclipseLink, NoSQL 
MBeans 
Avatar 
Flight Recorder Probes 
Application 
JavaScript 
& 
Java 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
18 
Avatar 
2.0 
Architecture 
REST/WS/SSE 
JVM 
Core Node Modules 
Nashorn & JRE 8 
Mission 
Control 
Mgmt Plugin Admin Agent 
EJB/JMS WebLogic 
Data Database 
libuv + JNI bindings 
JavaScript 
code 
Java 
code 
Platform 
specific 
native 
code 
Optional 
Processes 
Coherence State Coherence
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Nashorn 
! 
• Bundled 
with 
Java 
7 
and 
8 
• ECMAScript 
5.1 
compatibility 
• Performance 
(vs 
Rhino) 
• Java 
Interoperability 
19 
6 
4,5 
3 
1,5 
0 
crypto earley-­‐boyer mandreel pdas regexp splay 
rhino 
nashorn 
jdk8 
nashorn 
jdk9 
JavaScript 
Engine
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
20 
Nashorn 
-­‐ 
Using 
Java 
8 
within 
a 
Node 
app 
var http = require("http");! 
var list = new java.util.ArrayList();! 
! 
list.add("Blue"); list.add(“Green"); list.add("Yellow");! 
list.add("Red"); list.add("Dark Red"); list.add("Light Red”);! 
! 
http.createServer(function(request, response) {! 
response.writeHead(200, {"Content-Type": "application/json"});! ! 
var count = list.parallelStream()! 
.filter(function(t) { return t.match('Red') } )! 
.count();! ! 
response.end(“{'reds': count}”);! 
}).listen(8080);
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Avatar 
Multithreading 
• Multiple 
instances 
of 
an 
application 
in 
single 
JVM 
process 
– Each 
instance 
has 
its 
own 
event 
loop 
thread 
and 
JavaScript 
context 
– Shared 
sockets 
– 
every 
instance 
listens 
on 
the 
same 
port 
– Optional 
coordination 
via 
JavaScript 
state 
sharing 
APIs 
– Messaging 
API 
– Map 
API 
• Can 
dynamically 
create 
background 
threads 
as 
well 
21 
Taking 
advantage 
of 
the 
multithreaded 
JVM
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Avatar 
Application 
Scaling 
22 
A 
picture 
is 
worth 
a 
thousand 
threads
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
23 
Creating 
New 
Event 
Threads 
!var threads = require('avatar/threads');! 
var createBallThread = function(ballInfo) {! 
! var deferred = when.defer();! 
! var eventThread = threads.newEventThread("BouncingBallThread", ! 
! ! __dirname + "/ball.js", [! 
! ! ! "color=" + ballInfo.color,! 
! ! ! "gravity=" + ballInfo.gravity,! 
! ! ! "rowid=" + ballInfo.id_! 
!! ! ]);! 
! eventThread.start(function (event, error) {! 
! ! switch(event) {! 
! ! ! case "started":! 
! ! ! ! console.log("Thread ", eventThread.thread.index(), "Started");! 
! ! ! ! ballInfo.id = eventThread.thread.index();! 
…
Avatar 
Shared 
State 
Framework 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Message 
Bus 
– Publish 
/ 
subscribe 
message 
passing 
• Shared 
State 
– Simple 
map 
API 
– Application-­‐scoped 
instance 
– Session-­‐scoped 
instance 
• Named 
• Leased, 
with 
configurable 
timeout 
• Avatar 
provides 
required 
serialization, 
concurrency 
control, 
and 
caching 
24 
Lightweight 
inter-­‐thread 
communication
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
25 
Message 
Bus 
(Subscribe) 
bus.on("kill", function (id) {! 
if (_interval && _id && (_id.toString() === id.toString())) {! 
clearInterval(_interval);! 
process.exit();! 
}! 
});! 
! 
bus.subscribe("argsUpdate", function (data) {! 
if (data.id === app.threadIndex) {! 
gravity = data.gravity;! 
}! 
});
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
26 
Message 
Bus 
(Publish) 
_interval = setInterval(function () {! 
var msg = {! 
id: _id, ! 
color: app.args.color,! 
heartbeat: heartbeat++, ! 
…! 
};! ! 
msg.message = "Thread " + app.threadIndex + " | Heartbeat: " +! 
heartbeat + " | Gravity: " + gravity;! ! 
bus.publish("messages", msg);! ! 
}, 2000);
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Supports 
Relational 
& 
NoSQL 
databases 
• Similar 
to 
Sequelize, 
JugglingDB, 
etc 
• Leverages 
EclipseLink 
JPA 
Provider 
• Leverages 
mature, 
feature 
rich 
Java 
ecosystem 
– Tooling 
to 
generate 
JavaScript 
model 
for 
existing 
database 
schema 
– 2nd 
level 
JPA 
cache 
(TopLink 
Grid) 
– Oracle 
RAC 
connection 
pooling, 
etc. 
27 
Avatar 
Persistence 
Framework 
JavaScript 
API
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
28 
Avatar 
Persistence 
(Model) 
var avatar = require("avatar");! 
var model = require("avatar/model");! ! 
var store = model.newStore(config.db.name, {! 
database: config.db.database,! 
username: config.db.username,! 
properties: { "eclipselink.logging.level": “INFO” }! 
});! ! 
var BallModel = model.newModel("Ball", {! 
"color": "string",! 
"gravity": "number"! 
});! ! 
store.bind(BallModel);
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
29 
Avatar 
Persistence 
(Model) 
var avatar = require("avatar");! 
var model = require("avatar/model");! ! 
var store = model.newStore(config.db.name, {! 
database: config.db.database,! 
username: config.db.username,! 
properties: { "eclipselink.logging.level": “INFO” }! 
});! ! 
var BallModel = model.newModel("Ball", {! 
"color": "string",! 
"gravity": "number"! 
});! ! 
store.bind(BallModel);
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
30 
Avatar 
Persistence 
return {! 
! getThreads: function() {! 
! ! return BallModel.getAll();! 
! },! 
! ! 
! createThread: function(thread) {! 
! ! return BallModel.create(aBall);! 
! },! 
! ! 
! deleteThread: function(id) {! 
! ! return BallModel.delete(id);! 
! },! 
! ! 
! updateThread: function(data) {! 
! ! var deferred = when.defer();! 
! ! BallModel.get(data.id_).then(function(row) {! 
! ! row.gravity = parseInt(data.gravity);! 
! ! BallModel.put(row).then(function(updatedRow) {
Additional 
Features 
and 
Potential 
• Expand 
Java 
Mission 
Control 
/ 
Flight 
Recorder 
support 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Remote 
EJB 
and 
JMS 
support 
– Using 
WebLogic 
t3 
thin 
client 
• Automatically 
reload 
application 
on 
file 
change 
(development 
feature) 
• Work 
in 
progress 
– Coherence 
(JCache) 
integration 
for 
cross-­‐JVM 
state 
sharing 
– Manage 
using 
WebLogic 
and/or 
Oracle 
Enterprise 
Manager 
31
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Agenda 
Setting 
the 
context 
Avatar 
– 
Enterprise 
Node 
on 
the 
JVM 
Demo 
1 
2 
3 
32
model.js 
heartbeat gravity heartbeat heartbeat Message 
Bus 
express.js ws.js avatar.js 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
33 
Browser main.js ball.js ball.js ball.js 
. 
. 
. 
ball.js 
newEventThread(‘ball.js’) 
REST 
WebSocket 
Avatar 
Process 
Database 
Demo
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Next 
• Check 
Avatar 
- http://avatar.java.net 
• We 
plan 
to 
open 
source 
Avatar 
2.0 
soon 
• We 
need 
your 
feedback! 
! 
• Thank 
You! 
34
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
35

More Related Content

What's hot (18)

PPTX
Mastering the Sling Rewriter
Justin Edelson
 
PDF
Java EE 8: On the Horizon
Josh Juneau
 
PDF
Nashorn in the future (English)
Logico
 
PDF
Java: Create The Future Keynote
Simon Ritter
 
PDF
JavaScript Interview Questions and Answers | Full Stack Web Development Train...
Edureka!
 
PDF
40020
tutorialsruby
 
PPTX
Real life-maf-2015
Luc Bors
 
PPT
Reactive Java EE - Let Me Count the Ways!
Reza Rahman
 
PPT
01 java intro
Deepal Shah
 
PDF
Java EE Revisits GoF Design Patterns
Murat Yener
 
PPTX
Java EE 8 Update
Ryan Cuprak
 
PDF
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
David Delabassee
 
PPTX
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
Daniel Bryant
 
PDF
Real Life MAF (2.2) Oracle Open World 2015
Luc Bors
 
PPT
Developing modular Java applications
Julien Dubois
 
PDF
JavaOne 2014 BOF4241 What's Next for JSF?
Edward Burns
 
PDF
Avoiding Java EE Application Design Traps to Achieve Effective Use of Cloud C...
Dr. Spock
 
PDF
JavaOne 2011: Migrating Spring Applications to Java EE 6
Bert Ertman
 
Mastering the Sling Rewriter
Justin Edelson
 
Java EE 8: On the Horizon
Josh Juneau
 
Nashorn in the future (English)
Logico
 
Java: Create The Future Keynote
Simon Ritter
 
JavaScript Interview Questions and Answers | Full Stack Web Development Train...
Edureka!
 
Real life-maf-2015
Luc Bors
 
Reactive Java EE - Let Me Count the Ways!
Reza Rahman
 
01 java intro
Deepal Shah
 
Java EE Revisits GoF Design Patterns
Murat Yener
 
Java EE 8 Update
Ryan Cuprak
 
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
David Delabassee
 
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
Daniel Bryant
 
Real Life MAF (2.2) Oracle Open World 2015
Luc Bors
 
Developing modular Java applications
Julien Dubois
 
JavaOne 2014 BOF4241 What's Next for JSF?
Edward Burns
 
Avoiding Java EE Application Design Traps to Achieve Effective Use of Cloud C...
Dr. Spock
 
JavaOne 2011: Migrating Spring Applications to Java EE 6
Bert Ertman
 

Similar to Server Side JavaScript on the Java Platform - David Delabassee (20)

PDF
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
David Delabassee
 
PPTX
JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Leonardo Zanivan
 
PDF
CON6423: Scalable JavaScript applications with Project Nashorn
Michel Graciano
 
PDF
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Vitalij Zadneprovskij
 
PDF
IBM InterConnect: Java vs JavaScript for Enterprise WebApps
Chris Bailey
 
PPTX
NodeJS - Server Side JS
Ganesh Kondal
 
PDF
Avatar.js
Alin Pandichi
 
PPTX
After the LAMP, it's time to get MEAN
Jeff Fox
 
PDF
A295 nodejs-knowledge-accelerator
Michael Dawson
 
PDF
Node.js for beginner
Sarunyhot Suwannachoti
 
PDF
JAX London 2015: Java vs Nodejs
Chris Bailey
 
PDF
JavaOne 2014: Java vs JavaScript
Chris Bailey
 
PDF
Java vs. Java Script for enterprise web applications - Chris Bailey
JAXLondon_Conference
 
PPT
Node and Azure
Jason Gerard
 
PDF
Node.js Enterprise Middleware
Behrad Zari
 
PPTX
Beginners Node.js
Khaled Mosharraf
 
PPTX
Oracle application container cloud back end integration using node final
Getting value from IoT, Integration and Data Analytics
 
PPTX
Introduction to node.js
Arun Kumar Arjunan
 
PPTX
Introduction to Node.js
Vikash Singh
 
PDF
Node.js an Exectutive View
Manuel Eusebio de Paz Carmona
 
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
David Delabassee
 
JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Leonardo Zanivan
 
CON6423: Scalable JavaScript applications with Project Nashorn
Michel Graciano
 
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Vitalij Zadneprovskij
 
IBM InterConnect: Java vs JavaScript for Enterprise WebApps
Chris Bailey
 
NodeJS - Server Side JS
Ganesh Kondal
 
Avatar.js
Alin Pandichi
 
After the LAMP, it's time to get MEAN
Jeff Fox
 
A295 nodejs-knowledge-accelerator
Michael Dawson
 
Node.js for beginner
Sarunyhot Suwannachoti
 
JAX London 2015: Java vs Nodejs
Chris Bailey
 
JavaOne 2014: Java vs JavaScript
Chris Bailey
 
Java vs. Java Script for enterprise web applications - Chris Bailey
JAXLondon_Conference
 
Node and Azure
Jason Gerard
 
Node.js Enterprise Middleware
Behrad Zari
 
Beginners Node.js
Khaled Mosharraf
 
Oracle application container cloud back end integration using node final
Getting value from IoT, Integration and Data Analytics
 
Introduction to node.js
Arun Kumar Arjunan
 
Introduction to Node.js
Vikash Singh
 
Node.js an Exectutive View
Manuel Eusebio de Paz Carmona
 
Ad

More from JAXLondon2014 (20)

PDF
GridGain 6.0: Open Source In-Memory Computing Platform - Nikita Ivanov
JAXLondon2014
 
PDF
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
JAXLondon2014
 
PPTX
How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...
JAXLondon2014
 
PDF
Conditional Logging Considered Harmful - Sean Reilly
JAXLondon2014
 
PDF
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
JAXLondon2014
 
PPT
API Management - a hands on workshop - Paul Fremantle
JAXLondon2014
 
PDF
'Bootiful' Code with Spring Boot - Josh Long
JAXLondon2014
 
PDF
The Full Stack Java Developer - Josh Long
JAXLondon2014
 
PDF
The Economies of Scaling Software - Josh Long and Abdelmonaim Remani
JAXLondon2014
 
PDF
Dataflow, the Forgotten Way - Russel Winder
JAXLondon2014
 
PDF
Habits of Highly Effective Technical Teams - Martijn Verburg
JAXLondon2014
 
PDF
The Lazy Developer's Guide to Cloud Foundry - Holly Cummins
JAXLondon2014
 
PPTX
Testing within an Agile Environment - Beyza Sakir and Chris Gollop
JAXLondon2014
 
PDF
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
JAXLondon2014
 
PDF
Squeezing Performance of out of In-Memory Data Grids - Fuad Malikov
JAXLondon2014
 
PDF
Spocktacular Testing - Russel Winder
JAXLondon2014
 
PDF
Reflection Madness - Dr. Heinz Kabutz
JAXLondon2014
 
PDF
Rapid Web Application Development with MongoDB and the JVM - Trisha Gee
JAXLondon2014
 
PDF
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
JAXLondon2014
 
PDF
Personal Retrospectives - Johannes Thönes
JAXLondon2014
 
GridGain 6.0: Open Source In-Memory Computing Platform - Nikita Ivanov
JAXLondon2014
 
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
JAXLondon2014
 
How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...
JAXLondon2014
 
Conditional Logging Considered Harmful - Sean Reilly
JAXLondon2014
 
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
JAXLondon2014
 
API Management - a hands on workshop - Paul Fremantle
JAXLondon2014
 
'Bootiful' Code with Spring Boot - Josh Long
JAXLondon2014
 
The Full Stack Java Developer - Josh Long
JAXLondon2014
 
The Economies of Scaling Software - Josh Long and Abdelmonaim Remani
JAXLondon2014
 
Dataflow, the Forgotten Way - Russel Winder
JAXLondon2014
 
Habits of Highly Effective Technical Teams - Martijn Verburg
JAXLondon2014
 
The Lazy Developer's Guide to Cloud Foundry - Holly Cummins
JAXLondon2014
 
Testing within an Agile Environment - Beyza Sakir and Chris Gollop
JAXLondon2014
 
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
JAXLondon2014
 
Squeezing Performance of out of In-Memory Data Grids - Fuad Malikov
JAXLondon2014
 
Spocktacular Testing - Russel Winder
JAXLondon2014
 
Reflection Madness - Dr. Heinz Kabutz
JAXLondon2014
 
Rapid Web Application Development with MongoDB and the JVM - Trisha Gee
JAXLondon2014
 
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
JAXLondon2014
 
Personal Retrospectives - Johannes Thönes
JAXLondon2014
 
Ad

Recently uploaded (20)

PPTX
Joy In The Journey 06 22 2025.pptx
FamilyWorshipCenterD
 
PPTX
FL Studio Crack Full Version [Latest 2025]
Jackson lithms
 
PPTX
Itinerary ROHIS SMUNIC diperlukan untuk acara.pptx
lukmanjavalatte
 
PPTX
Heating_Effect_of_Solar_Corona_Presentation.pptx
Hanumamshukla
 
PDF
models-of-communication reading and writing.pdf
TristanNabong
 
PDF
Amazon Wholesale Product Research Example
Joseph Juntilla
 
PPTX
Bob Stewart Acts 18 06 18 2025.pptx
FamilyWorshipCenterD
 
PDF
Josaya - Abstract for the research of the youth development.pdf
Josaya Injesi
 
PPTX
Section 4 - Islamic Civilization & Culture.pptx
MianMuhammadUbaidUll
 
PDF
Rethinking Public–Private Partnerships: From Funding Gaps to Shared Goals
Francois Stepman
 
PDF
Materi Presentasi_Sales_Kit_IPA_Convex_2025.pdf
YudiAhmad6
 
PPTX
From Hackathon to Real-World Impact: The Story of Sneh Vidhya Sahayog
shubhamsharma994585
 
PPTX
Speech and which are the type of speechs
krajishmaa
 
DOCX
Dissertation_Antony_Musyoka.docx.for presentation
antonykamile
 
PPTX
AC_Manufacturer_Strategy_Commercial_Government.pptx
ajajsain
 
PPTX
2025-06-22 Abraham 04 (shared slides).pptx
Dale Wells
 
PPTX
AI for Empowering Women in AI
Letizia Jaccheri
 
PPTX
Pastor Bob Stewart Acts 19 06 25 2025.pptx
FamilyWorshipCenterD
 
PPTX
Soft Skills Training for Everybody.pp.pptx
Mayuri Srivastava
 
PPTX
Ludwig van Beethoven Life and Legacy.pptx
aryansnow1304
 
Joy In The Journey 06 22 2025.pptx
FamilyWorshipCenterD
 
FL Studio Crack Full Version [Latest 2025]
Jackson lithms
 
Itinerary ROHIS SMUNIC diperlukan untuk acara.pptx
lukmanjavalatte
 
Heating_Effect_of_Solar_Corona_Presentation.pptx
Hanumamshukla
 
models-of-communication reading and writing.pdf
TristanNabong
 
Amazon Wholesale Product Research Example
Joseph Juntilla
 
Bob Stewart Acts 18 06 18 2025.pptx
FamilyWorshipCenterD
 
Josaya - Abstract for the research of the youth development.pdf
Josaya Injesi
 
Section 4 - Islamic Civilization & Culture.pptx
MianMuhammadUbaidUll
 
Rethinking Public–Private Partnerships: From Funding Gaps to Shared Goals
Francois Stepman
 
Materi Presentasi_Sales_Kit_IPA_Convex_2025.pdf
YudiAhmad6
 
From Hackathon to Real-World Impact: The Story of Sneh Vidhya Sahayog
shubhamsharma994585
 
Speech and which are the type of speechs
krajishmaa
 
Dissertation_Antony_Musyoka.docx.for presentation
antonykamile
 
AC_Manufacturer_Strategy_Commercial_Government.pptx
ajajsain
 
2025-06-22 Abraham 04 (shared slides).pptx
Dale Wells
 
AI for Empowering Women in AI
Letizia Jaccheri
 
Pastor Bob Stewart Acts 19 06 25 2025.pptx
FamilyWorshipCenterD
 
Soft Skills Training for Everybody.pp.pptx
Mayuri Srivastava
 
Ludwig van Beethoven Life and Legacy.pptx
aryansnow1304
 

Server Side JavaScript on the Java Platform - David Delabassee

  • 1. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Project Avatar Server-­‐side JavaScript on the JVM ! JAX London -­‐ Oct. 2014 David Delabassee (@delabassee) Oracle
  • 2. Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 2
  • 3. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Agenda Setting the Context Avatar – Enterprise Node on the JVM Demo 1 3 3 2
  • 4. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Agenda Setting the Context Avatar – Enterprise Node on the JVM Demo 1 2 3 4
  • 5. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Node.js • Server-­‐side JavaScript based on Chrome v8 engine • Created in 2009, Open Source • Designed for scalable Internet applications • Melting pot community – Java, .NET, Browser, PHP, etc, experience • Node Packaged Modules – Very active, with +98,000 modules (YMMV) 5 Server Side JavaScript
  • 6. Node.js Programming Model • Multi-­‐threading Copyright © 2014, Oracle and/or its affiliates. All rights reserved. is hard – Thousands of concurrent connections – Deal with deadlocks and race conditions • Blocking on I/O is bad • Event Loop – Reactive Model – Non-­‐blocking I/O calls • Application code executes in a single thread 6 Event Clients Loop Non-­‐blocking Worker
  • 7. Node.js Programming Model Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 7 var http = require("http");! ! http.createServer( … ).listen(80);
  • 8. Node.js Programming Model Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 8 var http = require("http");! ! http.createServer(function(request, response) {! ! response.writeHead(200, {"Content-type": "text/plain"});! ! response.write("Hello World";)! ! response.end();! }).listen(80);
  • 9. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Nashorn ! • Bundled with Java 7 and 8 • ECMAScript 5.1 compatibility • Performance (vs Rhino) • Java Interoperability 9 6 4,5 3 1,5 0 crypto earley-­‐boyer mandreel pdas regexp splay rhino nashorn jdk8 nashorn jdk9 JavaScript Engine
  • 10. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Nashorn Quick Demo 10
  • 11. Scaling Server-­‐Side JavaScript Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 11
  • 12. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. What If I’m in a Java Shop? • Java Developer Investments – In-­‐house Java-­‐based frameworks – 3rd party commercial and/or open source libraries – Lots of experience with Java development • Investment in Java infrastructure – Java EE application servers – JMX-­‐based monitoring and management – Established data center processes and best practices – “We are a Java company”, or “We already do Java and .NET” 12
  • 13. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Project Avatar 13 Bridging the gap Avatar Node on the JVM ! Thousands of Node libraries ! Thousands of Java libraries Java EE Interoperability ! Leverage Existing Infrastructure ! Build Enterprise Applications in JavaScript !
  • 14. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Agenda Setting the context Avatar – Enterprise Node on the JVM Demo 1 2 3 14
  • 15. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Avatar 2.0 • 95% Node compatibility provided by Avatar.js • Uses same C portability libraries as Node.js – libuv, http-­‐parser • No Chrome v8 native APIs! • Run popular packages – Express, async, commander, etc. 15
  • 16. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Avatar 2.0 • Enterprise Features – Advanced multithreading – State sharing – Avatar Persistence – Java EE Interoperability (EJB, JMS) 16
  • 17. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Avatar 2.0 -­‐ What’s new • Runs standalone – Out of the box, no application server required • Run from command line • Use your favorite Node framework(s) • Use your favorite client framework 17
  • 18. Avatar Process Application JavaScript Modules & Java Jars Bundled Third-Party JavaScript Modules Avatar API Modules WLS T3 thin client EclipseLink, NoSQL MBeans Avatar Flight Recorder Probes Application JavaScript & Java Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 18 Avatar 2.0 Architecture REST/WS/SSE JVM Core Node Modules Nashorn & JRE 8 Mission Control Mgmt Plugin Admin Agent EJB/JMS WebLogic Data Database libuv + JNI bindings JavaScript code Java code Platform specific native code Optional Processes Coherence State Coherence
  • 19. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Nashorn ! • Bundled with Java 7 and 8 • ECMAScript 5.1 compatibility • Performance (vs Rhino) • Java Interoperability 19 6 4,5 3 1,5 0 crypto earley-­‐boyer mandreel pdas regexp splay rhino nashorn jdk8 nashorn jdk9 JavaScript Engine
  • 20. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 20 Nashorn -­‐ Using Java 8 within a Node app var http = require("http");! var list = new java.util.ArrayList();! ! list.add("Blue"); list.add(“Green"); list.add("Yellow");! list.add("Red"); list.add("Dark Red"); list.add("Light Red”);! ! http.createServer(function(request, response) {! response.writeHead(200, {"Content-Type": "application/json"});! ! var count = list.parallelStream()! .filter(function(t) { return t.match('Red') } )! .count();! ! response.end(“{'reds': count}”);! }).listen(8080);
  • 21. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Avatar Multithreading • Multiple instances of an application in single JVM process – Each instance has its own event loop thread and JavaScript context – Shared sockets – every instance listens on the same port – Optional coordination via JavaScript state sharing APIs – Messaging API – Map API • Can dynamically create background threads as well 21 Taking advantage of the multithreaded JVM
  • 22. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Avatar Application Scaling 22 A picture is worth a thousand threads
  • 23. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 23 Creating New Event Threads !var threads = require('avatar/threads');! var createBallThread = function(ballInfo) {! ! var deferred = when.defer();! ! var eventThread = threads.newEventThread("BouncingBallThread", ! ! ! __dirname + "/ball.js", [! ! ! ! "color=" + ballInfo.color,! ! ! ! "gravity=" + ballInfo.gravity,! ! ! ! "rowid=" + ballInfo.id_! !! ! ]);! ! eventThread.start(function (event, error) {! ! ! switch(event) {! ! ! ! case "started":! ! ! ! ! console.log("Thread ", eventThread.thread.index(), "Started");! ! ! ! ! ballInfo.id = eventThread.thread.index();! …
  • 24. Avatar Shared State Framework Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Message Bus – Publish / subscribe message passing • Shared State – Simple map API – Application-­‐scoped instance – Session-­‐scoped instance • Named • Leased, with configurable timeout • Avatar provides required serialization, concurrency control, and caching 24 Lightweight inter-­‐thread communication
  • 25. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 25 Message Bus (Subscribe) bus.on("kill", function (id) {! if (_interval && _id && (_id.toString() === id.toString())) {! clearInterval(_interval);! process.exit();! }! });! ! bus.subscribe("argsUpdate", function (data) {! if (data.id === app.threadIndex) {! gravity = data.gravity;! }! });
  • 26. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 26 Message Bus (Publish) _interval = setInterval(function () {! var msg = {! id: _id, ! color: app.args.color,! heartbeat: heartbeat++, ! …! };! ! msg.message = "Thread " + app.threadIndex + " | Heartbeat: " +! heartbeat + " | Gravity: " + gravity;! ! bus.publish("messages", msg);! ! }, 2000);
  • 27. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Supports Relational & NoSQL databases • Similar to Sequelize, JugglingDB, etc • Leverages EclipseLink JPA Provider • Leverages mature, feature rich Java ecosystem – Tooling to generate JavaScript model for existing database schema – 2nd level JPA cache (TopLink Grid) – Oracle RAC connection pooling, etc. 27 Avatar Persistence Framework JavaScript API
  • 28. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 28 Avatar Persistence (Model) var avatar = require("avatar");! var model = require("avatar/model");! ! var store = model.newStore(config.db.name, {! database: config.db.database,! username: config.db.username,! properties: { "eclipselink.logging.level": “INFO” }! });! ! var BallModel = model.newModel("Ball", {! "color": "string",! "gravity": "number"! });! ! store.bind(BallModel);
  • 29. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 29 Avatar Persistence (Model) var avatar = require("avatar");! var model = require("avatar/model");! ! var store = model.newStore(config.db.name, {! database: config.db.database,! username: config.db.username,! properties: { "eclipselink.logging.level": “INFO” }! });! ! var BallModel = model.newModel("Ball", {! "color": "string",! "gravity": "number"! });! ! store.bind(BallModel);
  • 30. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 30 Avatar Persistence return {! ! getThreads: function() {! ! ! return BallModel.getAll();! ! },! ! ! ! createThread: function(thread) {! ! ! return BallModel.create(aBall);! ! },! ! ! ! deleteThread: function(id) {! ! ! return BallModel.delete(id);! ! },! ! ! ! updateThread: function(data) {! ! ! var deferred = when.defer();! ! ! BallModel.get(data.id_).then(function(row) {! ! ! row.gravity = parseInt(data.gravity);! ! ! BallModel.put(row).then(function(updatedRow) {
  • 31. Additional Features and Potential • Expand Java Mission Control / Flight Recorder support Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Remote EJB and JMS support – Using WebLogic t3 thin client • Automatically reload application on file change (development feature) • Work in progress – Coherence (JCache) integration for cross-­‐JVM state sharing – Manage using WebLogic and/or Oracle Enterprise Manager 31
  • 32. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Agenda Setting the context Avatar – Enterprise Node on the JVM Demo 1 2 3 32
  • 33. model.js heartbeat gravity heartbeat heartbeat Message Bus express.js ws.js avatar.js Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 33 Browser main.js ball.js ball.js ball.js . . . ball.js newEventThread(‘ball.js’) REST WebSocket Avatar Process Database Demo
  • 34. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Next • Check Avatar - http://avatar.java.net • We plan to open source Avatar 2.0 soon • We need your feedback! ! • Thank You! 34
  • 35. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | 35