JRuby on Appengine

4,392 views

Published on

A meetup talk given at budapest.rb http://www.meetup.com/budapest-rb/

Published in: Technology, News & Politics
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total views
4,392
On SlideShare
0
From Embeds
0
Number of Embeds
581
Actions
Shares
0
Downloads
23
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

JRuby on Appengine

  1. 1. budapest.rb JRuby on AppEngine Janos Hardi janos@liligo.com
  2. 2. Agenda JVM Scripting on the JVM JRuby Rack Google AppEngine/Java Experiences
  3. 3. JVM Java Language != Java Platform Platform Independence Rich Class System Open Source
  4. 4. JVM App App App JVM JVM JVM Java Runtime Environment
  5. 5. JVM http://www.artima.com/insidejvm/ed2/jvm2.html
  6. 6. JVM Fine tuneability Extensibility Stable Admin interfaces Safe code sharing
  7. 7. Scripting on the JVM Python (Jython - http://www.jython.org) Ruby (JRuby - http://www.jruby.org) Lisp (Clojure - http://clojure.org) JavaScript (Rhino - http://www.mozilla.org/rhino/) PHP (IBM - P8 / Caucho - Quercus) Scala (http://www.scala-lang.org) And many many more
  8. 8. Scripting on the JVM How?
  9. 9. Scripting on the JVM JSR-223 import javax.script.* http://scripting.dev.java.net/ http://developers.sun.com/scripting/
  10. 10. Scripting on the JVM App JRuby Scripting JVM Java Runtime Environment
  11. 11. Scripting on the JVM Why?
  12. 12. Scripting on the JVM Rapid app development Special needs, eg. at liligo.com ;) Integration
  13. 13. JRuby Ruby for Java Ruby in Java
  14. 14. JRuby Native Threads Garbage Collector Embeddability No fork No C extensions
  15. 15. Rack Rails, Merb, Sinatra, Camping, Ramaze ... CGI, FCGI, Mongrel, Thin, Webrick, Litespeed ...
  16. 16. Rack class HelloWorld def call(env) [200, {"Content-Type" => "text/plain"}, ["Hello world!"]] end end
  17. 17. Rack Simple Ruby API modelling HTTP Standard interface between frameworks and handlers Interface for injecting middlewares
  18. 18. Rack WSGI for Ruby http://chneukirchen.org/talks/#introducingrack http://wiki.github.com/rack/rack
  19. 19. JRuby-Rack WSGI for JRuby Rack + Java Servlet Containers Tomcat, Glassfish, Jetty ...
  20. 20. <context-param> <param-name>rackup</param-name> <param-value> require 'rubygems' require 'app' set :environment, :production set :run, false run Sinatra::Application </param-value> </context-param> <filter> <filter-name>RackFilter</filter-name> <filter-class>org.jruby.rack.RackFilter</filter-class> </filter> <filter-mapping> <filter-name>RackFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class> org.jruby.rack.RackServletContextListener </listener-class> </listener>
  21. 21. <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"> <context-param> <param-name>public.root</param-name> <param-value>/</param-value> </context-param> <filter> <filter-name>RackFilter</filter-name> <filter-class> org.jruby.rack.RackFilter </filter-class> </filter> <filter-mapping> <filter-name>RackFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class> org.jruby.rack.merb.MerbServletContextListener </listener-class> </listener> </web-app>
  22. 22. JRuby-Rack Framework R JRuby a c App k Servlet container JVM Java Runtime Environment
  23. 23. Google AppEngine/Java What?
  24. 24. Google AppEngine/Java App stack App hosting Development environment Great API system A bunch of services for free ...
  25. 25. GAE/J – App stack Automatic scaling Write your App only Everything else happens on APIs External APIs with URL Fetch
  26. 26. GAE/J – App hosting 10 app / google user Admin interface Cron Quota is OK Logging
  27. 27. GAE/J – App hosting
  28. 28. GAE/J – App hosting
  29. 29. GAE/J – App hosting
  30. 30. GAE/J – Dev environment App server Deployment App versions Multiple developer accounts Good examples SDK Plugins (Eclipse IDE)
  31. 31. GAE/J – APIs / Services Memcache Datastore Mail Image Google account URL Fetch
  32. 32. GAE/J - Datastore Schemaless Object oriented Key / Value Universal < Entity ( Story (1) ) >
  33. 33. Experiences Slow warmup (JRuby + AppEngine) Nice performance after App cache CPU intensive operations Almost unusable Dev tools Rare libs for GAE/J APIs No migration (bulk loader is 404!)
  34. 34. Experiences JRuby-AppEngine (low level wrapper for almost all APIs) Bumble (minimal lib for the Datastore) Datamapper (with JRuby-AppEngine) Warbler (for deployment)
  35. 35. JRuby-AppEngine post '/story/add' do @story = Datastore::Entity.new('Story') @story['title'] = params[:title] @story['slug'] = params[:slug] @story['body'] = Datastore::Text.new( params[:body] ) Datastore.put(@story) redirect '/stories' end
  36. 36. Bumble class Person include Bumble ds :given_name, :sur_name, :email has_many :blogs, Blog, :owner_id end class Blog include Bumble ds :name, :owner_id, :created_at belongs_to :owner, Person has_many :posts, :Post, :blog_id, :iorder => :created_at end class Post include Bumble ds :title, :content, :created_at, :blog_id belongs_to :blog, Blog end
  37. 37. Warbler Warbler::Config.new do |config| config.dirs = %w(lib views models) config.includes = FileList["appengine-web.xml", "app.rb", "config.ru"] config.gems = ['sinatra', 'haml','appengine- apis','maruku'] config.gem_dependencies = true config.war_name = "test" config.webxml.booter = :rack config.webxml.jruby.min.runtimes = 1 config.webxml.jruby.max.runtimes = 1 config.webxml.jruby.init.serial = true config.java_libs = [] end
  38. 38. Components Appengine account GAE/J SDK JRuby 1.3.1 JRuby-Rack Gems GAE/Merb Example Application ;) http://github.com/yaanno/gae-merb-example
  39. 39. Merb flat app WEB-INF appengine-web.xml web.xml application.rb config framework.rb init.rb lib appengine-api-sdk.jar gems.jar jruby-complete.jar jruby-rack.jar views index.haml
  40. 40. Thanks
  41. 41. A few useful links http://www.infoq.com/presentations/nicholson-php-jvm http://www.artima.com/insidejvm/ed2/index.html http://code.google.com/appengine/ http://blog.headius.com http://blog.nicksieger.com http://olabini.com/blog/ http://isitjruby.com/ http://code.google.com/events/io/sessions.html#appengine

×