SlideShare a Scribd company logo
1
JRoRの力を
Java EEでさらに高める
10の方法
(発動編)
橋本 吉治
http://www.flickr.com/photos/shinyai/335249511/
Japan Java User Group
Japan JRuby User Group
卓球.rb
x.tokyo
@hasssieJJUG CCC 2010 Fall , 2010 18th Oct
HASHIMOTO Yoshiharu
2
自己紹介
はっし~~(@hasssie)
Rubyを愛するJava開発者
JJUG /JJRUG/ 卓球.rb
某SIer勤務http://www.flickr.com/photos/vs/186075406/
3
2010年3月16日 刊行!
4http://www.flickr.com/photos/rutlo/4574262003/
Agenda
1.JRubyとは
2.10の方法(本論)
3.JRubyのこれから
5
1.JRubyとは
http://www.flickr.com/photos/nicksieger/3750338433/
6
JRuby
• Rubyと100%の互換性を持
つRuby言語のJava実装
• 2010/10/18 現在、
最新版はJRuby1.5.3
7
Rails3 Ready
• Rails3.0は、Ruby1.8.7,
Ruby 1.9.2, JRuby1.5.2+
で動作するように設計
※ http://weblog.rubyonrails.org/2010/8/29/rails-3-0-it-s-done
8
Rails3については
松田さんの記事を!
9
Speed & Scalability
• Ruby1.9.2と同等の動作速度
• native thread の利用、JVMプロセス
中に複数のJRuby VMを埋め込める
• マルチコア対応?
• 参考
• JRubyConf2010資料, "Rails + 2(JRuby)", Nick Sieger,
http://bit.ly/njs-jrubyconf2010
10
事例
• CTC : IaaS Controller
• Oracle : Oracle Mix
• 社内SNS
• Sun→Oracle : Project Kenai
• OSS ソースコードホスティングサイト
などなど
JRubyのバイブル
12
成長する
JRubyコミュニティ
http://www.flickr.com/photos/nanagyei/5051441596/in/photostream/
13
Columbus, Ohio October 1–3, 2010
14
JRubyKaigi 2010
2010 28th Aug
in RubyKaigi
http://www.flickr.com/photos/shinyai/335249511/
15
Q. はっし~~の
JRuby界隈における
重要性
16
これくらい
http://www.flickr.com/photos/shinyai/335249511/
17「urekatのスカンク日記3」 より http://d.hatena.ne.jp/urekat/20100831
ナ
イ
ス
背
後
霊 by urekat
18http://www.flickr.com/photos/shinyai/335249511/
2.JRoRの力を
Java EEでさらに高める
10の方法
10things
1. Java build tool like Ant
2. Java App Server
3. JAX-WS API
4. JMS API
5. EJB
6. JDBC driver
7. JMX
8. Spring Framework
9. Java IDE
10. Java OSS library 19
20
21
エンタープライズ・システム
で大事なことを
考えてみた
Think about what
important things for
enterprise system
http://www.flickr.com/photos/marcinmoga/4572263486/in/photostream/
22
エンタープライズシステム
は多くのシステムが
連動して動く
Lots of systems are
connecting each other on
enterprise systems
23
JRoRシステムも
繋がらないと
JRoR system
must connect with
other systems
http://www.flickr.com/photos/yngrich/8828592/
2
4http://www.flickr.com/photos/marvinkuo/2153147300/
繋がるために大事な
7つのJava EE 技術を
紹介
7 things about
Java EE
for connecting each other
7things
1. Java build tool like Ant
2. App Server
3. JDBC driver
4. JAX-WS API
5. JMS API
6. EJB
7. JMX
8. Spring Framework
9. Java IDE
10. Java OSS library 25
26
about
Java build tool
like Ant
http://www.flickr.com/photos/shinyai/335249511/
困った
• 例えば、開発ツールはAntやMaven
といったJava製ビルドツールを使っ
たものがほとんど、とか
• 例えば、RubyのビルドツールはRake
だから、上記のようなJava資産は使
えない、とか
28
そんなあなたに
Rake/Antの統合
http://http://www.flickr.com/photos/pinksherbet/3038760752/
Rake/Ant統合
Rake←→Antの相互利用
require 'ant'
namespace :ant do
task :jar => :compile do
ant.jar :basedir => "." ,
:destfile => "baseball.jar" ,
:includes => "*.class" do
manifest do
attribute :name => "Main-Class" , :value => "Catcher"
end
end
end
end
RakeからAntを呼ぶ
30
そして、
Rake/mavenの統合
http://http://www.flickr.com/photos/pinksherbet/3038760752/
Rake/maven統合
<plugin>
<executions>
<execution>
<id> rspec </id>
<phase> test </phase>
<goals> <goal> rake </goal> </goals>
<configuration>
<script>
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new do |t|
t.spec_files = FileList['src/spec/ruby/**/*_spec.rb']
end
task :default => :spec
</script>
</configuration>
</execution>
</executions>
</plugin>
mavenからrakeを呼ぶ
32
about
Java App Server
http://www.flickr.com/photos/shinyai/335249511/
困った
• 例えば、某社の開発標準だとJava
App Serverしか導入できない、とか
• 例えば、我が社の運用標準だと運用監
視ツールがJava App Server前提に
なっている、とか
・・・このままでは、Railsの導入は難しい
34
そんなあなたに
warbler
http://http://www.flickr.com/photos/pinksherbet/3038760752/
warbler
• Railsアプリをwarにパッケージング
• これで、Java App Serverの
Webコンテナにデプロイ可能!
• web.xmlも利用可能
• なぜ、Railsアプリがwarとして動作
するの?
jruby-rack
Servlet層とRack層の
橋渡し
37
about
JDBC
http://www.flickr.com/photos/shinyai/335249511/
38http://www.flickr.com/photos/mulmatsherm/2221223106/in/ph
Java App Server の
コネクションプール
を使いたい
activerecord-jdbc
• JDBCとActiveRecord(O/R Mapper)
が組み合わせられる!
• 1.0.1の登場
• 対応DB
• MySQL SQLite3 PostgreSQL
Derby HSQLDB H2 DB2 SQLServer
Oracle Informix Sybase
40
JNDI経由で
コネクション
取得可能
http://http://www.flickr.com/photos/pinksherbet/3038760752/
41
ActiveRecord::Base.establish_connection(
:adapter => "jdbc",
:jndi => "jdbc/MySQL",
:driver => "com.mysql.jdbc.Driver",
:pool => 5
)
コネクションプーリングの仕組み
(JNDIを利用する場合)
Rails App
ActiveRecord process1-2
check out
App Server
Connection
Pool
ActiveRecord
Connection
Pool
disconnectcheck in
connect or
reconnect
connection connection
JNDI
DataSource
43
about JAX-WS・・・
http://www.flickr.com/photos/shinyai/335249511/
44
空前の SOAP ブーム
※エンタープライズシステム限定
The SOAP boom spread
like wildfire
just only on enterprise system
http://www.flickr.com/photos/usfwssoutheast/4642078354/
45
•SOAP Webサービス実装の安定化
•SOAでレガシー再構築という夢
•SOAPで繋げるクラウド基盤多数
• stabilize SOAP Web Service impl
• fantasy of restructuring of legacy
system using SOA
• SOAP connect with cloud computing
base
46
Rails+SOAP
Railsは、SOAPを捨てた
RubyとXMLの相性が「よい」とはいえない
Rails dump SOAP;
not get along with Ruby and
XML REXML
47
JRoR
JAX-WS
+
http://http://www.flickr.com/photos/pinksherbet/3038760752/
48
メリット
JAX-WSは扱いやすく、比較的高速
NetBeansなどツールサポートが手厚い
JAX-WS is easy to use,
faster to access and have lots of
support tools like NetBeans.
49
STEP1: WSDLからコード生成してjarに固める
STEP2: 下記のコードを書く
Step1: generate from WSDL and pack into jar
Step2: write code as follows;
require 'java'
require 'jar/UsersManagerWSClient'
import ‘ws.client.UsersManagerService’
class UsersManager
def initialize
@service =
UsersManagerService.new.get_users_manager_port
end
def find(user_id); transform(@service.find(user_id.to_s)); end
private
def transform(jobj)
# Java オブジェクト ⇒ Rubyオブジェクトの変換
end
end
50
JAXBは便利♪
http://http://www.flickr.com/photos/pinksherbet/3038760752/
51
Step1: XMLスキーマを設計
Step2: xjcコマンドを使ってJavaクラスの生成
Step3:下記のコードを書く
Step1: Design XML schema
Step2: generate Java class using xjc command
Step3: write code above
def unmarshal
ctx = JAXBContext.newInstance("net.pkg.class")
um = ctx.createUnmarshaller()
gbc = (GeneratedBindingClass) um.unmarshal(file)
xmlVal = gbc.getXMLValueOfInterest()
end
52
about
JMS・・・
http://www.flickr.com/photos/shinyai/335249511/
53
RailsからMoMを使いたい
安定した非同期通信基盤を使いたい
M1・・・・ M2Mn
Message oriented Middleware
Rails other system
want to use MoM from Rails,
want to use stable
async-messaging base
54
非同期通信のメリット
ユーザーにいち早く応答できる
他システム連携が容易
the merit of async-messaging
prompt response to users
easy to collaborate other systems
JRoR
other
systems
time
message
55
Rails+非同期通信
AP4R、ActiveMessagingなどがあるが、WMQ
など安定した基盤を使いたい
Rails + async-messaging
AP4R, ActiveMessaging ans so on...
But want to use stable base like WMQ
56
JRoR
JMS
+
http://http://www.flickr.com/photos/pinksherbet/3038760752/
57
メリット
JMSをサポートするMoMが多い
トランザクション処理が容易に書ける
ActiveMessagingもJMSをサポート
merit
Many MoMs support JMS
Easy to develop for transaction function
Also ActiveMessaging support JMS
例)メッセージ送信
ex) sending messages
EJB/Web Service ContainerJRoR
Java Application Server
Rails
Web App
Mongrel other systems
JMS client
59
STEP1.下記のコード or ActiveMessagingを使う
Step1: Use this code above or ActiveMessaging
import javax.jms.Session;
import javax.naming.InitialContext;
class UsersRegister
def initialize
@context = InitialContext.new
end
def regist(user, ut)
begin
cf = @context .lookup "jms/UsersRegisterQConFactory"
que = @context .lookup "jms/UsersRegisterQueue"
con = cf.create_queue_connection
qs =
con.create_queue_session(
false,
Session.AUTO_ACKNOWLEDGE
)
sender = qs.create_sender(que)
msg = qs.create_text_message
msg.set_text(create_msg(user))
sender.send(txt);
rescue
60
では、メッセージを
受け取るには?
http://www.flickr.com/photos/marcinmoga/4240686102/
Then how to receive
messages?
61
MDBで受信、RESTでJRoRへ
EJB/Web Service ContainerJRoR
Session Bean
Java Application Server
Rails
Web App
Message-driven
Bean
Web
Service
Mongrel other systems
SOAP client
REST I/F
MDB receive messages
and use REST to JRoR
62
about
EJB ・・・
http://www.flickr.com/photos/shinyai/335249511/
62
63
Railsから2pcを使いたい!
Rails App
other sytem2
process1-1process1
process1-2
other sytem1
2 phase commit = prepare(1) + commit(2)
want to use 2pc from Rails?
64
JRoR
EJB
+
http://http://www.flickr.com/photos/pinksherbet/3038760752/
65
メリット
XAを使った分散トランザクションが可能
トランザクション処理コードの複雑さが緩和
merit
can develop a distributed transaction
system using XA without any
complicated messy transaction code
66
典型的な使い方
typical usage
EJB
Java App Server
Rails App M1・・・・ M2Mn
MoM
other system
RDB
67
but,
でも、
68
こうやりたいよね
want to do like this way
Java App Server
M1・・・・ M2Mn
MoM
other systems
RDB
ActionController
ActiveRecord
JMS
same transaction
DataSourceJTA
war
web container
69
send queue with user transaction.
# POST /users
# POST /users.xml
def create
ut = InitialContext.new.lookup "UserTransaction“
@user = User.new(params[:user])
respond_to do |format|
begin
ut.begin # transaction begin
@user.save! # persist to RDB
send_queue(@user) # send queue
・・・
ut.commit; # transaction commit
end
rescue
ut.rollback # transaction rollback
・・・
70
Try it!
やってみよう!
71http://www.flickr.com/photos/proimos/4199675334/
failure... orz
失敗
72
理由(調査中)
『リソースマネージャが
グローバルトランザクションの外で作業中』
コネクション管理が別なのが原因か
Why?(consumption)
“The resource manager is doing work
outside a global transaction”
separate connection management
http://http://www.flickr.com/photos/anitakhart/4626206362/
73
about
SpringFramework
http://www.flickr.com/photos/shinyai/335249511/
74
about
SpringFramework
http://www.flickr.com/photos/shinyai/335249511/
75http://www.flickr.com/photos/proimos/4199675334/
ママン、やっぱり、
JTAが使いたいよ
76http://www.flickr.com/photos/proimos/4199675334/
失敗原因追及の
単体テスト環境も
ほしいよ
77http://http://www.flickr.com/photos/pinksherbet/3038760752/
はっし~~、がんばれ
そこでSeasar2 ♪
78
こうやりたいよね
M1・・・・ M2Mn
MoM
other systems
RDB
ActionController
ActiveRecord
JMS
same transaction
DataSourceJTA
S2Container
Passenger/Thin/Ngnix
Rails App
ActiveRecord process1-2
check out
S2Container
ActiveRecord
Connection
Pool
disconnectcheck in
connect or
reconnect
connection connection
JTA
DataSource
active-record-jdbc
ActiveS2
ActiveRecord
client
use
use UserTransaction
ActiveS2
manage
80
課題
• S2Containerの保持方法
• SingletonでDataSourceImplと
TransactionManagerImplを保持しておく。
• 複雑なコネクション管理の回避方法
• なんで、O/R Mapperとコネクションプーリング
機構が密結合なんだ・・・。
http://http://www.flickr.com/photos/anitakhart/4626206362/
81http://www.flickr.com/photos/vitroids/977380846/
鋭意開発中!
年末までには・・・
82http://www.flickr.com/photos/aussiegall/808040457/in/photostream/
3.JRubyの
これから
83
JRuby1.6の登場
• Native C 拡張
• CRubyの拡張APIをJNI経由で提供
• Win32OLE
• Jacob拡張によるWindows Automation
• dynopt
• 実行時情報による動的最適化
• backtrace
• Java&Rubyスタックの混在バックトレース
• CRubyとの互換性の向上
などなど
84
conclusion
まとめ
85
JRubyとは
http://www.flickr.com/photos/nicksieger/3750338433/
86
成長する
JRubyコミュニティ
http://www.flickr.com/photos/nanagyei/5051441596/in/photostream/
87
JRoRシステムも
繋がらないと
JRoR system
must connect with
other systems
http://www.flickr.com/photos/yngrich/8828592/
8
8http://www.flickr.com/photos/marvinkuo/2153147300/
繋がるために大事な
7つのJava EE 技術を
紹介
7 things about
Java EE
for connecting each other
89http://www.flickr.com/photos/shinyai/335249511/ 89
JRoRの力を
Java EEでさらに高める
10の方法
(発動編)
橋本 吉治 Japan Java User Group
Japan JRuby User Group
卓球.rb
x.tokyo
@hasssieJJUG CCC 2010 Fall , 2010 18th Oct
HASHIMOTO Yoshiharu

