Node.jsがJVMにやってきた
- Introduction of Nodyn -
東京Node学園 12時限目 #thg12
import groovy.json.*
def json = new JsonBuilder()
json {
自己紹介 {
"@grimrose" {
好きな言語 "Groovy"
好きなIDE "IntelliJ IDEA"
コミュニティ "Yokohama.groovy", "#yokohamagroovy"
}
}
}
println StringEscapeUtils.unescapeJava(json.toPrettyString())
groovyconsole.appspot.com
東京Node学園祭2013
Nodyn.io使ってたりJXCore試してみた、って人いたら教えてもらいたい https://t.co/LkxbDwGqpW
— Yosuke FURUKAWA (@yosuke_furukawa) 2014, 3月 4
話すこと
- Nodyn
- Vert.x
- Netty
- Node.js API
- Demo
Nodynって何?
Nodyn
is a node.js compatible framework, running on the JVM powered by the DynJS Javascript runtime running under vert.x
Nodyn
Imagine running your Node.js app on the JVM with clean, clear access to Java directly in your Javascript. All that with vert.x's powerful clustering technology built right in.
Nodyn
DynJS
+
lang-dynjs
+
Vert.x
DynJS
is an ECMAScript runtime for the JVM.
Vert.xって何?
Vert.x
is a lightweight, high performance application platform for the JVM that's designed for modern mobile, web, and enterprise applications.
Vert.x がいいね!
(第1回:入門する)
http://acro-engineer.hatenablog.com/entry/2013/08/10/131203
written by@muraken720
Nettyって何?
Netty
is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients.
Netty
etc...
Nettyの基本
Reactive Streams
詳しくは
非同期ストリーム処理の標準化を目指す "Reactive Streams" とは
Vert.x
と
JavaScript
…その前に
JavaとJavaScript
JavaScript on JVM
Java書けるんなら当然JavaScript呼び出せるよね?
import javax.script.*;
public class Sample {
public static void main(String[] args) throws ScriptException {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
engine.eval("println('Hello Script API');");
}
}
JavaScript Runtime
for Vert.x
DynJS
Rhino (Java 6, 7)
Nashorn (Java 8 ~)
e.g. Web Server
Node.js Web Server
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
Vert.x Web Server
var vertx = require('vertx');
vertx.createHttpServer().requestHandler(function(req) {
req.response.headers['Content-Type'] = "text/plain";
req.response.statusCode(200).end("Hello World");
}).listen(8080, 'localhost');
Node.jsとどう違うの?
Node.js API Compatibility
Nodyn Completion of the Node.js API
Node.jsのpure JavaScriptのコードは、そのまま利用している
Cを使ったモジュールについては、Javaで書き直している
Complete
Assert
DNS
Events
Modules
Path
Punycode
Query Strings
STDIO
Stream
Timers
UDP/Datagram
URL
Utilities
Complete but ...
HTTP(詳細)
Net(詳細)
Globals
In progress
Buffer(詳細)
Crypto
File System
Other
C Addons
Child Processes
Cluster
Debugger
Domain
HTTPS
OS(詳細)
Process
Readline
REPL
String Decoder
TLS/SSL
TTY
VM
ZLIB
Demo
demo_server.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
node demo_server.js
Hello World
langs.properties
#// 一行で
nodejs=org.projectodd~nodyn-verticle~0.1.1-SNAPSHOT\
:org.projectodd.nodyn.NodeJSVerticleFactory
#// .jsと.coffeeをnodynで使う
.js=nodejs
.coffee=nodejs