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

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

on

  • 2,018 views

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

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

Statistics

Views

Total Views
2,018
Views on SlideShare
2,012
Embed Views
6

Actions

Likes
1
Downloads
14
Comments
0

2 Embeds 6

https://twitter.com 5
http://nodeslide.herokuapp.com 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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

  • 頑皮工坊Sleepnova Inc. 創 辦人暨執行長 周立瑋
  • 自我介紹頑皮工坊 Sleepnova Inc. 創辦人暨執行長,KKBOX Android技術顧問。(Android 與雲端技術顧問公司)感興趣的領域:- 敏捷開發,尋找更符合人性的程式設計典範。- 可應付高承載的延展性架構。- 思考資訊人為社會做點什麼?
  • 過去經歷Talks: ● Javascript take-off to the clouds - Server-side Javascript @ COSCUP 2009 ● The NoSQL movement: CouchDB as an example @ COSCUP 2010Projects: ● 東森大選即時開票系統,締造兩千兩百萬 req / 4 hr 記錄
  • 最近 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 named HelmaNG● Follow CommonJS
  • Node.js vs RingoJS1. VM maturaty2. Community size3. Library base4. Java interopability5. Single-thread vs. Multi-thread
  • 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
  • Rhino JavaScript Engine● JavaScript <-> Java inter-operation ○ Access Java packages and classes ○ Working with Java objects ○ Inherit class/interface● E4X
  • 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]
  • 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");
  • 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 = new java.lang.Runnable(obj);[object JavaObject]
  • Implementing Java Interfacesjs> r = new java.lang.Runnable({ run: function () { print("nrunning"); } });[object JavaObject]
  • 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" 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;
  • RingoJS● Minimal web app● Packages● Storage● AppEngine
  • 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);
  • 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 = function(req) { var posts = model.Post.query().select().slice(0,10); return Response.skin(skins/index.html, { posts: posts, });};
  • 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 Datastore API
  • 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();
  • 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();
  • 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();
  • 天下沒有白痴的午餐
  • 天下沒有白吃的午餐
  • 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.jsScore (version 5): 120[larger is better]
  • ~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 Desktop
  • Stay Hungry, Stay Foolish!