Project Avatar (Lyon JUG & Alpes JUG - March 2014)

David Delabassee
David DelabasseeDevRel - Java Platform Group - Oracle
Project Avatar:
Server Side JavaScript on the JVM
Lyon JUG - March 2014
!
David Delabassee
@delabassee
Software Evangelist - Oracle
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!2
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.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Agenda
▪ Web Application Architecture Evolution
▪ JavaScript and Node on the JVM
▪ Project Avatar – Advanced JavaScript Services
▪ Avatar Client Framework
▪ Summary
!3
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Evolution of Web Application Architecture
!4
A Java EE Perspective
Http, REST
REST, SSE, WebSockets
Presentation
!
(Servlet/JSP,

JSF)
Connectivity


(WebSocket,

REST,SSE)
EnterpriseConnectivity

andBusinessLogic
Java EE / JVM
▪ Single-page applications
▪ View/Controller in browser
▪ Model on server
View
Controller
JavaScript
Browser
ClientServer
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Java EE – The Latest in Enterprise Java
!5
ENTERPRISE
EDITIONDEVELOPER
PRODUCTIVITY
MEETING 

ENTERPRISE
DEMANDS
Java EE 7
▪ Batch
▪ Concurrency
▪ Simplified JMS
▪ More annotated POJOs
▪ Less boilerplate code
▪ Cohesive integrated 

platform
▪ WebSockets
▪ JSON
▪ Servlet 3.1 NIO
▪ REST
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Node.js
▪ Server-side JavaScript based on Chrome v8 engine
▪ Created by Ryan Dahl (2009), Open Source
▪ Designed for fast, scalable network applications
▪ Event-driven, non-blocking I/O model
▪ “Melting pot community”
▪ JavaScript, Java, .NET, PHP, …
▪ Very active, with 60,000+ modules
!6
Server Side JavaScript
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Node.js Programming Model
▪ Multi-threading is hard
▪ Thousands of concurrent connections
▪ Deal with deadlocks and race conditions
▪ Blocking I/O is bad
!7
▪ Single threaded
▪ Event-loop
▪ Callback model
▪ Non-blocking I/O calls
▪ Heavily parallelized
HTTP Callback Example:
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Node.js Event Loop
!8
Single-Threaded

Event Loop
Resource-Intensive
Operations
Network
File System
Network
Compute
Register Callback
CompleteOperation
Client
Requests
(Http)
Response
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!9
REST/SSE/WebSockets
JavaScript
View
Controller
JavaScript
Browser
ClientServer
Node
Evolution of Web Application Architecture
▪ Project-based end-to-end JavaScript
▪ Rapid prototyping & API layer
▪ Leverage backend resources
▪ Aggregate & transform content
▪ Return JSON to browser
Mobile-enabling existing services
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!10
Evolution of Web Application Architecture
Mobile-enabling existing services
ClientServer
EnterpriseConnectivity

andBusinessLogic
Java EE / JVM
JavaScript
What if we could run Node

alongside Java EE in

the same JVM?
View
Controller
JavaScript
Browser
REST / SSE/ WebSockets
Node
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!11
JavaScript and
Node on the JVM
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Project Nashorn
▪ ECMAScript 5.1 compliant
▪ Bundled with JDK 8
▪ Replaces Rhino
▪ Faster (2x – 10x)
▪ More secure
▪ Java <-> JavaScript interoperability
!12
JavaScript on the JVM
http://download.java.net/jdk8/docs/technotes/guides/scripting/nashorn/index.html
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Avatar.js
▪ Platform for server side JavaScript applications
▪ Requires Nashorn (JDK 8)
▪ 95% Node compatibility
▪ Use popular packages (Express, async, commander, etc)
▪ Uses same portability libraries as Node.js
▪ Limitation: No Chrome v8 native APIs
▪ Avatar.js Advantages
▪ Leverage JVM
▪ e.g. Java frameworks, libraries, tools…
!13
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Avatar.js = Node + Java
!14
Leverage Java, including Threads
Java
JavaScript
java.lang.Thread
java.util.SortedSet
java.math.BigInteger
Node App
JVM Process
com.myorg.MyObj
require (‘async’)
postEvent() ▪ Node Programming Model
▪ Code in JavaScript
▪ Single event loop / thread
▪ Require (import) Node modules
▪ Invoke Java code
▪ Java types and libraries
▪ new java.lang.Thread();
▪ new com.myorg.MyObj();
▪ …
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!15
Project Avatar:

Advanced JavaScript Services



