SlideShare a Scribd company logo
頑皮工坊
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 2010
Projects:
 ● 東森大選即時開票系統,締造兩千兩百萬 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 RingoJS

1.   VM maturaty
2.   Community size
3.   Library base
4.   Java interopability
5.   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 and
classes
js> 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 objects


js> new java.util.Date()
Thu Jan 24 16:18:17 EST 2002

var File = java.io.File;
var myfile = new File("sample.txt");
Working with Java objects


js> f = new java.io.File("test.txt")
test.txt
js> f.exists()
true
js> f.getName()
test.txt
Implementing Java Interfaces

js> obj = { run: function () { print("nrunning"); } }
[object Object]
js> obj.run()

running

js> r = new java.lang.Runnable(obj);
[object JavaObject]
Implementing Java Interfaces



js> 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
特異功能 E4X
var 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.js
var 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.js
exports.urls = [
    ['/', './actions'],
];
Database


●   ringo-sqlstore
●   berkeleystore
●   cassandrastore
●   mongodbstore
●   redis-ringojs-client
●   Google App Engine Datastore API
Mongodbstore
Initializing 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();
Mongodbstore
Retrieving 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();
Berkeleystore
Initializing 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.js
19 Aug 16:13:33 - Score (version 5): 4090

$ java -Xmx265m -jar js.jar run.js
Score (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 Engine

JavaScript engine
● Nashorn, dyn.js
● InvokeDynamic
JavaScript territory

●   Titanium
●   CouchDB
●   Unity
●   node.js + webkit
●   RingoJS + SWT
●   ES operating system
●   Ubuntu Desktop
Stay Hungry, Stay Foolish!

More Related Content

PPTX
NoSQL - Hands on
KEY
Introducing DynaTrace AJAX Edition
DOCX
Format xls sheets Demo Mode
PPTX
MongoDb and NoSQL
PPTX
MongoDB Shell Tips & Tricks
PDF
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
PPTX
Shell Tips & Tricks
PDF
MySQL Without The SQL -- Oh My! PHP Detroit July 2018
NoSQL - Hands on
Introducing DynaTrace AJAX Edition
Format xls sheets Demo Mode
MongoDb and NoSQL
MongoDB Shell Tips & Tricks
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
Shell Tips & Tricks
MySQL Without The SQL -- Oh My! PHP Detroit July 2018

What's hot (20)

PPTX
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
PDF
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
KEY
Introduction to MongoDB
PPTX
2015 02-09 - NoSQL Vorlesung Mosbach
PDF
San Francisco Java User Group
PDF
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
PDF
Drupal 7: What's In It For You?
PDF
Latinoware
PDF
MySQL Without the SQL - Oh My! August 2nd presentation at Mid Atlantic Develo...
KEY
PDF
Building Your First MongoDB App
KEY
Seedhack MongoDB 2011
KEY
London MongoDB User Group April 2011
ODP
PDF
CouchDB Open Source Bridge
PDF
Dynamic SQL in doobie
PDF
Vanilla JS*
PDF
Getting Started With #Drools 6 Slides - JBUG Denmark
KEY
nodecalgary1
PPTX
Mastering the MongoDB Javascript Shell
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
Introduction to MongoDB
2015 02-09 - NoSQL Vorlesung Mosbach
San Francisco Java User Group
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Drupal 7: What's In It For You?
Latinoware
MySQL Without the SQL - Oh My! August 2nd presentation at Mid Atlantic Develo...
Building Your First MongoDB App
Seedhack MongoDB 2011
London MongoDB User Group April 2011
CouchDB Open Source Bridge
Dynamic SQL in doobie
Vanilla JS*
Getting Started With #Drools 6 Slides - JBUG Denmark
nodecalgary1
Mastering the MongoDB Javascript Shell
Ad

Viewers also liked (11)

PPTX
吳宗泓個人簡歷
PPTX
Patent Management Along Its Life Cycle
PPTX
洪毅昕Openmic 理念說明
PPTX
2016 【CMoney實習生計畫】
PDF
創人物Vol.1 - 兩分鐘自我介紹
PPTX
Robot 解析
PPT
1、第一堂課 自我介紹
PDF
交點聚會2分鐘自我介紹範本
PPTX
英文面試自我介紹
PPTX
[資管系 業界講師]演講題目:我的It人生
PPTX
吳崑榮 自我介紹
吳宗泓個人簡歷
Patent Management Along Its Life Cycle
洪毅昕Openmic 理念說明
2016 【CMoney實習生計畫】
創人物Vol.1 - 兩分鐘自我介紹
Robot 解析
1、第一堂課 自我介紹
交點聚會2分鐘自我介紹範本
英文面試自我介紹
[資管系 業界講師]演講題目:我的It人生
吳崑榮 自我介紹
Ad

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

ZIP
Javascript Everywhere
PPTX
Morphia: Simplifying Persistence for Java and MongoDB
PPTX
Brightstar DB
PDF
Back to Basics 2017: Mí primera aplicación MongoDB
PDF
Buildingsocialanalyticstoolwithmongodb
PDF
WebNet Conference 2012 - Designing complex applications using html5 and knock...
PDF
Using YQL Sensibly - YUIConf 2010
PDF
Experiences with Evangelizing Java Within the Database
PDF
How to React Native
PDF
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
PDF
RESTFul development with Apache sling
PDF
Persitance Data with sqlite
PDF
A new execution model for Nashorn in Java 9
PPTX
Java 7 Whats New(), Whats Next() from Oredev
PPTX
Simplifying Persistence for Java and MongoDB with Morphia
PPTX
Webinar: Building Your First MongoDB App
PPTX
Webinar: Simplifying Persistence for Java and MongoDB
PPTX
Building Your First Application with MongoDB
PDF
Who's afraid of front end databases
PDF
How to make Ajax Libraries work for you
Javascript Everywhere
Morphia: Simplifying Persistence for Java and MongoDB
Brightstar DB
Back to Basics 2017: Mí primera aplicación MongoDB
Buildingsocialanalyticstoolwithmongodb
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Using YQL Sensibly - YUIConf 2010
Experiences with Evangelizing Java Within the Database
How to React Native
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
RESTFul development with Apache sling
Persitance Data with sqlite
A new execution model for Nashorn in Java 9
Java 7 Whats New(), Whats Next() from Oredev
Simplifying Persistence for Java and MongoDB with Morphia
Webinar: Building Your First MongoDB App
Webinar: Simplifying Persistence for Java and MongoDB
Building Your First Application with MongoDB
Who's afraid of front end databases
How to make Ajax Libraries work for you

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Approach and Philosophy of On baking technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
Teaching material agriculture food technology
PPTX
A Presentation on Artificial Intelligence
Electronic commerce courselecture one. Pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Building Integrated photovoltaic BIPV_UPV.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Unlocking AI with Model Context Protocol (MCP)
“AI and Expert System Decision Support & Business Intelligence Systems”
Review of recent advances in non-invasive hemoglobin estimation
MYSQL Presentation for SQL database connectivity
Agricultural_Statistics_at_a_Glance_2022_0.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Approach and Philosophy of On baking technology
Network Security Unit 5.pdf for BCA BBA.
Teaching material agriculture food technology
A Presentation on Artificial Intelligence

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

  • 1. 頑皮工坊 Sleepnova Inc. 創 辦人暨執行長 周立瑋
  • 2. 自我介紹 頑皮工坊 Sleepnova Inc. 創辦人暨執行長,KKBOX Android 技術顧問。 (Android 與雲端技術顧問公司) 感興趣的領域: - 敏捷開發,尋找更符合人性的程式設計典範。 - 可應付高承載的延展性架構。 - 思考資訊人為社會做點什麼?
  • 3. 過去經歷 Talks: ● Javascript take-off to the clouds - Server-side Javascript @ COSCUP 2009 ● The NoSQL movement: CouchDB as an example @ COSCUP 2010 Projects: ● 東森大選即時開票系統,締造兩千兩百萬 req / 4 hr 記錄
  • 4. 最近 node.js 來勢洶洶, 怎麼辦? 別 怕, 我們也有秘密武器 RingoJS!
  • 5. 簡介 簡介 RingoJS 的特色,如何使用 RingoJS 在 JVM 上面快速開發,以及如何在專案中同時保有 scripting 的靈活度以及使用既有的 Java Library。
  • 7. The native language of the web
  • 9. About JavaScript ● Javascript vs. Java <恩怨情仇> ● JavaScript 不能拿來寫大系統? ● CommonJS module system
  • 10. RingoJS overview ● Developed by Hannes Wallnöfer (hns.github.com) ● Based on Mozilla Rhino ● Runs on JVM ● Orignal named HelmaNG ● Follow CommonJS
  • 11. Node.js vs RingoJS 1. VM maturaty 2. Community size 3. Library base 4. Java interopability 5. Single-thread vs. Multi-thread
  • 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. Rhino JavaScript Engine ● JavaScript <-> Java inter-operation ○ Access Java packages and classes ○ Working with Java objects ○ Inherit class/interface ● E4X
  • 14. Accessing Java packages and classes js> 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. Working with Java objects js> new java.util.Date() Thu Jan 24 16:18:17 EST 2002 var File = java.io.File; var myfile = new File("sample.txt");
  • 16. Working with Java objects js> f = new java.io.File("test.txt") test.txt js> f.exists() true js> f.getName() test.txt
  • 17. Implementing Java Interfaces js> obj = { run: function () { print("nrunning"); } } [object Object] js> obj.run() running js> r = new java.lang.Runnable(obj); [object JavaObject]
  • 18. Implementing Java Interfaces js> r = new java.lang.Runnable({ run: function () { print("nrunning"); } }); [object JavaObject]
  • 19. Working with Java objects js> for (i in f) { print(i) } exists parentFile mkdir toString wait
  • 20. 特異功能 E4X var 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. RingoJS ● Minimal web app ● Packages ● Storage ● AppEngine
  • 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. Ringo Shell >> var fs = require('fs'); >> var file = fs.open('README.md'); >> var lines = [line for (line in file)];
  • 24. Handle HTTP Request // actions.js var 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. Skins // in a skin <% for post in <% posts %> render 'postOverview' %> <% subskin 'postOverview' %> <h2><% post.title %></h2>
  • 26. URL mapping // config.js exports.urls = [ ['/', './actions'], ];
  • 27. Database ● ringo-sqlstore ● berkeleystore ● cassandrastore ● mongodbstore ● redis-ringojs-client ● Google App Engine Datastore API
  • 28. Mongodbstore Initializing 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. Mongodbstore Retrieving 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. Berkeleystore Initializing 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();
  • 33. Performance characteristic ● Translation to JVM bytecode ● JVM is not a perfect dynamic language VM yet!
  • 34. Performance characteristic $ node v8bench.js 19 Aug 16:13:33 - Score (version 5): 4090 $ java -Xmx265m -jar js.jar run.js Score (version 5): 120 [larger is better]
  • 35. ~1/34
  • 36. Node.js vs RingoJS GC Benchmark http://hns.github.com/2010/09/29/benchmark2.html
  • 37. Future of JavaScript Engine JavaScript engine ● Nashorn, dyn.js ● InvokeDynamic
  • 38. JavaScript territory ● Titanium ● CouchDB ● Unity ● node.js + webkit ● RingoJS + SWT ● ES operating system ● Ubuntu Desktop
  • 39. Stay Hungry, Stay Foolish!