More Related Content

PDF
Public 20100828 j_ruby_kaigi_10things_jror_with_javaee
PDF
Jsug 20160422 slides
PDF
JavaScript.Next
PPTX
はじめてのSpring Boot
PDF
Spring Bootでチャットツールを作りながらWebの仕組みを理解しよう!
PDF
Spring3.1概要x di
PDF
Java SE 再入門
PPTX
Spring frameworkが大好きなおはなし
Public 20100828 j_ruby_kaigi_10things_jror_with_javaee
Jsug 20160422 slides
JavaScript.Next
はじめてのSpring Boot
Spring Bootでチャットツールを作りながらWebの仕組みを理解しよう!
Spring3.1概要x di
Java SE 再入門
Spring frameworkが大好きなおはなし

What's hot (20)

PPT
大ヒットソーシャルアプリの裏側
PDF
PHP in Java -Quercus- によるレガシーマイグレーション実例 #jjug_ccc #ccc_r12
PDF
WildFly Swarm In Progress
PPTX
Seasar2で作った俺たちのサービスの今
PDF
Java EEの話(仮)
PDF
自宅で出来る!ゲームサーバの作り方
PDF
Introduction to WildFly Swarm #jjug
PDF
Java EE 再入門
PDF
JJUGナイトセミナー オープンソースポータルLiferayの紹介とLiferay IDEを使った簡単ポートレット開発
PDF
Lampで作るソーシャルアプリの負荷対策~アプリとインフラの調和のテクニック~
PDF
Introduction to WildFly Swarm
PDF
2015/11/15 Javaでwebアプリケーション入門
PDF
React.js + Flux入門 #scripty02
PPTX
PPTX
初心者向け負荷軽減のはなし
PDF
SpringMVC
PDF
MySQLの冗長化 2013-01-24
PDF
Mroongaを選んだ理由と
ちょっと嬉しかった話
PDF
スマートフォン向けサービスにおけるサーバサイド設計入門
PDF
WildFly Swarm - Rightsize Your Java EE Apps
大ヒットソーシャルアプリの裏側
PHP in Java -Quercus- によるレガシーマイグレーション実例 #jjug_ccc #ccc_r12
WildFly Swarm In Progress
Seasar2で作った俺たちのサービスの今
Java EEの話(仮)
自宅で出来る!ゲームサーバの作り方
Introduction to WildFly Swarm #jjug
Java EE 再入門
JJUGナイトセミナー オープンソースポータルLiferayの紹介とLiferay IDEを使った簡単ポートレット開発
Lampで作るソーシャルアプリの負荷対策~アプリとインフラの調和のテクニック~
Introduction to WildFly Swarm
2015/11/15 Javaでwebアプリケーション入門
React.js + Flux入門 #scripty02
初心者向け負荷軽減のはなし
SpringMVC
MySQLの冗長化 2013-01-24
Mroongaを選んだ理由と
ちょっと嬉しかった話
スマートフォン向けサービスにおけるサーバサイド設計入門
WildFly Swarm - Rightsize Your Java EE Apps
Ad