Leveraging Java EE
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Project Avatar
▪ Similar in spirit to Servlets, but focused on REST, WebSocket,
Server Sent Event (SSE) endpoints
▪ Use familiar Node.js event-driven programming model and modules
▪ Layers on Avatar.js Node-compatible runtime
▪ Adds integrated enterprise features
!16
A Server Side JavaScript Services Framework
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Project Avatar
▪ Multi-threading, lightweight message passing, no mutable
shared state
▪ HTTP listener / load-balancer managed by framework
▪ Model Store – Object Relational Mapping
▪ Messaging – JMS on Java EE container
!17
Leveraging the JVM and Java EE
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Avatar Architecture
!18
Server side
Server Database
Data
Notification
JDK 8 / Nashorn
Avatar Runtime
Node Modules
Avatar Modules
Server Runtime (Java EE)
Application
Services
= Java framework
= JavaScript framework
= Application code
Avatar.js
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Avatar Services
!19
Multi-core, state sharing, data storage
Java
JVM Process
JavaScript
Services Services ServicesServices
Database
Data
Notification
shared state
JSON JSON JSON JSON
HTTP Load Balancer
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Shared State
▪ MessageBus
▪ Publish/subscribe message passing
▪ Shared State
▪ Simple map API
▪ Application-scoped instance
▪ Session-scoped instance
▪ Named
▪ Leased, with configurable timeout
▪ Provide required serialization, concurrency, and caching
!20
Lightweight inter-thread communication
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Shared State Example
!21
var avatar = require(‘org/glassfish/avatar’);!
var threads = require(‘org/glassfish/avatar/threads’);!
var app = avatar.application;!
var name = app.name;!
var bus = app.bus;!
!
// Listen for messages on the ‘alert’ topic!
bus.on(‘alert’, function(msg) {!
print(name + ‘ got ‘ + msg); !
});!
!
// Start a background thread which publishes to the ‘alert’ topic!
// Background threads do not participate in request processing!
threads.newBackgroundThread(‘background’, ‘monitor.js’).start();!
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Push Service Example
!22
var avatar = require(‘org/glassfish/avatar’);!
var threads = require('org/glassfish/avatar/threads');!
var bus = avatar.application.bus;!
!
// Register a push service that forwards background messages!
avatar.registerPushService({url: 'push/message'}, function () { !
this.onOpen = function (context) {!
bus.on(’background', function(msg) {!
context.sendMessage({body: msg});!
});!
};!
});!
!
// Create and start a background thread that publishes messages!
threads.newBackgroundThread(‘background’, ‘monitor.js’).start();!
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
WebSocket Service Example
!23
// Load avatar module!
var avatar = require(‘org/glassfish/avatar’); !!
// Register service instance!
avatar.registerSocketService({ url:‘websocket/chat’ },function() { !
this.data = { transcript : ‘’ };!

this.onMessage = function (peer, message) {

this.data.transcript += message;

this.data.transcript += ‘n’;

peer.getContext().sendAll(this.data);!
};!
});!
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Model-Store Framework
▪ JavaScript ORM library
▪ Pure JavaScript API that
▪ Supports relational and non-relational databases
▪ Integration with other Avatar services
▪ Similar to pure Node.js libraries
▪ Sequelize, JugglingDB, db…
!24
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Model-Store API
!25
Model and Database setup
var Product = avatar.newModel({!
"name": {!
type: "string",!
primary: true!
},!
"price": "number",!
"quantity": "integer"!
});!
var store = avatar.newStore(‘mysql’, {!
host: ‘localhost’,!
port: 3306,!
database: ‘test’,!
username: ‘someUser’,!
password: ‘gu3ssIt’,!
createDb: true,!
dropTables: true!
});!
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Model-Store Example
!26
Creating and Storing an Object
// Binds Product model with store!
Product.bind(store);
!
// Insert a new product into the db!
store.connect(function() {
Product.create({
name: 'Widget',!
price: 1.00,
quantity: 2
}, function(err, w1) {
console.log(JSON.stringify(w1));
store.disconnect(function() {
// Done!
});
});
});
▪ Bind Model to Store
!
▪ Connect to Store
▪ Creates Product table if required
▪ Callback adds product to table
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Model-Store Example
!27
Relationships
var Family = avatarModel.newModel('family',{!
"name": {!
type: "string",!
primary: true!
},!
"description": "string"!
});!
!
var Product = avatarModel.newModel('product',{!
"name": {!
type: "string",!
primary: true!
},!
"madeBy": "string",!
"price": "number",!
"quantity": "integer"!
});!
!
Family.hasMany(Product, {!
as: 'products',!
foreign: 'family'!
});!
!
store.bind(Family, Product);
…!
// for a given ‘f’!
f.products.create(o).then(function(p) {!
// Creating prod. (p.name) !
// in family (f.name)!
…
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Model-Store API
▪ Models can have relationships with other models
▪ 1:1, 1:n, M,N
▪ Relational Data Stores
▪ Tested: Oracle DB, MySQL, Derby (Embedded, Network)
▪ Non-tested: Any other JDBC driver
▪ Non-relational Data Stores
▪ Oracle NoSQL, MongoDB (in progress)
!28
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Model-Store API
▪ Lots of possibilities and ideas
▪ Configure JPA provider using properties
▪ Generate JavaScript model from database schema
▪ User transactions
▪ 2nd level JPA cache, TopLink Grid
▪ Oracle RAC Support, …
▪ Maintain pure JavaScript API
▪ We’re looking for YOUR feedback!
!29
Opportunities to leverage JPA
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!30
Avatar Client Framework
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Avatar Client Model
▪ View
▪ Extensible component views
▪ Pre-defined Widget Sets: jQuery UI (default), jQuery Mobile, Dijit
▪ Declarative UI components
▪ Model
▪ Models (WS, SSE, REST, local) in JavaScript
▪ Easily connects to Java and JavaScript services
▪ Model library usable as standalone JavaScript file
▪ Misc.
▪ Familiar syntax in HTML with “data-” tags
▪ Bidirectional Data binding using EL (Expression Language)
▪ CSS support
▪ AMD modules for code partitioning
!31
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Avatar Architecture - Server and Client
!32
Server
Client
REST/WebSocket/SSE
*.html
*.css
*.js
HTP
Database
Data
Notification
JDK 8 / Nashorn
Avatar Compiler
Avatar Runtime
Node Modules
Avatar Modules
Server Runtime (Java EE)
Application
Services
Application Views
= Java framework
= JavaScript framework
= Application code
Avatar.js
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Hello World
!33
<script data-model=”local” data-instance="name">!
       var NameModel = function() {!
             this.first = "John";!
             this.last = "Doe";!
             this.clear = function() { this.first = this.last = "”; }; !
};!
</script>!
View
<form>!
<label for="first">First Name</label>!
<input id="first" type="text” data-value="#{name.first}"/>!
<label for=“last">Last Name</label>!
<input id=“last" type="text” data-value="#{name.last}"/>!
Hello #{name.first} #{name.last}!
<button onclick="#{name.clear()}”>Clear</button>!
</form>!
Model
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Chat WebSocket Example
!34
<script data-model="socket">!
var ChatModel = function() {!
…!
this.sendMsg = function() {!
this.send(this.user + ":" + this.message);!
this.message = "";!
};!
};!
</script>!
!
<script data-type="ChatModel" data-instance="chat”!
data-url=“websocket/chat”>!
</script>!
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!35
Project Avatar
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Summary
!36
Server-side JavaScript on the JVM
▪ Leverage the JVM
▪ Multi-threading optimizations
▪ Share state across threads, JVMs
▪ Built-in load balancing across threads
▪ Leverage Java EE services
▪ Deploy on existing Java EE infrastructure
▪ Leverage AppServer features (clustering, lifecycle management)
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Status
!37
▪ Launched JavaOne 2013
▪ GlassFish 4.0 Open Source Edition
▪ Open Source
▪ 2014
▪ Add WebLogic runtime
▪ 2015
▪ Commercial support?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Next steps
!38
1) Download
https://avatar.java.net/
2) Try it out
!
3) Give us feedback
https://avatar.java.net/mailing.html
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Merci!
!39
Project Avatar
https://avatar.java.net/
!
Java EE 8 Survey
http://glassfish.org/survey
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12!40
Graphic Section Divider
1 of 40

