Node.jsがJVMにやってきた

- Introduction of Nodyn -

東京Node学園 12時限目 #thg12

@grimrose

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

東京Node学園祭2013 に参加してきました #nodefest

話すこと

Nodynって何?

Nodyn

is a node.js compatible framework, running on the JVM powered by the DynJS Javascript runtime running under vert.x

nodyn.io

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.io

Nodyn

DynJS

+

lang-dynjs

+

Vert.x

DynJS

is an ECMAScript runtime for the JVM.

dynjs.org

Vert.xって何?

Vert.x

is a lightweight, high performance application platform for the JVM that's designed for modern mobile, web, and enterprise applications.

vertx.io

Vert.x がいいね!

(第1回:入門する)

http://acro-engineer.hatenablog.com/entry/2013/08/10/131203

written by@muraken720

An Introduction to Vert.x from Acroquest Technology

Nettyって何?

Netty

is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients.

netty.io

Netty

Finagle

Play Framework

Vert.x

etc...

Nettyの基本

http://d.hatena.ne.jp/fatrow/20110208/netty

Netty 入門 - 「Netty ベース」の何かに着手する前に from Takuma SHIRAISHI
Nettyらへん from Go Tanaka

Reactive Streams

www.reactive-streams.org

詳しくは

非同期ストリーム処理の標準化を目指す "Reactive Streams" とは

http://okapies.hateblo.jp/entry/2014/04/20/212821

Vert.x

JavaScript

…その前に

JavaとJavaScript

java javascript 違い

JavaScript on JVM

Java書けるんなら当然JavaScript呼び出せるよね?

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');");
    }
}

http://d.hatena.ne.jp/Nagise/20140227/1393500657

New Feature Of Java SE 8 from Oracle Fusion Middleware

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');

http://nodejs.org

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');

http://vertx.io/core_manual_js.html#writing-http-servers

Node.jsとどう違うの?

Node.js API Compatibility

Nodyn Completion of the Node.js API

Node.jsのpure JavaScriptのコードは、そのまま利用している

Cを使ったモジュールについては、Javaで書き直している

http://nodyn.io/compatibility/

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');

http://nodejs.org

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

vertx run demo_server.js

Hello NoDyn!

ご清聴

ありがとうございました。