Your SlideShare is downloading. ×
0
頑皮工坊Sleepnova Inc. 創 辦人暨執行長     周立瑋
自我介紹頑皮工坊 Sleepnova Inc. 創辦人暨執行長,KKBOX Android技術顧問。(Android 與雲端技術顧問公司)感興趣的領域:- 敏捷開發,尋找更符合人性的程式設計典範。- 可應付高承載的延展性架構。- 思考資訊人為社...
過去經歷Talks: ● Javascript take-off to the clouds - Server-side Javascript   @ COSCUP 2009 ● The NoSQL movement: CouchDB as a...
最近 node.js 來勢洶洶, 怎麼辦? 別 怕, 我們也有秘密武器 RingoJS!
簡介簡介 RingoJS 的特色,如何使用 RingoJS 在 JVM上面快速開發,以及如何在專案中同時保有scripting 的靈活度以及使用既有的 Java Library。
Why JavaScript
The native language of       the web
JavaScript 到底是不是個語言?
About JavaScript●   Javascript vs. Java <恩怨情仇>●   JavaScript 不能拿來寫大系統?●   CommonJS module system
RingoJS overview●   Developed by Hannes Wallnöfer (hns.github.com)●   Based on Mozilla Rhino●   Runs on JVM●   Orignal nam...
Node.js vs RingoJS1.   VM maturaty2.   Community size3.   Library base4.   Java interopability5.   Single-thread vs. Multi...
Node.js vs RingoJS●   VM optimize for browser          ●   Quite mature enterprise grade VM●   Young community            ...
Rhino JavaScript Engine●   JavaScript <-> Java inter-operation     ○ Access Java packages and classes     ○ Working with J...
Accessing Java packages andclassesjs> Packages.java[JavaPackage java]js> java[JavaPackage java]js> java.io.File[JavaClass ...
Working with Java objectsjs> new java.util.Date()Thu Jan 24 16:18:17 EST 2002var File = java.io.File;var myfile = new File...
Working with Java objectsjs> f = new java.io.File("test.txt")test.txtjs> f.exists()truejs> f.getName()test.txt
Implementing Java Interfacesjs> obj = { run: function () { print("nrunning"); } }[object Object]js> obj.run()runningjs> r ...
Implementing Java Interfacesjs> r = new java.lang.Runnable({   run: function () { print("nrunning"); }   });[object JavaOb...
Working with Java objects  js> for (i in f) { print(i) }  exists  parentFile  mkdir  toString  wait
特異功能 E4Xvar sales = <sales vendor="John">  <item type="peas" price="4" quantity="6"/>  <item type="carrot" price="3" quant...
RingoJS●   Minimal web app●   Packages●   Storage●   AppEngine
Hello World!exports.app = function(req) {   return {      status: 200,      headers: {"Content-Type": "text/plain"},      ...
Ringo Shell>> var fs = require(fs);>> var file = fs.open(README.md);>> var lines = [line for (line in file)];
Handle HTTP Request// actions.jsvar Response = require(ringo/webapp/response);var model = require(./model);exports.index =...
Skins// in a skin<% for post in <% posts %> render postOverview %><% subskin postOverview %>  <h2><% post.title %></h2>
URL mapping// config.jsexports.urls = [    [/, ./actions],];
Database●   ringo-sqlstore●   berkeleystore●   cassandrastore●   mongodbstore●   redis-ringojs-client●   Google App Engine...
MongodbstoreInitializing the store:include(ringo/storage/mongodbstore);store = new Store(server, 27017, dbName);Creating a...
MongodbstoreRetrieving all objects from a db:var books = Book.all();Retrieving an object by id:var book = Book.get(id);Del...
BerkeleystoreInitializing the store:include(ringo/storage/berkeleystore);store = new Store(dbpath);Creating a new Storable...
天下沒有白痴的午餐
天下沒有白吃的午餐
Performance characteristic●   Translation to JVM bytecode●   JVM is not a perfect dynamic language VM    yet!
Performance characteristic$ node v8bench.js19 Aug 16:13:33 - Score (version 5): 4090$ java -Xmx265m -jar js.jar run.jsScor...
~1/34
Node.js vs RingoJS GC Benchmark                   http://hns.github.com/2010/09/29/benchmark2.html
Future of JavaScript EngineJavaScript engine● Nashorn, dyn.js● InvokeDynamic
JavaScript territory●   Titanium●   CouchDB●   Unity●   node.js + webkit●   RingoJS + SWT●   ES operating system●   Ubuntu...
Stay Hungry, Stay Foolish!
Upcoming SlideShare
Loading in...5
×

最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!

1,777

Published on

簡介 RingoJS 的特色,如何使用 RingoJS 在 JVM 上面快速開發,以及如何在專案中同時保有 scripting 的靈活度以及使用既有的 Java Library。

Published in: Technology, News & Politics
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,777
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
15
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!"

  1. 1. 頑皮工坊Sleepnova Inc. 創 辦人暨執行長 周立瑋
  2. 2. 自我介紹頑皮工坊 Sleepnova Inc. 創辦人暨執行長,KKBOX Android技術顧問。(Android 與雲端技術顧問公司)感興趣的領域:- 敏捷開發,尋找更符合人性的程式設計典範。- 可應付高承載的延展性架構。- 思考資訊人為社會做點什麼?
  3. 3. 過去經歷Talks: ● Javascript take-off to the clouds - Server-side Javascript @ COSCUP 2009 ● The NoSQL movement: CouchDB as an example @ COSCUP 2010Projects: ● 東森大選即時開票系統,締造兩千兩百萬 req / 4 hr 記錄
  4. 4. 最近 node.js 來勢洶洶, 怎麼辦? 別 怕, 我們也有秘密武器 RingoJS!
  5. 5. 簡介簡介 RingoJS 的特色,如何使用 RingoJS 在 JVM上面快速開發,以及如何在專案中同時保有scripting 的靈活度以及使用既有的 Java Library。
  6. 6. Why JavaScript
  7. 7. The native language of the web
  8. 8. JavaScript 到底是不是個語言?
  9. 9. About JavaScript● Javascript vs. Java <恩怨情仇>● JavaScript 不能拿來寫大系統?● CommonJS module system
  10. 10. RingoJS overview● Developed by Hannes Wallnöfer (hns.github.com)● Based on Mozilla Rhino● Runs on JVM● Orignal named HelmaNG● Follow CommonJS
  11. 11. Node.js vs RingoJS1. VM maturaty2. Community size3. Library base4. Java interopability5. Single-thread vs. Multi-thread
  12. 12. Node.js vs RingoJS● VM optimize for browser ● Quite mature enterprise grade VM● Young community ● Big community● Not much library but will grow ● Lots of Java library● No Java interoperability ● Very good Java interoperability● Single thread ● Multi-thread
  13. 13. Rhino JavaScript Engine● JavaScript <-> Java inter-operation ○ Access Java packages and classes ○ Working with Java objects ○ Inherit class/interface● E4X
  14. 14. Accessing Java packages andclassesjs> Packages.java[JavaPackage java]js> java[JavaPackage java]js> java.io.File[JavaClass java.io.File]js> importPackage(java.io)js> File[JavaClass java.io.File]
  15. 15. Working with Java objectsjs> new java.util.Date()Thu Jan 24 16:18:17 EST 2002var File = java.io.File;var myfile = new File("sample.txt");
  16. 16. Working with Java objectsjs> f = new java.io.File("test.txt")test.txtjs> f.exists()truejs> f.getName()test.txt
  17. 17. Implementing Java Interfacesjs> obj = { run: function () { print("nrunning"); } }[object Object]js> obj.run()runningjs> r = new java.lang.Runnable(obj);[object JavaObject]
  18. 18. Implementing Java Interfacesjs> r = new java.lang.Runnable({ run: function () { print("nrunning"); } });[object JavaObject]
  19. 19. Working with Java objects js> for (i in f) { print(i) } exists parentFile mkdir toString wait
  20. 20. 特異功能 E4Xvar sales = <sales vendor="John"> <item type="peas" price="4" quantity="6"/> <item type="carrot" price="3" quantity="10"/> <item type="chips" price="5" quantity="3"/> </sales>;alert( sales.item.(@type == "carrot").@quantity );alert( sales.@vendor );for each( var price in sales..@price ) { alert( price );}delete sales.item[0];sales.item += <item type="oranges" price="4"/>;sales.item.(@type == "oranges").@quantity = 4;
  21. 21. RingoJS● Minimal web app● Packages● Storage● AppEngine
  22. 22. Hello World!exports.app = function(req) { return { status: 200, headers: {"Content-Type": "text/plain"}, body: ["Hello World!"] };};if (require.main == module) require("ringo/httpserver").main(module.id);
  23. 23. Ringo Shell>> var fs = require(fs);>> var file = fs.open(README.md);>> var lines = [line for (line in file)];
  24. 24. Handle HTTP Request// actions.jsvar Response = require(ringo/webapp/response);var model = require(./model);exports.index = function(req) { var posts = model.Post.query().select().slice(0,10); return Response.skin(skins/index.html, { posts: posts, });};
  25. 25. Skins// in a skin<% for post in <% posts %> render postOverview %><% subskin postOverview %> <h2><% post.title %></h2>
  26. 26. URL mapping// config.jsexports.urls = [ [/, ./actions],];
  27. 27. Database● ringo-sqlstore● berkeleystore● cassandrastore● mongodbstore● redis-ringojs-client● Google App Engine Datastore API
  28. 28. MongodbstoreInitializing the store:include(ringo/storage/mongodbstore);store = new Store(server, 27017, dbName);Creating a new Storable class:Book = store.defineEntity(book);Creating and saving a new Storable instance:var b = new Book({title: "DBs for dummies"});b.save();
  29. 29. MongodbstoreRetrieving all objects from a db:var books = Book.all();Retrieving an object by id:var book = Book.get(id);Deleting an object from the db:book.remove();Running a query on the database:Book.query().equals(prop, value).select();
  30. 30. BerkeleystoreInitializing the store:include(ringo/storage/berkeleystore);store = new Store(dbpath);Creating a new Storable class:Book = store.defineEntity(book);Creating and saving a new Storable instance:var b = new Book({title: "DBs for dummies"});b.save();
  31. 31. 天下沒有白痴的午餐
  32. 32. 天下沒有白吃的午餐
  33. 33. Performance characteristic● Translation to JVM bytecode● JVM is not a perfect dynamic language VM yet!
  34. 34. Performance characteristic$ node v8bench.js19 Aug 16:13:33 - Score (version 5): 4090$ java -Xmx265m -jar js.jar run.jsScore (version 5): 120[larger is better]
  35. 35. ~1/34
  36. 36. Node.js vs RingoJS GC Benchmark http://hns.github.com/2010/09/29/benchmark2.html
  37. 37. Future of JavaScript EngineJavaScript engine● Nashorn, dyn.js● InvokeDynamic
  38. 38. JavaScript territory● Titanium● CouchDB● Unity● node.js + webkit● RingoJS + SWT● ES operating system● Ubuntu Desktop
  39. 39. Stay Hungry, Stay Foolish!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×