Recommended

Java EE 7 (Lyon JUG & Alpes JUG - March 2014) by
Java EE 7 (Lyon JUG & Alpes JUG  - March 2014)Java EE 7 (Lyon JUG & Alpes JUG  - March 2014)
Java EE 7 (Lyon JUG & Alpes JUG - March 2014)David Delabassee
4.8K views76 slides
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014 by
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014David Delabassee
5.9K views42 slides
JavaOne 2014 BOF4241 What's Next for JSF? by
JavaOne 2014 BOF4241 What's Next for JSF?JavaOne 2014 BOF4241 What's Next for JSF?
JavaOne 2014 BOF4241 What's Next for JSF?Edward Burns
29.8K views33 slides
XML and Web Services with Groovy by
XML and Web Services with GroovyXML and Web Services with Groovy
XML and Web Services with GroovyPaul King
3.8K views86 slides
RESTful Services and Distributed OSGi - 04/2009 by
RESTful Services and Distributed OSGi - 04/2009RESTful Services and Distributed OSGi - 04/2009
RESTful Services and Distributed OSGi - 04/2009Roland Tritsch
3K views30 slides
HTTP/2 comes to Java by
HTTP/2 comes to JavaHTTP/2 comes to Java
HTTP/2 comes to JavaDavid Delabassee
5.9K views79 slides

More Related Content

What's hot

Java API for WebSocket 1.0: Java EE 7 and GlassFish by
Java API for WebSocket 1.0: Java EE 7 and GlassFishJava API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFishArun Gupta
23K views45 slides
What's next for Java API for WebSocket (JSR 356) by
What's next for Java API for WebSocket (JSR 356)What's next for Java API for WebSocket (JSR 356)
What's next for Java API for WebSocket (JSR 356)Pavel Bucek
34.1K views31 slides
CON5898 What Servlet 4.0 Means To You by
CON5898 What Servlet 4.0 Means To YouCON5898 What Servlet 4.0 Means To You
CON5898 What Servlet 4.0 Means To YouEdward Burns
31.5K views51 slides
Servlet 4.0 at GeekOut 2015 by
Servlet 4.0 at GeekOut 2015Servlet 4.0 at GeekOut 2015
Servlet 4.0 at GeekOut 2015Edward Burns
19.3K views87 slides

What's hot(20)

