/
index.html
562 lines (399 loc) · 18 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>JRuby - introduction (srug)</title>
<link rel="stylesheet" href="./css/reset.css" type="text/css"/>
<link rel="stylesheet" href="./css/showoff.css" type="text/css"/>
<script type="text/javascript" src="./js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="./js/jquery.cycle.all.js"></script>
<script type="text/javascript" src="./js/jquery-print.js"></script>
<script type="text/javascript" src="./js/jquery.batchImageLoad.js"></script>
<script type="text/javascript" src="./js/jquery.doubletap-0.1.js"></script>
<script type="text/javascript" src="./js/fg.menu.js"></script>
<script type="text/javascript" src="./js/showoff.js"></script>
<script type="text/javascript" src="./js/jTypeWriter.js"> </script>
<script type="text/javascript" src="./js/sh_main.min.js"></script>
<script type="text/javascript" src="./js/core.js"></script>
<script type="text/javascript" src="./js/showoffcore.js"></script>
<link type="text/css" href="./css/fg.menu.css" media="screen" rel="stylesheet" />
<link type="text/css" href="./css/theme/ui.all.css" media="screen" rel="stylesheet" />
<link type="text/css" href="./css/sh_style.css" rel="stylesheet" >
<link rel="stylesheet" href="file/custom.css" type="text/css"/>
<script type="text/javascript" src="file/notes.js"></script>
<script type="text/javascript" src="file/jquery.tooltip.js"></script>
<script type="text/javascript">
$(function(){
setupPreso(false, './');
});
</script>
</head>
<body>
<a tabindex="0" href="#search-engines" class="fg-button fg-button-icon-right ui-widget ui-state-default ui-corner-all" id="navmenu"><span class="ui-icon ui-icon-triangle-1-s"></span>slides</a>
<div id="navigation" class="hidden"></div>
<div id="help">
<table>
<tr><td class="key">space, →</td><td>next slide</td></tr>
<tr><td class="key">←</td><td>previous slide</td></tr>
<tr><td class="key">d</td><td>debug mode</td></tr>
<tr><td class="key">## <ret></td><td>go to slide #</td></tr>
<tr><td class="key">c</td><td>table of contents (vi)</td></tr>
<tr><td class="key">f</td><td>toggle footer</td></tr>
<tr><td class="key">r</td><td>reload slides</td></tr>
<tr><td class="key">z</td><td>toggle help (this)</td></tr>
</table>
</div>
<div class="buttonNav">
<input type="submit" onClick="prevStep();" value="prev"/>
<input type="submit" onClick="nextStep();" value="next"/>
</div>
<div id="preso">loading presentation...</div>
<div id="footer">
<span id="slideInfo"></span>
<span id="debugInfo"></span>
</div>
<div id="slides" class="offscreen" style="display:none;">
<div class="slide" data-transition="none"><div class="content" ref="intro/intro/1">
<h1><strong>JRuby</strong></h1>
<h2>Introduction</h2>
<hr/>
<p style="text-align:center;"> Author: Marek Kowalcze</p>
<p style="text-align:center;"> from <a href="http://antennasoftware.com/">AntennaSoftware</a></p>
<p style="text-align:center;"> marek.kowalcze (at) gmail.com</p></div>
</div><div class="slide" data-transition="none"><div class="content" ref="intro/intro/2">
<h2><strong>Agenda</strong></h2>
<hr/>
<h3>History</h3>
<h3>Ruby - Java integration</h3>
<h3>Runtime</h3>
<h3>App Deployment</h3>
<h3>Future</h3></div>
</div><div class="slide" data-transition="none"><div class="content bullets incremental smaller" ref="intro/intro/3">
<h2><strong>The story of JRuby</strong></h2>
<hr/>
<ul>
<li>2001 - created by <strong>Jan Arne Petersen</strong></li>
<li>2006 - Rails support</li>
<li>2007 - JRuby 1.0</li>
<li>2009 - Engine Yard, Ruby 1.9, first <strong>JRubyConf</strong></li>
<li>2011 - Ruby 1.9.2, profiler, experimental C support</li>
<li>2011 - Book: <em>"Using JRuby: Bringing Ruby to Java"</em></li>
<li>2011 - 15 March - <strong>JRuby 1.6</strong></li>
</ul>
</div>
</div><div class="slide" data-transition="none"><div class="content" ref="intro/intro/4">
<h2><strong>Current core-team</strong></h2>
<hr/>
<h3>Charles Nutter, Thomas Enebo, Ola Bini, Nick Sieger</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/1">
<h2><strong>Why use JRuby?</strong></h2>
<hr/>
<h3>Performance</h3>
<h3>Native threads</h3>
<h3>Cross - platform</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/2">
<h2><strong>Why use JRuby?</strong></h2>
<hr/>
<h3>Ways to use legacy Java code base</h3>
<h3>Wrapping a Java library</h3>
<h3>Embedding JRuby in Java environment</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/3">
<h2><strong>Why use JRuby?</strong></h2>
<hr/>
<h3>Take Rails into the Enterprise ;)</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/4">
<h2><strong>Common scenarios</strong></h2>
<hr/>
<h3>Java backend + Rails deployed on Tomcat</h3>
<h3>ActiveModel wrappers around Java models (add DSL /improve API)</h3>
<h3>Development tools (testing, building, project management)</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/5">
<h2><strong>Possible disadvantages</strong></h2>
<hr/>
<h3>Requires more momory</h3>
<h3>Startup time</h3>
<h3>C extensions - work in progress</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/6">
<h2><strong>Ruby & Java integration</strong></h2></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/7">
<h2>Installation</h2>
<h3>RVM</h3>
<pre class="sh_bash"><code>rvm install jruby-1.6.0
rvm use jruby
ruby -v
# => jruby 1.6.0 (ruby 1.8.7 patchlevel 330)</code></pre>
<h3>System</h3>
<pre class="sh_bash"><code>sudo apt-get install jruby</code></pre>
<h3>Source</h3>
<pre class="sh_bash"><code>git clone https://github.com/jruby/jruby.git
ant</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/8">
<h2>Options</h2>
<pre class="sh_bash"><code>-J-Xmx512m Pass option to JVM
--profile run with profiler
--client use the non-optimizing "client" JVM
(improves startup; default)
--server use the optimizing "server" JVM
(improves performance)
--1.8 Ruby 1.8.x compatibility (default)
--1.9 Ruby 1.9.x compatibility</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/9">
<h2>1.9 compatibility</h2>
<pre class="sh_bash"><code>jruby --1.9 -e "sum = -> a, b { a + b }; p sum[2,3]"
# => 5
jruby -e "sum = -> a, b { a + b }; p sum[2,3]"
# => SyntaxError: -e:1: syntax error, unexpected tGT
sum = -> a, b { a + b }; puts sum[2,3]
^</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/10">
<h2><strong>Ruby & Java integration</strong></h2>
<hr/>
<h3>Loading classes</h3>
<h3>Using objects</h3>
<h3>Passing parameters</h3>
<h3>Overloaded methods</h3>
<h3>Java interfaces</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/11">
<h2>Setting Classpath</h2>
<h3>Env variable</h3>
<h3>From source</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/12">
<h2>Setting Classpath</h2>
<h3>Env variable</h3>
<pre class="sh_bash"><code>$ jruby -J-cp $CLASSPATH:/path/to/library.jar</code></pre>
<h3>From source</h3>
<pre class="sh_Ruby"><code>require 'java'
$CLASSPATH << '/path/to/library.jar'
# or..
require '/path/to/library.jar'
# or..
$LOAD_PATH << '/path/to'
require 'jemmy.jar'</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/13">
<h2>Loading classes</h2>
<h3>By namespaces</h3>
<h3>By importing</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/14">
<h2>Loading classes</h2>
<h3>By namespaces</h3>
<pre class="sh_Ruby"><code># common namespaces (com, org, java, and javax)
require 'java'
java.lang.StringBuffer
# default package (prepend Java::)
Java::MyTopLevelClass</code></pre>
<h3>By importing</h3>
<pre class="sh_Ruby"><code>StringBuffer = java.lang.StringBuffer
# shortcut:
java_import java.lang.StringBuffer
# alias
java_import 'java.lang.String' do |pckg, classname|
'JString'
end</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/15">
<h2>Using objects</h2></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/16">
<h2>Using objects</h2>
<h3>.. Java idioms translated into “the Ruby way”..</h3>
<pre class="sh_ruby"><code># java getters/setter => attrs accessors
user.setName('Matz')
user.name = 'Matz'</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/17">
<h2>Using objects</h2>
<h3>.. Java idioms translated into “the Ruby way”..</h3>
<pre class="sh_ruby"><code># camelCase => snake_case
java_import java.lang.System
System.currentTimeMillis
System.current_time_millis</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/18">
<h2>Using objects</h2>
<h3>.. Java idioms translated into “the Ruby way”..</h3>
<pre class="sh_ruby"><code># object construction
# new URL(String spec)
# new URL(String protocol, String host, String file)
URL.new 'http://srug.pl'
URL.new 'http' , 'srug.pl' , '/jruby'</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/19">
<h2>Passing parameters</h2></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/20">
<h2>Passing parameters</h2>
<h3>Basic Types</h3>
<pre class="sh_ruby"><code>String # => java.lang.String
Fixnum # => int / java.lang.Float / ...
Float # => float / java.lang.Double
NilClass # => null reference
Bignum # => java.math.BigInteger</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/21">
<h2>Passing parameters</h2>
<h3>Some Java code ...</h3>
<pre class="sh_java"><code>public class Dude {
public static String whatsMyType(Object o) {
return o.getClass().getName();
}
}</code></pre>
<h3>Check parameter type ...</h3>
<pre class="sh_ruby"><code>Dude.whats_my_type(['a', 'b'])
# => "org.jruby.RubyArray"
Dude.whats_my_type(['a', 'b'].to_java)
# => "[Ljava.lang.Object;"
['a','b'].to_java(:string).java_class.name
# => "[Ljava.lang.String;"</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/22">
<h2>Java interfaces</h2></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/23">
<h2>Java interfaces</h2>
<h3>Java</h3>
<pre class="sh_java"><code>static Callable<Object> callable(Runnable task);</code></pre>
<h3>Ruby</h3>
<pre class="sh_ruby"><code>require 'java'
java_import java.lang.Runnable
java_import java.util.concurrent.Executors
class Foo
include Runnable
def run
puts "Run!"
end
end
call_me = Executors.callable(Foo.new)
call_me.call</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="integration/integration/24">
<h2>Java interfaces</h2>
<h3>Java</h3>
<pre class="sh_java"><code>static Callable<Object> callable(Runnable task);</code></pre>
<h3>Ruby</h3>
<pre class="sh_ruby"><code>require 'java'
java_import java.lang.Runnable
java_import java.util.concurrent.Executors
# for single-methods i-faces
call_me = Executors.callable do
puts "Run!"
end
call_me.call</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="runtime/runtime/1">
<h2><strong>Runtime modes</strong></h2>
<hr/>
<h3>Interpreted</h3>
<h3>Just-in-time</h3>
<h3>Ahead-of-time</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="runtime/runtime/2">
<h2><strong>JIT</strong></h2>
<h3>Performance improves over time...</h3>
<pre class="sh_ruby"><code># performance.rb
require 'benchmark'
def expensive(i)
# very expensive computations...
end
5.times do
timing = Benchmark.measure do
1000.times { |i| expensive(i) }
end
puts timing
end</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="runtime/runtime/3">
<pre class="sh_bash"><code>jruby -J-Djruby.compile.mode=OFF performance.rb
0.086000 0.000000 0.086000 ( 0.052000)
0.023000 0.000000 0.023000 ( 0.023000)
0.012000 0.000000 0.012000 ( 0.012000)
0.013000 0.000000 0.013000 ( 0.013000)
jruby performance.rb
0.065000 0.000000 0.065000 ( 0.047000)
0.021000 0.000000 0.021000 ( 0.021000)
0.014000 0.000000 0.014000 ( 0.014000)
0.009000 0.000000 0.009000 ( 0.009000)</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="runtime/runtime/4">
<h2><strong>Write code to make use of JIT</strong></h2>
<hr/>
<h3>Try to not generate code at runtime</h3>
<h3>Create small methods</h3></div>
</div><div class="slide" data-transition="none"><div class="content bullets incremental smaller" ref="runtime/runtime/5">
<h1><strong>When to use AOT?</strong></h1>
<ul>
<li>System requires .class files</li>
<li>Hide source code</li>
<li>AOT is faster than JIT (Android)</li>
</ul>
</div>
</div><div class="slide" data-transition="none"><div class="content" ref="runtime/runtime/6">
<h2>JRuby AOT compiler</h2>
<pre class="sh_bash"><code>jrubyc program.rb # => Program.class
jrubyc --java program.rb # => Program.java
jrubyc --javac program.rb # => Program.java Program.class</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="runtime/runtime/7">
<h3>Using compiled Ruby class in ... Ruby ;)</h3>
<pre class="sh_ruby"><code># user.rb :
class User
def self.create(args={})
@args = args
end
end
# jrubyc user.rb => user.class
# other.rb:
require 'java'
require 'user' # will use user.class
User.create :name => 'Marek'</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="deployment/deployment/1">
<h2><strong>Application deployment</strong></h2></div>
</div><div class="slide" data-transition="none"><div class="content" ref="deployment/deployment/2">
<h2><strong>Warbler</strong></h2>
<h3>To package Rails(rack) app into WAR file</h3>
<pre class="sh_bash"><code>gem install warbler
warble executable war # => rails_app.war</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="deployment/deployment/3">
<h2><strong>Embedded servers</strong></h2>
<h3>Trinidad - A wrapper around Tomcat.</h3>
<h3>Mizuno - A wrapper around Jetty.</h3>
<h3>Aspen - A server based on Netty, a Java NIO framework.</h3>
<h3>TorqueBox - A server based on JBoss.</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="deployment/deployment/4">
<h2><strong>Platform as a service</strong></h2></div>
</div><div class="slide" data-transition="none"><div class="content" ref="deployment/deployment/5">
<h2><strong>App Engine</strong></h2>
<h3>Sinatra, Rails 2.3.x</h3>
<h3>DataMapper</h3>
<pre class="sh_bash"><code>gem install google-appengine</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="deployment/deployment/6">
<h2><strong>Amazon Elastic Beanstalk</strong></h2></div>
</div><div class="slide" data-transition="none"><div class="content" ref="deployment/deployment/7">
<h2><strong>Engine Yard</strong></h2></div>
</div><div class="slide" data-transition="none"><div class="content" ref="deployment/deployment/8">
<h2><strong>Heroku?</strong></h2>
<h3>Not yet... :(</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="future/future/1">
<h1><strong>Future of JRuby?</strong></h1></div>
</div><div class="slide" data-transition="none"><div class="content" ref="future/future/2">
<h2><strong>Mirah Project</strong></h2>
<h3>Mirah is a customizable programming language</h3>
<h3>featuring static types, local type inference</h3>
<h3>and a heavily Ruby-inspired syntax.</h3>
<h3>Mirah currently includes a typer/compiler backend for</h3>
<h3>the JVM which can output either JVM bytecode</h3>
<h3>or Java source files.</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="future/future/3">
<h2><strong>Mirah Project</strong></h2>
<h3>Statically-typed, object-oriented</h3>
<h3>Ruby-inspired syntax</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="future/future/4">
<h2><strong>Mirah Project</strong></h2>
<h3>The word “mirah” means “ruby” in Javanese,</h3>
<h3>the language of the island of Java</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="future/future/5">
<h2><strong>Mirah Project</strong></h2>
<pre class="sh_bash"><code>gem install mirah
mirah -e 'puts "Hello, Mirah!"'</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="future/future/6">
<h2><strong>Mirah Project</strong></h2>
<pre class="sh_ruby"><code>def foo(a:int = 1, b:int = 2)
puts a + b
end</code></pre></div>
</div><div class="slide" data-transition="none"><div class="content" ref="future/future/7">
<h2><strong>Where to start?</strong></h2>
<hr/>
<h3>http://www.jruby.org</h3>
<h3>https://github.com/jruby/jruby/wiki</h3>
<h3>http://blog.headius.com</h3></div>
</div><div class="slide" data-transition="none"><div class="content" ref="future/future/8">
<h2><strong>Thank You! :)</strong></h2></div>
</div>
</div>
</body>
</html>