SlideShare uma empresa Scribd logo
1 de 39
Baixar para ler offline
頑皮工坊
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!

Mais conteúdo relacionado

Mais procurados

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Alex Bilbie
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
kchodorow
 
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and GrailsPhilip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik
 
Seedhack MongoDB 2011
Seedhack MongoDB 2011Seedhack MongoDB 2011
Seedhack MongoDB 2011
Rainforest QA
 
CouchDB Open Source Bridge
CouchDB Open Source BridgeCouchDB Open Source Bridge
CouchDB Open Source Bridge
Chris Anderson
 
Mastering the MongoDB Javascript Shell
Mastering the MongoDB Javascript ShellMastering the MongoDB Javascript Shell
Mastering the MongoDB Javascript Shell
Scott Hernandez
 

Mais procurados (20)

MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
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
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and GrailsPhilip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
 
Drupal 7: What's In It For You?
Drupal 7: What's In It For You?Drupal 7: What's In It For You?
Drupal 7: What's In It For You?
 
Latinoware
LatinowareLatinoware
Latinoware
 
MySQL Without the SQL - Oh My! August 2nd presentation at Mid Atlantic Develo...
MySQL Without the SQL - Oh My! August 2nd presentation at Mid Atlantic Develo...MySQL Without the SQL - Oh My! August 2nd presentation at Mid Atlantic Develo...
MySQL Without the SQL - Oh My! August 2nd presentation at Mid Atlantic Develo...
 
Sequel
SequelSequel
Sequel
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
 
Seedhack MongoDB 2011
Seedhack MongoDB 2011Seedhack MongoDB 2011
Seedhack MongoDB 2011
 
London MongoDB User Group April 2011
London MongoDB User Group April 2011London MongoDB User Group April 2011
London MongoDB User Group April 2011
 
MongoDB
MongoDBMongoDB
MongoDB
 
CouchDB Open Source Bridge
CouchDB Open Source BridgeCouchDB Open Source Bridge
CouchDB Open Source Bridge
 
Dynamic SQL in doobie
Dynamic SQL in doobieDynamic SQL in doobie
Dynamic SQL in doobie
 
Vanilla JS*
Vanilla JS*Vanilla JS*
Vanilla JS*
 
Getting Started With #Drools 6 Slides - JBUG Denmark
Getting Started With #Drools 6 Slides - JBUG DenmarkGetting Started With #Drools 6 Slides - JBUG Denmark
Getting Started With #Drools 6 Slides - JBUG Denmark
 
nodecalgary1
nodecalgary1nodecalgary1
nodecalgary1
 
Mastering the MongoDB Javascript Shell
Mastering the MongoDB Javascript ShellMastering the MongoDB Javascript Shell
Mastering the MongoDB Javascript Shell
 

Destaque

Patent Management Along Its Life Cycle
Patent Management Along Its Life CyclePatent Management Along Its Life Cycle
Patent Management Along Its Life Cycle
Hsien-Yung Yi
 
洪毅昕Openmic 理念說明
洪毅昕Openmic 理念說明洪毅昕Openmic 理念說明
洪毅昕Openmic 理念說明
宜璇 蔡
 
創人物Vol.1 - 兩分鐘自我介紹
創人物Vol.1 - 兩分鐘自我介紹創人物Vol.1 - 兩分鐘自我介紹
創人物Vol.1 - 兩分鐘自我介紹
交點
 
英文面試自我介紹
英文面試自我介紹英文面試自我介紹
英文面試自我介紹
Hsien-Yung Yi
 

Destaque (11)

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

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

Morphia: Simplifying Persistence for Java and MongoDB
Morphia:  Simplifying Persistence for Java and MongoDBMorphia:  Simplifying Persistence for Java and MongoDB
Morphia: Simplifying Persistence for Java and MongoDB
Jeff Yemin
 
Buildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbBuildingsocialanalyticstoolwithmongodb
Buildingsocialanalyticstoolwithmongodb
MongoDB APAC
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptThe Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
Hazelcast
 
Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDB
MongoDB
 

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

Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
Morphia: Simplifying Persistence for Java and MongoDB
Morphia:  Simplifying Persistence for Java and MongoDBMorphia:  Simplifying Persistence for Java and MongoDB
Morphia: Simplifying Persistence for Java and MongoDB
 
Back to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBBack to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDB
 
Buildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbBuildingsocialanalyticstoolwithmongodb
Buildingsocialanalyticstoolwithmongodb
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Using YQL Sensibly - YUIConf 2010
Using YQL Sensibly - YUIConf 2010Using YQL Sensibly - YUIConf 2010
Using YQL Sensibly - YUIConf 2010
 
Experiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the DatabaseExperiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the Database
 
How to React Native
How to React NativeHow to React Native
How to React Native
 
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptThe Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
 
RESTFul development with Apache sling
RESTFul development with Apache slingRESTFul development with Apache sling
RESTFul development with Apache sling
 
Persitance Data with sqlite
Persitance Data with sqlitePersitance Data with sqlite
Persitance Data with sqlite
 
A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaSimplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with Morphia
 
Webinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB AppWebinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB App
 
Webinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBWebinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDB
 
Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDB
 
Who's afraid of front end databases
Who's afraid of front end databasesWho's afraid of front end databases
Who's afraid of front end databases
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
 
JS Essence
JS EssenceJS Essence
JS Essence
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

最近 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!