Java API for WebSocket 1.0: Java EE 7 and GlassFish by Arun Gupta
Java API for WebSocket 1.0: Java EE 7 and GlassFishJava API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFish
Arun Gupta23K views
What's next for Java API for WebSocket (JSR 356) by Pavel Bucek
What's next for Java API for WebSocket (JSR 356)What's next for Java API for WebSocket (JSR 356)
What's next for Java API for WebSocket (JSR 356)
Pavel Bucek34.1K views
CON5898 What Servlet 4.0 Means To You by Edward Burns
CON5898 What Servlet 4.0 Means To YouCON5898 What Servlet 4.0 Means To You
CON5898 What Servlet 4.0 Means To You
Edward Burns31.5K views
Servlet 4.0 at GeekOut 2015 by Edward Burns
Servlet 4.0 at GeekOut 2015Servlet 4.0 at GeekOut 2015
Servlet 4.0 at GeekOut 2015
Edward Burns19.3K views
Reactive Java EE - Let Me Count the Ways! by Reza Rahman
Reactive Java EE - Let Me Count the Ways!Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!
Reza Rahman104.5K views
Web protocols for java developers by Pavel Bucek
Web protocols for java developersWeb protocols for java developers
Web protocols for java developers
Pavel Bucek582 views
WebSockets in Enterprise Applications by Pavel Bucek
WebSockets in Enterprise ApplicationsWebSockets in Enterprise Applications
WebSockets in Enterprise Applications
Pavel Bucek8K views
WebSockets - Realtime em Mundo Conectado by Bruno Borges
WebSockets - Realtime em Mundo ConectadoWebSockets - Realtime em Mundo Conectado
WebSockets - Realtime em Mundo Conectado
Bruno Borges1.3K views
Experiences of SOACS by Simon Haslam
Experiences of SOACSExperiences of SOACS
Experiences of SOACS
Simon Haslam563 views
Server Side JavaScript on the Java Platform - David Delabassee by JAXLondon2014
Server Side JavaScript on the Java Platform - David DelabasseeServer Side JavaScript on the Java Platform - David Delabassee
Server Side JavaScript on the Java Platform - David Delabassee
JAXLondon2014569 views
Cloud Foundry, Spring and Vaadin by Joshua Long
Cloud Foundry, Spring and VaadinCloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and Vaadin
Joshua Long3.2K views
Asynchronous OSGi – Promises for the Masses - T Ward by mfrancis
Asynchronous OSGi – Promises for the Masses - T WardAsynchronous OSGi – Promises for the Masses - T Ward
Asynchronous OSGi – Promises for the Masses - T Ward
mfrancis3.7K views
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010 by Arun Gupta
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Arun Gupta1.7K views
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required" by Daniel Bryant
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
Daniel Bryant21.1K views
Oracle Keynote from JMagghreb 2014 by Simon Ritter
Oracle Keynote from JMagghreb 2014Oracle Keynote from JMagghreb 2014
Oracle Keynote from JMagghreb 2014
Simon Ritter693 views

Similar to Project Avatar (Lyon JUG & Alpes JUG - March 2014)

Avatar 2.0 by
Avatar 2.0Avatar 2.0
Avatar 2.0David Delabassee
1.9K views32 slides
Tweet4Beer (atualizada): Torneira de Chopp Controlada por Java, JavaFX, IoT ... by
Tweet4Beer (atualizada): Torneira de Chopp Controlada por Java, JavaFX, IoT ...Tweet4Beer (atualizada): Torneira de Chopp Controlada por Java, JavaFX, IoT ...
Tweet4Beer (atualizada): Torneira de Chopp Controlada por Java, JavaFX, IoT ...Marco Antonio Maciel
1.2K views40 slides
Imworld.ro by
Imworld.roImworld.ro
Imworld.roGeertjan Wielenga
360 views66 slides
10 Building Blocks for Enterprise JavaScript by
10 Building Blocks for Enterprise JavaScript10 Building Blocks for Enterprise JavaScript
10 Building Blocks for Enterprise JavaScriptGeertjan Wielenga
617 views66 slides
Slovenian Oracle User Group by
Slovenian Oracle User GroupSlovenian Oracle User Group
Slovenian Oracle User GroupGeertjan Wielenga
289 views65 slides
Session at Oredev 2016. by
Session at Oredev 2016.Session at Oredev 2016.
Session at Oredev 2016.Geertjan Wielenga
327 views65 slides

Similar to Project Avatar (Lyon JUG & Alpes JUG - March 2014)(20)