Similar to JRoRの力をJava EE技術を使ってさらに高める10の方法(発動編) (20)

PPT
JRuby on Rails
PDF
Jjug springセッション
PPT
JRuby on Rails on JBoss
PDF
Java Community Process(JCP)ミーティング
PPTX
Spring Rooで作るGWTアプリケーション
KEY
Real world rails
PDF
JavaとRubyのすてきな関係
KEY
JRubyで作るapiサーバー
PDF
Spring BootでHello Worldのその先へ
PPTX
Java EE8 Report
PPTX
Ruby on Rails を用いたWEBアプリケーションの開発
PDF
SpringOne 2GX 2014 参加報告 & Spring 4.1について #jsug
PDF
Perl Ocean
PDF
UnicastWS vol.1
PPTX
2013.01.18 G*Workshop GGX 2012 Report
PPTX
JavaOne 2016 Report for Java EE
PDF
20161119 java one-feedback_osaka
PDF
20161111 java one2016-feedback
PDF
Java による Web アプリケーションのプロトタイプのために最近使っている構成
PDF
どこよりも早い Spring Boot 1.2 解説 #渋谷Java
JRuby on Rails
Jjug springセッション
JRuby on Rails on JBoss
Java Community Process(JCP)ミーティング
Spring Rooで作るGWTアプリケーション
Real world rails
JavaとRubyのすてきな関係
JRubyで作るapiサーバー
Spring BootでHello Worldのその先へ
Java EE8 Report
Ruby on Rails を用いたWEBアプリケーションの開発
SpringOne 2GX 2014 参加報告 & Spring 4.1について #jsug
Perl Ocean
UnicastWS vol.1
2013.01.18 G*Workshop GGX 2012 Report
JavaOne 2016 Report for Java EE
20161119 java one-feedback_osaka
20161111 java one2016-feedback
Java による Web アプリケーションのプロトタイプのために最近使っている構成
どこよりも早い Spring Boot 1.2 解説 #渋谷Java
Ad

JRoRの力をJava EE技術を使ってさらに高める10の方法(発動編)