jruby a pi and a database
DESCRIPTION
JRuby is a great way to use native Java libraries and get around the project overhead of Java, but how do you actually use Java from JRuby? This talk explores building a JRuby application, backed by the portable Java version of Couchbase Mobile. While JRuby is build to interface with Java, when calling out to JVM land there are all those little hurdles to overcome. Handling Strings correctly, using native Collection types, and interfacing with libraries which expect those native types instead of the ones provided by JRuby, and last but not least Implementing native interfaces to pass around. Oh and by the way all of this runs on a little Raspberry Pi!TRANSCRIPT
JRuby, a Pi and a Database
PHILIPP FEHRE
Twi3er: @ischi Github: @sideshowcoder Developer Advocate, Couchbase
It’s just ruby!
NaEve threads
99% vs 125% | 17 sec vs 11 sec Yes jruby startup Eme is slow …
And more
GC, Java Debugging tools, Java Servers…
-‐-‐dev tradeoff performance for startup @me
Lets see it in pracEce
Couchbase Lite
Couchbase Mobil
Couchbase Lite + Sync Gateway
Couchbase Mobil Couchbase Lite + Sync Gateway
Channels
Tags…
AuthenEcaEon
Facebook, Mozilla Persona, User + Password, OAuth
Sync FuncEon
Channels
AuthenEcaEon
Why JRuby?
NEED TO CALL TO JAVA Java has loads of libraries (like Couchbase Lite) which are only on Java
Pi on Couch
Using JRuby
Loading JARs
Loading naEve JARs
Just for reference… ;)
Calling Java Methods
Calling Java Methods
CreaEng Items in the database
Some Java Idioms
in Ruby
Naming
Se3er and Ge3er
Se3er and Ge3er
Se3er and Ge3er
Method names
Anonymous Classes
Java
Ruby way number 1
Ruby way number 2
GENERICS They don’t auto convert types
Se[ng up sync
Querying Couchbase Lite
Querying Couchbase Lite
Querying Couchbase Lite
Querying Couchbase Lite
LOOKING UNDER THE HOOD How JRuby is implemented
HACKING JRUBY CreaEng a method from Scratch
git clone h3ps://github.com/jruby/jruby
mvn -‐pBoostrap
Running the tests
1.to_froscon # => “froscon”
Adding to RubyFixnum
Couchbase Server 3.0 Beta Bug Bash Download, Find, Report, Win
• DOWNLOAD Couchbase Server 3.0 Beta
• Run some workload, play with it, FIND a bug
• If you find a bug, REPORT it! All bugs count – anything from correctness, to performance, to
usability, to docs
• WIN Prizes!!
h`p://www.couchbase.com/bugbash Contest ends Aug 31st 2014
QuesEons?
Links
• h3p://github.com/couchbaselabs/pi-‐on-‐couch • h3p://www.couchbase.com/communiEes • h3p://jruby.org