Tweet4Beer (atualizada): Torneira de Chopp Controlada por Java, JavaFX, IoT ... by Marco Antonio Maciel
Tweet4Beer (atualizada): Torneira de Chopp Controlada por Java, JavaFX, IoT ...Tweet4Beer (atualizada): Torneira de Chopp Controlada por Java, JavaFX, IoT ...
Tweet4Beer (atualizada): Torneira de Chopp Controlada por Java, JavaFX, IoT ...
10 Building Blocks for Enterprise JavaScript by Geertjan Wielenga
10 Building Blocks for Enterprise JavaScript10 Building Blocks for Enterprise JavaScript
10 Building Blocks for Enterprise JavaScript
Geertjan Wielenga617 views
Building Java Desktop Apps with JavaFX 8 and Java EE 7 by Bruno Borges
Building Java Desktop Apps with JavaFX 8 and Java EE 7Building Java Desktop Apps with JavaFX 8 and Java EE 7
Building Java Desktop Apps with JavaFX 8 and Java EE 7
Bruno Borges7.3K views
HTTP/2 Comes to Java - What Servlet 4.0 Means to You by David Delabassee
HTTP/2 Comes to Java - What Servlet 4.0 Means to YouHTTP/2 Comes to Java - What Servlet 4.0 Means to You
HTTP/2 Comes to Java - What Servlet 4.0 Means to You
David Delabassee13.8K views
Surviving Life in the JavaScript Ecosystem by Geertjan Wielenga
Surviving Life in the JavaScript EcosystemSurviving Life in the JavaScript Ecosystem
Surviving Life in the JavaScript Ecosystem
Geertjan Wielenga2.8K views
What's new in Java 8 by jclingan
What's new in Java 8What's new in Java 8
What's new in Java 8
jclingan855 views
Java 8 by jclingan
Java 8Java 8
Java 8
jclingan694 views
Servidores de Aplicação: por que ainda precisamos deles? by Bruno Borges
Servidores de Aplicação: por que ainda precisamos deles?Servidores de Aplicação: por que ainda precisamos deles?
Servidores de Aplicação: por que ainda precisamos deles?
Bruno Borges1K views
Oracle JET: Enterprise-Ready JavaScript Toolkit by Geertjan Wielenga
Oracle JET: Enterprise-Ready JavaScript ToolkitOracle JET: Enterprise-Ready JavaScript Toolkit
Oracle JET: Enterprise-Ready JavaScript Toolkit
Geertjan Wielenga2.2K views
Java EE Arquillian Testing with Docker & The Cloud by Bruno Borges
Java EE Arquillian Testing with Docker & The CloudJava EE Arquillian Testing with Docker & The Cloud
Java EE Arquillian Testing with Docker & The Cloud
Bruno Borges3.3K views
Serverless Java - Challenges and Triumphs by David Delabassee
Serverless Java - Challenges and TriumphsServerless Java - Challenges and Triumphs
Serverless Java - Challenges and Triumphs
David Delabassee282 views
WSO2Con Asia 2014 - WSO2 AppDev Platform for the Connected Business by WSO2
WSO2Con Asia 2014 - WSO2 AppDev Platform for the Connected BusinessWSO2Con Asia 2014 - WSO2 AppDev Platform for the Connected Business
WSO2Con Asia 2014 - WSO2 AppDev Platform for the Connected Business
WSO21.2K views

More from David Delabassee

JVMs in Containers - Best Practices by
JVMs in Containers - Best PracticesJVMs in Containers - Best Practices
JVMs in Containers - Best PracticesDavid Delabassee
726 views37 slides
JVMs in Containers by
JVMs in ContainersJVMs in Containers
JVMs in ContainersDavid Delabassee
1.3K views38 slides
Serverless Java Challenges & Triumphs by
Serverless Java Challenges & TriumphsServerless Java Challenges & Triumphs
Serverless Java Challenges & TriumphsDavid Delabassee
1.2K views46 slides
Randstad Docker meetup - Serverless by
Randstad Docker meetup - ServerlessRandstad Docker meetup - Serverless
Randstad Docker meetup - ServerlessDavid Delabassee
322 views37 slides
Java Serverless in Action - Voxxed Banff by
Java Serverless in Action - Voxxed BanffJava Serverless in Action - Voxxed Banff
Java Serverless in Action - Voxxed BanffDavid Delabassee
232 views22 slides
Serverless Kotlin by
Serverless KotlinServerless Kotlin
Serverless KotlinDavid Delabassee
251 views24 slides

More from David Delabassee(20)

Serverless Java Challenges & Triumphs by David Delabassee
Serverless Java Challenges & TriumphsServerless Java Challenges & Triumphs
Serverless Java Challenges & Triumphs
David Delabassee1.2K views
Java Serverless in Action - Voxxed Banff by David Delabassee
Java Serverless in Action - Voxxed BanffJava Serverless in Action - Voxxed Banff
Java Serverless in Action - Voxxed Banff
David Delabassee232 views
Java EE Next - BeJUG JavaOne Afterglow 2016 by David Delabassee
Java EE Next - BeJUG JavaOne Afterglow 2016Java EE Next - BeJUG JavaOne Afterglow 2016
Java EE Next - BeJUG JavaOne Afterglow 2016
David Delabassee433 views
HTTP/2 comes to Java (Dec. 2015 version) by David Delabassee
HTTP/2 comes to Java (Dec. 2015 version)HTTP/2 comes to Java (Dec. 2015 version)
HTTP/2 comes to Java (Dec. 2015 version)
David Delabassee690 views
EJB and CDI - Alignment and Strategy by David Delabassee
EJB and CDI - Alignment and StrategyEJB and CDI - Alignment and Strategy
EJB and CDI - Alignment and Strategy
David Delabassee31.9K views
Java EE 8 - What’s new on the Web front by David Delabassee
Java EE 8 - What’s new on the Web frontJava EE 8 - What’s new on the Web front
Java EE 8 - What’s new on the Web front
David Delabassee960 views
Java EE 8 Adopt a JSR : JSON-P 1.1 & MVC 1.0 by David Delabassee
Java EE 8 Adopt a JSR : JSON-P 1.1 & MVC 1.0Java EE 8 Adopt a JSR : JSON-P 1.1 & MVC 1.0
Java EE 8 Adopt a JSR : JSON-P 1.1 & MVC 1.0
David Delabassee1.8K views
Java EE 8 - An instant snapshot by David Delabassee
Java EE 8 - An instant snapshot Java EE 8 - An instant snapshot
Java EE 8 - An instant snapshot
David Delabassee10.7K views

