Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
David 
Delabassee 
(@delabassee) 
Oracle 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
|...
Safe 
Harbor 
Statement 
The 
following 
is 
intended 
to 
outline 
our 
general 
product 
direction. 
It 
is 
intended 
f...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
3 
Java 
EE 
Java 
Platform 
Java 
on 
the ...
JavaScript 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
4 
Java 
EE 
Java 
Platform 
Ja...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Node.js 
• Server-­‐side 
JavaScript 
based...
Node.js 
Programming 
Model 
• Multi-­‐threading 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
rese...
Node.js 
Programming 
Model 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
7 
var http = ...
Node.js 
Programming 
Model 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
8 
var http = ...
6 
4,5 
3 
1,5 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Nashorn 
! 
• Bundled 
with...
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
What 
If 
I’m 
in 
a 
Java 
Shop? 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Java 
...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Project 
Avatar 
13 
Bridging 
the 
gap 
Av...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Avatar 
2.0 
• 95% 
Node 
compatibility 
pr...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Avatar 
2.0 
• Enterprise 
Features 
– Adva...
Avatar 
Process 
Application JavaScript Modules & Java Jars 
Bundled Third-Party JavaScript Modules 
Avatar API Modules 
W...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
17 
Nashorn 
-­‐ 
Using 
Java 
8 
within 
a...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Avatar 
Multithreading 
• Multiple 
instanc...
Avatar 
Application 
Scaling 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
19 
A 
pictur...
Creating 
New 
Event 
Threads 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
20 
!var thr...
Avatar 
Shared 
State 
Framework 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Message...
Message 
Bus 
(Subscribe) 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
22 
bus.on("kill...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
23 
Message 
Bus 
(Publish) 
_interval = se...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Supports 
Relational 
& 
NoSQL 
databases...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
25 
Avatar 
Persistence 
(Model) 
var avata...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
26 
Avatar 
Persistence 
(Model) 
var avata...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
27 
Avatar 
Persistence 
return {! 
! getTh...
model.js 
heartbeat gravity heartbeat heartbeat Message 
Bus 
express.js ws.js avatar.js 
Copyright 
© 
2014, 
Oracle 
and...
Additional 
Features 
and 
Potential 
• Expand 
Java 
Mission 
Control 
/ 
Flight 
Recorder 
support 
Copyright 
© 
2014, ...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Next 
• Check 
Project 
Avatar 
(aka 
“Avat...
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
31
Avatar 2.0
Prochain SlideShare
Chargement dans…5
×

Avatar 2.0

1 688 vues

Publié le

Presented at J-Fall (Nov. 2014)

Publié dans : Internet
  • http://dbmanagement.info/Tutorials/Java.htm
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Avatar 2.0

  1. 1. David Delabassee (@delabassee) Oracle Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Avatar 2.0 J-­‐Fall 2014 1
  2. 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. 3. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 3 Java EE Java Platform Java on the Server Side Agenda
  4. 4. JavaScript Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 4 Java EE Java Platform Java on the Server Side Agenda
  5. 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. 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. 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. 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. 9. 6 4,5 3 1,5 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 0 crypto earley-­‐boyer mandreel pdas regexp splay rhino nashorn jdk8 nashorn jdk9 JavaScript Engine
  10. 10. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Nashorn Quick Demo 10
  11. 11. Scaling Server-­‐Side JavaScript Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 11
  12. 12. What If I’m in a Java Shop? Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • 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. 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. 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. 14
  15. 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) 15
  16. 16. 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 JavaScript code Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 16 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 Java code Platform specific native code Optional Processes Coherence State Coherence
  17. 17. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 17 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);
  18. 18. 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 18 Taking advantage of the multithreaded JVM
  19. 19. Avatar Application Scaling Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 19 A picture is worth a thousand threads
  20. 20. Creating New Event Threads Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 20 !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();! …
  21. 21. 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 21 Lightweight inter-­‐thread communication
  22. 22. Message Bus (Subscribe) Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 22 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;! }! });
  23. 23. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 23 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);
  24. 24. 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. 24 Avatar Persistence Framework JavaScript API
  25. 25. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 25 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);
  26. 26. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 26 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);
  27. 27. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 27 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) {
  28. 28. model.js heartbeat gravity heartbeat heartbeat Message Bus express.js ws.js avatar.js Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 28 Browser main.js ball.js ball.js ball.js . . . ball.js newEventThread(‘ball.js’) REST WebSocket Avatar Process Database Demo
  29. 29. 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 29
  30. 30. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Next • Check Project Avatar (aka “Avatar 1.0”) - http://avatar.java.net • We plan to open source Avatar 2.0 soon • We need your feedback! ! • Thank You! 30
  31. 31. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 31

×