Recently uploaded

Special_edition_innovator_2023.pdf by
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdfWillDavies22
16 views6 slides
Black and White Modern Science Presentation.pptx by
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptxmaryamkhalid2916
14 views21 slides
Spesifikasi Lengkap ASUS Vivobook Go 14 by
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14Dot Semarang
35 views1 slide
From chaos to control: Managing migrations and Microsoft 365 with ShareGate! by
From chaos to control: Managing migrations and Microsoft 365 with ShareGate!From chaos to control: Managing migrations and Microsoft 365 with ShareGate!
From chaos to control: Managing migrations and Microsoft 365 with ShareGate!sammart93
9 views39 slides
Unit 1_Lecture 2_Physical Design of IoT.pdf by
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdfStephenTec
11 views36 slides
Data-centric AI and the convergence of data and model engineering: opportunit... by
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...Paolo Missier
34 views40 slides

Recently uploaded(20)

Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2216 views
Black and White Modern Science Presentation.pptx by maryamkhalid2916
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptx
maryamkhalid291614 views
Spesifikasi Lengkap ASUS Vivobook Go 14 by Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
From chaos to control: Managing migrations and Microsoft 365 with ShareGate! by sammart93
From chaos to control: Managing migrations and Microsoft 365 with ShareGate!From chaos to control: Managing migrations and Microsoft 365 with ShareGate!
From chaos to control: Managing migrations and Microsoft 365 with ShareGate!
sammart939 views
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec11 views
Data-centric AI and the convergence of data and model engineering: opportunit... by Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier34 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta15 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst470 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 views
Web Dev - 1 PPT.pdf by gdsczhcet
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet55 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software225 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana12 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views

Project Avatar (Lyon JUG & Alpes JUG - March 2014)

  • 1. Project Avatar: Server Side JavaScript on the JVM Lyon JUG - March 2014 ! David Delabassee @delabassee Software Evangelist - Oracle
  • 2. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!2 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.
  • 3. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Agenda ▪ Web Application Architecture Evolution ▪ JavaScript and Node on the JVM ▪ Project Avatar – Advanced JavaScript Services ▪ Avatar Client Framework ▪ Summary !3
  • 4. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Evolution of Web Application Architecture !4 A Java EE Perspective Http, REST REST, SSE, WebSockets Presentation ! (Servlet/JSP,
 JSF) Connectivity 
 (WebSocket,
 REST,SSE) EnterpriseConnectivity
 andBusinessLogic Java EE / JVM ▪ Single-page applications ▪ View/Controller in browser ▪ Model on server View Controller JavaScript Browser ClientServer
  • 5. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Java EE – The Latest in Enterprise Java !5 ENTERPRISE EDITIONDEVELOPER PRODUCTIVITY MEETING 
 ENTERPRISE DEMANDS Java EE 7 ▪ Batch ▪ Concurrency ▪ Simplified JMS ▪ More annotated POJOs ▪ Less boilerplate code ▪ Cohesive integrated 
 platform ▪ WebSockets ▪ JSON ▪ Servlet 3.1 NIO ▪ REST
  • 6. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Node.js ▪ Server-side JavaScript based on Chrome v8 engine ▪ Created by Ryan Dahl (2009), Open Source ▪ Designed for fast, scalable network applications ▪ Event-driven, non-blocking I/O model ▪ “Melting pot community” ▪ JavaScript, Java, .NET, PHP, … ▪ Very active, with 60,000+ modules !6 Server Side JavaScript
  • 7. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Node.js Programming Model ▪ Multi-threading is hard ▪ Thousands of concurrent connections ▪ Deal with deadlocks and race conditions ▪ Blocking I/O is bad !7 ▪ Single threaded ▪ Event-loop ▪ Callback model ▪ Non-blocking I/O calls ▪ Heavily parallelized HTTP Callback Example:
  • 8. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Node.js Event Loop !8 Single-Threaded
 Event Loop Resource-Intensive Operations Network File System Network Compute Register Callback CompleteOperation Client Requests (Http) Response
  • 9. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!9 REST/SSE/WebSockets JavaScript View Controller JavaScript Browser ClientServer Node Evolution of Web Application Architecture ▪ Project-based end-to-end JavaScript ▪ Rapid prototyping & API layer ▪ Leverage backend resources ▪ Aggregate & transform content ▪ Return JSON to browser Mobile-enabling existing services
  • 10. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!10 Evolution of Web Application Architecture Mobile-enabling existing services ClientServer EnterpriseConnectivity
 andBusinessLogic Java EE / JVM JavaScript What if we could run Node
 alongside Java EE in
 the same JVM? View Controller JavaScript Browser REST / SSE/ WebSockets Node
  • 11. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!11 JavaScript and Node on the JVM
  • 12. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Project Nashorn ▪ ECMAScript 5.1 compliant ▪ Bundled with JDK 8 ▪ Replaces Rhino ▪ Faster (2x – 10x) ▪ More secure ▪ Java <-> JavaScript interoperability !12 JavaScript on the JVM http://download.java.net/jdk8/docs/technotes/guides/scripting/nashorn/index.html
  • 13. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Avatar.js ▪ Platform for server side JavaScript applications ▪ Requires Nashorn (JDK 8) ▪ 95% Node compatibility ▪ Use popular packages (Express, async, commander, etc) ▪ Uses same portability libraries as Node.js ▪ Limitation: No Chrome v8 native APIs ▪ Avatar.js Advantages ▪ Leverage JVM ▪ e.g. Java frameworks, libraries, tools… !13
  • 14. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Avatar.js = Node + Java !14 Leverage Java, including Threads Java JavaScript java.lang.Thread java.util.SortedSet java.math.BigInteger Node App JVM Process com.myorg.MyObj require (‘async’) postEvent() ▪ Node Programming Model ▪ Code in JavaScript ▪ Single event loop / thread ▪ Require (import) Node modules ▪ Invoke Java code ▪ Java types and libraries ▪ new java.lang.Thread(); ▪ new com.myorg.MyObj(); ▪ …
  • 15. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!15 Project Avatar:
 Advanced JavaScript Services
 
 Leveraging Java EE
  • 16. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Project Avatar ▪ Similar in spirit to Servlets, but focused on REST, WebSocket, Server Sent Event (SSE) endpoints ▪ Use familiar Node.js event-driven programming model and modules ▪ Layers on Avatar.js Node-compatible runtime ▪ Adds integrated enterprise features !16 A Server Side JavaScript Services Framework
  • 17. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Project Avatar ▪ Multi-threading, lightweight message passing, no mutable shared state ▪ HTTP listener / load-balancer managed by framework ▪ Model Store – Object Relational Mapping ▪ Messaging – JMS on Java EE container !17 Leveraging the JVM and Java EE
  • 18. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Avatar Architecture !18 Server side Server Database Data Notification JDK 8 / Nashorn Avatar Runtime Node Modules Avatar Modules Server Runtime (Java EE) Application Services = Java framework = JavaScript framework = Application code Avatar.js
  • 19. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Avatar Services !19 Multi-core, state sharing, data storage Java JVM Process JavaScript Services Services ServicesServices Database Data Notification shared state JSON JSON JSON JSON HTTP Load Balancer
  • 20. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Shared State ▪ MessageBus ▪ Publish/subscribe message passing ▪ Shared State ▪ Simple map API ▪ Application-scoped instance ▪ Session-scoped instance ▪ Named ▪ Leased, with configurable timeout ▪ Provide required serialization, concurrency, and caching !20 Lightweight inter-thread communication
  • 21. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Shared State Example !21 var avatar = require(‘org/glassfish/avatar’);! var threads = require(‘org/glassfish/avatar/threads’);! var app = avatar.application;! var name = app.name;! var bus = app.bus;! ! // Listen for messages on the ‘alert’ topic! bus.on(‘alert’, function(msg) {! print(name + ‘ got ‘ + msg); ! });! ! // Start a background thread which publishes to the ‘alert’ topic! // Background threads do not participate in request processing! threads.newBackgroundThread(‘background’, ‘monitor.js’).start();!
  • 22. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Push Service Example !22 var avatar = require(‘org/glassfish/avatar’);! var threads = require('org/glassfish/avatar/threads');! var bus = avatar.application.bus;! ! // Register a push service that forwards background messages! avatar.registerPushService({url: 'push/message'}, function () { ! this.onOpen = function (context) {! bus.on(’background', function(msg) {! context.sendMessage({body: msg});! });! };! });! ! // Create and start a background thread that publishes messages! threads.newBackgroundThread(‘background’, ‘monitor.js’).start();!
  • 23. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. WebSocket Service Example !23 // Load avatar module! var avatar = require(‘org/glassfish/avatar’); !! // Register service instance! avatar.registerSocketService({ url:‘websocket/chat’ },function() { ! this.data = { transcript : ‘’ };!
 this.onMessage = function (peer, message) {
 this.data.transcript += message;
 this.data.transcript += ‘n’;
 peer.getContext().sendAll(this.data);! };! });!
  • 24. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Model-Store Framework ▪ JavaScript ORM library ▪ Pure JavaScript API that ▪ Supports relational and non-relational databases ▪ Integration with other Avatar services ▪ Similar to pure Node.js libraries ▪ Sequelize, JugglingDB, db… !24
  • 25. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Model-Store API !25 Model and Database setup var Product = avatar.newModel({! "name": {! type: "string",! primary: true! },! "price": "number",! "quantity": "integer"! });! var store = avatar.newStore(‘mysql’, {! host: ‘localhost’,! port: 3306,! database: ‘test’,! username: ‘someUser’,! password: ‘gu3ssIt’,! createDb: true,! dropTables: true! });!
  • 26. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Model-Store Example !26 Creating and Storing an Object // Binds Product model with store! Product.bind(store); ! // Insert a new product into the db! store.connect(function() { Product.create({ name: 'Widget',! price: 1.00, quantity: 2 }, function(err, w1) { console.log(JSON.stringify(w1)); store.disconnect(function() { // Done! }); }); }); ▪ Bind Model to Store ! ▪ Connect to Store ▪ Creates Product table if required ▪ Callback adds product to table
  • 27. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Model-Store Example !27 Relationships var Family = avatarModel.newModel('family',{! "name": {! type: "string",! primary: true! },! "description": "string"! });! ! var Product = avatarModel.newModel('product',{! "name": {! type: "string",! primary: true! },! "madeBy": "string",! "price": "number",! "quantity": "integer"! });! ! Family.hasMany(Product, {! as: 'products',! foreign: 'family'! });! ! store.bind(Family, Product); …! // for a given ‘f’! f.products.create(o).then(function(p) {! // Creating prod. (p.name) ! // in family (f.name)! …
  • 28. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Model-Store API ▪ Models can have relationships with other models ▪ 1:1, 1:n, M,N ▪ Relational Data Stores ▪ Tested: Oracle DB, MySQL, Derby (Embedded, Network) ▪ Non-tested: Any other JDBC driver ▪ Non-relational Data Stores ▪ Oracle NoSQL, MongoDB (in progress) !28
  • 29. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Model-Store API ▪ Lots of possibilities and ideas ▪ Configure JPA provider using properties ▪ Generate JavaScript model from database schema ▪ User transactions ▪ 2nd level JPA cache, TopLink Grid ▪ Oracle RAC Support, … ▪ Maintain pure JavaScript API ▪ We’re looking for YOUR feedback! !29 Opportunities to leverage JPA
  • 30. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!30 Avatar Client Framework
  • 31. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Avatar Client Model ▪ View ▪ Extensible component views ▪ Pre-defined Widget Sets: jQuery UI (default), jQuery Mobile, Dijit ▪ Declarative UI components ▪ Model ▪ Models (WS, SSE, REST, local) in JavaScript ▪ Easily connects to Java and JavaScript services ▪ Model library usable as standalone JavaScript file ▪ Misc. ▪ Familiar syntax in HTML with “data-” tags ▪ Bidirectional Data binding using EL (Expression Language) ▪ CSS support ▪ AMD modules for code partitioning !31
  • 32. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Avatar Architecture - Server and Client !32 Server Client REST/WebSocket/SSE *.html *.css *.js HTP Database Data Notification JDK 8 / Nashorn Avatar Compiler Avatar Runtime Node Modules Avatar Modules Server Runtime (Java EE) Application Services Application Views = Java framework = JavaScript framework = Application code Avatar.js
  • 33. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Hello World !33 <script data-model=”local” data-instance="name">!        var NameModel = function() {!              this.first = "John";!              this.last = "Doe";!              this.clear = function() { this.first = this.last = "”; }; ! };! </script>! View <form>! <label for="first">First Name</label>! <input id="first" type="text” data-value="#{name.first}"/>! <label for=“last">Last Name</label>! <input id=“last" type="text” data-value="#{name.last}"/>! Hello #{name.first} #{name.last}! <button onclick="#{name.clear()}”>Clear</button>! </form>! Model
  • 34. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Chat WebSocket Example !34 <script data-model="socket">! var ChatModel = function() {! …! this.sendMsg = function() {! this.send(this.user + ":" + this.message);! this.message = "";! };! };! </script>! ! <script data-type="ChatModel" data-instance="chat”! data-url=“websocket/chat”>! </script>!
  • 35. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved.!35 Project Avatar
  • 36. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Summary !36 Server-side JavaScript on the JVM ▪ Leverage the JVM ▪ Multi-threading optimizations ▪ Share state across threads, JVMs ▪ Built-in load balancing across threads ▪ Leverage Java EE services ▪ Deploy on existing Java EE infrastructure ▪ Leverage AppServer features (clustering, lifecycle management)
  • 37. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Status !37 ▪ Launched JavaOne 2013 ▪ GlassFish 4.0 Open Source Edition ▪ Open Source ▪ 2014 ▪ Add WebLogic runtime ▪ 2015 ▪ Commercial support?
  • 38. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Next steps !38 1) Download https://avatar.java.net/ 2) Try it out ! 3) Give us feedback https://avatar.java.net/mailing.html
  • 39. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Merci! !39 Project Avatar https://avatar.java.net/ ! Java EE 8 Survey http://glassfish.org/survey
  • 40. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12!40 Graphic Section Divider