SlideShare une entreprise Scribd logo
1  sur  29
+   ×   n
Saturday, November 21, 2009
Scaling on App Engine
            with Ruby & Duby
            John Woodell
            Ryan Brown
            Nov 20, 2009




              2



Saturday, November 21, 2009
Google App Engine
              3



Saturday, November 21, 2009
What is Google App Engine?
            • A cloud-computing platform
            • Run your web apps on Google’s infrastructure
            • Platform as a Services (PaaS)




              4



Saturday, November 21, 2009
App Engine Architecture
                                                            Incoming Requests



                    Load                      App Engine     App Engine            App Engine
                   Balancer                    Front End      Front End             Front End




                                              AppServer      AppServer             AppServer



                                                                          Other Google
                              AppServer                                   Infrastructure

                                          API Layer                       - Bigtable

                                                                          - Google Accounts

                                                                          - Memcache
                                 App        App       App
                                                                          - Image manipulation


              5



Saturday, November 21, 2009
WhiteHouse.gov/openforquestions




              6



Saturday, November 21, 2009
Quotas and Billing
                     Resource       Provided Free      Additional Cost
                          CPU       6.5 hours/day        $0.10/hour


                  Bandwidth In       1GByte/day         $0.10/GByte

              Bandwidth Out          1GByte/day         $0.12/GByte

                  Stored Data           1 GB           $0.005/GB-day

                  Emails sent     2000/day to users    $0.0001/email
                                 50000/day to admins

              7



Saturday, November 21, 2009
Ruby on App Engine
              8



Saturday, November 21, 2009
Apps run on JRuby
           • Fast and portable
           • A wealth of integration options
           • Supported App Engine Java APIs




              9



Saturday, November 21, 2009
Small & Modular Frameworks
            • Rack
            • Sinatra
            • Merb/Rails3*
            • Duby




               * Currently unreleased

             10



Saturday, November 21, 2009
DataMapper for Persistence
            • Schema defined in your model
            • Extensions for validations, AR finders & more
            • Works with existing dm-appengine adapter




             11



Saturday, November 21, 2009
Easy to Install

                   sudo gem install google-appengine



                              Everything you need installs as gems


             12



Saturday, November 21, 2009
App Engine Gems
            • Development Gems
              – appengine-rack
              – appengine-tools [ appcfg.rb, dev_appserver.rb ]
              – appengine-sdk
              – appengine-jruby-jars
            • Runtime Gems
                  – appengine-rack
                  – dm-appengine
                  – appengine-apis




             13



Saturday, November 21, 2009
App Engine JRuby APIs
            • AppEngine::Users
            • AppEngine::Datastore
            • AppEngine::Memcache
            • AppEngine::Mail
            • AppEngine::URLFetch
            • AppEngine::Images
            • AppEngine::Logger
            • AppEngine::XMPP
            • AppEngine::Labs::TaskQueue




             14



Saturday, November 21, 2009
Simple XMPP Rack App




             15



Saturday, November 21, 2009
Demo

        run lambda { |env| [200, {}, 'Hello'] }




             16



Saturday, November 21, 2009
Current Issues with JRuby on App Engine
            • Several seconds to “spin-up” a new JRuby instance
            • Some gems still need their extensions ported to Java
            • Not officially supported




             17



Saturday, November 21, 2009
Introducing

                                Duby


Saturday, November 21, 2009
Duby’s not Ruby
            • Statically typed
            • No Duby runtime
            • Uses Java’s type system




             19



Saturday, November 21, 2009
Duby has Ruby-inspired Syntax

                         def fib(a:int)
                           if a < 2
                             a
                           else
                             fib(a - 1) + fib(a - 2)
                           end
                         end

                         puts fib 10

Saturday, November 21, 2009
// Generated from examples/Test.duby

           public class Test extends java.lang.Object {

                 public static void main(String[] argv) {
                   System.out.println(Test.fib(10));
                 }

                 public static int fib(int a) {
                   return (a < 2) ?
                       (a) :
                       ((Test.fib((a - 1)) + Test.fib((a - 2))));
                 }

           }


Saturday, November 21, 2009
A Simple Duby App
             import javax.servlet.http.HttpServlet
             import com.google.appengine.ext.duby.db.Model

             class Post < Model
               def initialize; end

               property title, String
               property body, Text
             end

             class DubyApp < HttpServlet
               def_edb(list, 'com/ribrdb/list.dhtml')

                  def doGet(request, response)
                    @posts = Post.all.run
                    response.getWriter.write(list)
                  end

               def doPost(request, response)
                 post = Post.new
                 post.title = request.getParameter('title')
                 post.body = Text.new(request.getParameter('body'))
                 post.save
                 doGet(request, response)
               end
             end


             22



Saturday, November 21, 2009
A Simple Duby App
             import javax.servlet.http.HttpServlet
             import com.google.appengine.ext.duby.db.Model

             class Post < Model
               def initialize; end

               property title, String
               property body, Text
             end                                          Types
             class DubyApp < HttpServlet           inferred from parent
               def_edb(list, 'com/ribrdb/list.dhtml')
                                                           class
                  def doGet(request, response)
                    @posts = Post.all.run
                    response.getWriter.write(list)
                  end

               def doPost(request, response)
                 post = Post.new
                 post.title = request.getParameter('title')
                 post.body = Text.new(request.getParameter('body'))
                 post.save
                 doGet(request, response)
               end
             end


             23



Saturday, November 21, 2009
A Simple Duby App
             import javax.servlet.http.HttpServlet
             import com.google.appengine.ext.duby.db.Model

             class Post < Model
               def initialize; end

               property title, String
               property body, Text
             end
                                                     Plugins
             class DubyApp < HttpServlet
               def_edb(list, 'com/ribrdb/list.dhtml')

                  def doGet(request, response)
                    @posts = Post.all.run
                    response.getWriter.write(list)
                  end

               def doPost(request, response)
                 post = Post.new
                 post.title = request.getParameter('title')
                 post.body = Text.new(request.getParameter('body'))
                 post.save
                 doGet(request, response)
               end
             end


             24



Saturday, November 21, 2009
Duby Supports Plugins
                 Only form of metaprogramming (for now)


             require 'erb'

             Duby::AST.defmacro('def_edb') do |duby, fcall, p|
               name = fcall.args_node.get(0).name
               path = fcall.args_node.get(1).value
               erb = ERB::Compiler.new(nil)
             ...
               src = erb.compile(IO.read(path))
               duby.eval(src, p, “(edb)”)
             end




Saturday, November 21, 2009
Duby Can Use erb Templates
               <title>Posts</title>
               <body>
                 <h1>All Posts:</h1>
                 <% for post in @posts %>
                   <h2><%= post.title %></h2>
                   <p><%= post.body.getValue %></p>
                 <% end %>
                 <hr>
                 <h1>New Post:</h1>
                 <form method=post>
                   Title: <input type=text name=title><br>
                   Body: <textarea name=body></textarea><br>
                   <input type=submit>
                 </form>
               </body>



Saturday, November 21, 2009
More to Come
            • Open classes
            • Mix ins
            • Blocks
            • More




             27



Saturday, November 21, 2009
Resources
            • Ryan Brown, ribrdb@google.com
               John Woodell, woodie@google.com
            • Google App Engine for JRuby
                  – http://code.google.com/p/appengine-jruby/
            • Google Group
              – http://groups.google.com/group/appengine-jruby
            • Blog: JRuby on App Engine Blog
              – http://jruby-appengine.blogspot.com/




             28



Saturday, November 21, 2009
+   ×   n
Saturday, November 21, 2009

Contenu connexe

Tendances

Aloha on-rails-2009
Aloha on-rails-2009Aloha on-rails-2009
Aloha on-rails-2009
John Woodell
 
Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...
Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...
Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...
manssandstrom
 
vSphere 5 - Image Builder and Auto Deploy
vSphere 5 - Image Builder and Auto DeployvSphere 5 - Image Builder and Auto Deploy
vSphere 5 - Image Builder and Auto Deploy
Eric Sloof
 
UCLUG TorqueBox - 03/08/2011
UCLUG TorqueBox - 03/08/2011UCLUG TorqueBox - 03/08/2011
UCLUG TorqueBox - 03/08/2011
tobiascrawley
 

Tendances (16)

GeekCamp SG 2009 - CouchApps with CouchDB
GeekCamp SG 2009 - CouchApps with CouchDBGeekCamp SG 2009 - CouchApps with CouchDB
GeekCamp SG 2009 - CouchApps with CouchDB
 
Ruby Plugins for Jenkins
Ruby Plugins for JenkinsRuby Plugins for Jenkins
Ruby Plugins for Jenkins
 
JRuby and You
JRuby and YouJRuby and You
JRuby and You
 
Gaelyk - Groovy Grails eXchange 2010 - Guillaume Laforge
Gaelyk - Groovy Grails eXchange 2010 - Guillaume LaforgeGaelyk - Groovy Grails eXchange 2010 - Guillaume Laforge
Gaelyk - Groovy Grails eXchange 2010 - Guillaume Laforge
 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projects
 
Aloha on-rails-2009
Aloha on-rails-2009Aloha on-rails-2009
Aloha on-rails-2009
 
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to ScalaLSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
 
Oscon 2010
Oscon 2010Oscon 2010
Oscon 2010
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
(ATS3-DEV08) Team Development with Accelrys Enterprise Platform
(ATS3-DEV08) Team Development with Accelrys Enterprise Platform(ATS3-DEV08) Team Development with Accelrys Enterprise Platform
(ATS3-DEV08) Team Development with Accelrys Enterprise Platform
 
Jrubykaigi 2010
Jrubykaigi 2010Jrubykaigi 2010
Jrubykaigi 2010
 
Get On The Audiobus (CocoaConf Atlanta, November 2013)
Get On The Audiobus (CocoaConf Atlanta, November 2013)Get On The Audiobus (CocoaConf Atlanta, November 2013)
Get On The Audiobus (CocoaConf Atlanta, November 2013)
 
Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...
Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...
Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...
 
vSphere 5 - Image Builder and Auto Deploy
vSphere 5 - Image Builder and Auto DeployvSphere 5 - Image Builder and Auto Deploy
vSphere 5 - Image Builder and Auto Deploy
 
UCLUG TorqueBox - 03/08/2011
UCLUG TorqueBox - 03/08/2011UCLUG TorqueBox - 03/08/2011
UCLUG TorqueBox - 03/08/2011
 
Make the code work for you with #git
Make the code work for you with #gitMake the code work for you with #git
Make the code work for you with #git
 

En vedette

Hadoop HDFS: The Ultimate Storage
Hadoop HDFS: The Ultimate StorageHadoop HDFS: The Ultimate Storage
Hadoop HDFS: The Ultimate Storage
SATOSHI TAGOMORI
 
Shib: WebUI tool provides crossover of Hive and MPP
Shib: WebUI tool provides crossover of Hive and MPPShib: WebUI tool provides crossover of Hive and MPP
Shib: WebUI tool provides crossover of Hive and MPP
SATOSHI TAGOMORI
 
Monitoring with Fluentd with fluent-plugin-notifier
Monitoring with Fluentd with fluent-plugin-notifierMonitoring with Fluentd with fluent-plugin-notifier
Monitoring with Fluentd with fluent-plugin-notifier
SATOSHI TAGOMORI
 
Log analysis with Hadoop in livedoor 2013
Log analysis with Hadoop in livedoor 2013Log analysis with Hadoop in livedoor 2013
Log analysis with Hadoop in livedoor 2013
SATOSHI TAGOMORI
 
Batch processing and Stream processing by SQL
Batch processing and Stream processing by SQLBatch processing and Stream processing by SQL
Batch processing and Stream processing by SQL
SATOSHI TAGOMORI
 

En vedette (20)

Using Google Cloud Infrastructure for twindly
Using Google Cloud Infrastructure for twindly Using Google Cloud Infrastructure for twindly
Using Google Cloud Infrastructure for twindly
 
O/R Mapper Stratumの話
O/R Mapper Stratumの話O/R Mapper Stratumの話
O/R Mapper Stratumの話
 
Hadoop HDFS: The Ultimate Storage
Hadoop HDFS: The Ultimate StorageHadoop HDFS: The Ultimate Storage
Hadoop HDFS: The Ultimate Storage
 
Shib: WebUI tool provides crossover of Hive and MPP
Shib: WebUI tool provides crossover of Hive and MPPShib: WebUI tool provides crossover of Hive and MPP
Shib: WebUI tool provides crossover of Hive and MPP
 
Fluentd in #tkrk10
Fluentd in #tkrk10Fluentd in #tkrk10
Fluentd in #tkrk10
 
Monitoring with Fluentd with fluent-plugin-notifier
Monitoring with Fluentd with fluent-plugin-notifierMonitoring with Fluentd with fluent-plugin-notifier
Monitoring with Fluentd with fluent-plugin-notifier
 
Retrospection / prospection and schema
Retrospection / prospection and schemaRetrospection / prospection and schema
Retrospection / prospection and schema
 
8 language deployments on GCE and GAE #gcpja
8 language deployments on GCE and GAE #gcpja8 language deployments on GCE and GAE #gcpja
8 language deployments on GCE and GAE #gcpja
 
Norikra in action
Norikra in actionNorikra in action
Norikra in action
 
Log analysis with Hadoop in livedoor 2013
Log analysis with Hadoop in livedoor 2013Log analysis with Hadoop in livedoor 2013
Log analysis with Hadoop in livedoor 2013
 
Log Analysis System And its designs in LINE Corp. 2014 early
Log Analysis System And its designs in LINE Corp. 2014 earlyLog Analysis System And its designs in LINE Corp. 2014 early
Log Analysis System And its designs in LINE Corp. 2014 early
 
Lambda Architecture Using SQL
Lambda Architecture Using SQLLambda Architecture Using SQL
Lambda Architecture Using SQL
 
Batch processing and Stream processing by SQL
Batch processing and Stream processing by SQLBatch processing and Stream processing by SQL
Batch processing and Stream processing by SQL
 
fluent-plugin-norikra #fluentdcasual
fluent-plugin-norikra #fluentdcasualfluent-plugin-norikra #fluentdcasual
fluent-plugin-norikra #fluentdcasual
 
Go lang introduction
Go lang introductionGo lang introduction
Go lang introduction
 
Railsconf 2010
Railsconf 2010Railsconf 2010
Railsconf 2010
 
Go Course Day2
Go Course Day2Go Course Day2
Go Course Day2
 
Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)
 
Fast Web Applications with Go
Fast Web Applications with Go Fast Web Applications with Go
Fast Web Applications with Go
 
About Go
About GoAbout Go
About Go
 

Similaire à RubyConf 2009

Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
catherinewall
 
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 20092009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
Caue Guerra
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Nilesh Panchal
 
Improving Your Heroku App Performance with Asset CDN and Unicorn
Improving Your Heroku App Performance with Asset CDN and UnicornImproving Your Heroku App Performance with Asset CDN and Unicorn
Improving Your Heroku App Performance with Asset CDN and Unicorn
Simon Bagreev
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
Nick Sieger
 
GR8Conf 2011: Adopting Grails
GR8Conf 2011: Adopting GrailsGR8Conf 2011: Adopting Grails
GR8Conf 2011: Adopting Grails
GR8Conf
 
Adopting Grails - GR8Conf Europe
Adopting Grails - GR8Conf EuropeAdopting Grails - GR8Conf Europe
Adopting Grails - GR8Conf Europe
KlausBaumecker
 

Similaire à RubyConf 2009 (20)

JRubyConf 2009
JRubyConf 2009JRubyConf 2009
JRubyConf 2009
 
Don Schwarz App Engine Talk
Don Schwarz App Engine TalkDon Schwarz App Engine Talk
Don Schwarz App Engine Talk
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
App Lego
App LegoApp Lego
App Lego
 
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureCloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
 
Practical JRuby
Practical JRubyPractical JRuby
Practical JRuby
 
JRuby - Programmer's Best Friend on JVM
JRuby - Programmer's Best Friend on JVMJRuby - Programmer's Best Friend on JVM
JRuby - Programmer's Best Friend on JVM
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 20092009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
 
Extending Spring for Custom Usage
Extending Spring for Custom UsageExtending Spring for Custom Usage
Extending Spring for Custom Usage
 
Play framework
Play frameworkPlay framework
Play framework
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
 
Developing Distributed Semantic Systems
Developing Distributed Semantic SystemsDeveloping Distributed Semantic Systems
Developing Distributed Semantic Systems
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
Improving Your Heroku App Performance with Asset CDN and Unicorn
Improving Your Heroku App Performance with Asset CDN and UnicornImproving Your Heroku App Performance with Asset CDN and Unicorn
Improving Your Heroku App Performance with Asset CDN and Unicorn
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
GR8Conf 2011: Adopting Grails
GR8Conf 2011: Adopting GrailsGR8Conf 2011: Adopting Grails
GR8Conf 2011: Adopting Grails
 
Adopting Grails - GR8Conf Europe
Adopting Grails - GR8Conf EuropeAdopting Grails - GR8Conf Europe
Adopting Grails - GR8Conf Europe
 

RubyConf 2009

  • 1. + × n Saturday, November 21, 2009
  • 2. Scaling on App Engine with Ruby & Duby John Woodell Ryan Brown Nov 20, 2009 2 Saturday, November 21, 2009
  • 3. Google App Engine 3 Saturday, November 21, 2009
  • 4. What is Google App Engine? • A cloud-computing platform • Run your web apps on Google’s infrastructure • Platform as a Services (PaaS) 4 Saturday, November 21, 2009
  • 5. App Engine Architecture Incoming Requests Load App Engine App Engine App Engine Balancer Front End Front End Front End AppServer AppServer AppServer Other Google AppServer Infrastructure API Layer - Bigtable - Google Accounts - Memcache App App App - Image manipulation 5 Saturday, November 21, 2009
  • 6. WhiteHouse.gov/openforquestions 6 Saturday, November 21, 2009
  • 7. Quotas and Billing Resource Provided Free Additional Cost CPU 6.5 hours/day $0.10/hour Bandwidth In 1GByte/day $0.10/GByte Bandwidth Out 1GByte/day $0.12/GByte Stored Data 1 GB $0.005/GB-day Emails sent 2000/day to users $0.0001/email 50000/day to admins 7 Saturday, November 21, 2009
  • 8. Ruby on App Engine 8 Saturday, November 21, 2009
  • 9. Apps run on JRuby • Fast and portable • A wealth of integration options • Supported App Engine Java APIs 9 Saturday, November 21, 2009
  • 10. Small & Modular Frameworks • Rack • Sinatra • Merb/Rails3* • Duby * Currently unreleased 10 Saturday, November 21, 2009
  • 11. DataMapper for Persistence • Schema defined in your model • Extensions for validations, AR finders & more • Works with existing dm-appengine adapter 11 Saturday, November 21, 2009
  • 12. Easy to Install sudo gem install google-appengine Everything you need installs as gems 12 Saturday, November 21, 2009
  • 13. App Engine Gems • Development Gems – appengine-rack – appengine-tools [ appcfg.rb, dev_appserver.rb ] – appengine-sdk – appengine-jruby-jars • Runtime Gems – appengine-rack – dm-appengine – appengine-apis 13 Saturday, November 21, 2009
  • 14. App Engine JRuby APIs • AppEngine::Users • AppEngine::Datastore • AppEngine::Memcache • AppEngine::Mail • AppEngine::URLFetch • AppEngine::Images • AppEngine::Logger • AppEngine::XMPP • AppEngine::Labs::TaskQueue 14 Saturday, November 21, 2009
  • 15. Simple XMPP Rack App 15 Saturday, November 21, 2009
  • 16. Demo run lambda { |env| [200, {}, 'Hello'] } 16 Saturday, November 21, 2009
  • 17. Current Issues with JRuby on App Engine • Several seconds to “spin-up” a new JRuby instance • Some gems still need their extensions ported to Java • Not officially supported 17 Saturday, November 21, 2009
  • 18. Introducing Duby Saturday, November 21, 2009
  • 19. Duby’s not Ruby • Statically typed • No Duby runtime • Uses Java’s type system 19 Saturday, November 21, 2009
  • 20. Duby has Ruby-inspired Syntax def fib(a:int) if a < 2 a else fib(a - 1) + fib(a - 2) end end puts fib 10 Saturday, November 21, 2009
  • 21. // Generated from examples/Test.duby public class Test extends java.lang.Object { public static void main(String[] argv) { System.out.println(Test.fib(10)); } public static int fib(int a) { return (a < 2) ? (a) : ((Test.fib((a - 1)) + Test.fib((a - 2)))); } } Saturday, November 21, 2009
  • 22. A Simple Duby App import javax.servlet.http.HttpServlet import com.google.appengine.ext.duby.db.Model class Post < Model def initialize; end property title, String property body, Text end class DubyApp < HttpServlet def_edb(list, 'com/ribrdb/list.dhtml') def doGet(request, response) @posts = Post.all.run response.getWriter.write(list) end def doPost(request, response) post = Post.new post.title = request.getParameter('title') post.body = Text.new(request.getParameter('body')) post.save doGet(request, response) end end 22 Saturday, November 21, 2009
  • 23. A Simple Duby App import javax.servlet.http.HttpServlet import com.google.appengine.ext.duby.db.Model class Post < Model def initialize; end property title, String property body, Text end Types class DubyApp < HttpServlet inferred from parent def_edb(list, 'com/ribrdb/list.dhtml') class def doGet(request, response) @posts = Post.all.run response.getWriter.write(list) end def doPost(request, response) post = Post.new post.title = request.getParameter('title') post.body = Text.new(request.getParameter('body')) post.save doGet(request, response) end end 23 Saturday, November 21, 2009
  • 24. A Simple Duby App import javax.servlet.http.HttpServlet import com.google.appengine.ext.duby.db.Model class Post < Model def initialize; end property title, String property body, Text end Plugins class DubyApp < HttpServlet def_edb(list, 'com/ribrdb/list.dhtml') def doGet(request, response) @posts = Post.all.run response.getWriter.write(list) end def doPost(request, response) post = Post.new post.title = request.getParameter('title') post.body = Text.new(request.getParameter('body')) post.save doGet(request, response) end end 24 Saturday, November 21, 2009
  • 25. Duby Supports Plugins Only form of metaprogramming (for now) require 'erb' Duby::AST.defmacro('def_edb') do |duby, fcall, p| name = fcall.args_node.get(0).name path = fcall.args_node.get(1).value erb = ERB::Compiler.new(nil) ... src = erb.compile(IO.read(path)) duby.eval(src, p, “(edb)”) end Saturday, November 21, 2009
  • 26. Duby Can Use erb Templates <title>Posts</title> <body> <h1>All Posts:</h1> <% for post in @posts %> <h2><%= post.title %></h2> <p><%= post.body.getValue %></p> <% end %> <hr> <h1>New Post:</h1> <form method=post> Title: <input type=text name=title><br> Body: <textarea name=body></textarea><br> <input type=submit> </form> </body> Saturday, November 21, 2009
  • 27. More to Come • Open classes • Mix ins • Blocks • More 27 Saturday, November 21, 2009
  • 28. Resources • Ryan Brown, ribrdb@google.com John Woodell, woodie@google.com • Google App Engine for JRuby – http://code.google.com/p/appengine-jruby/ • Google Group – http://groups.google.com/group/appengine-jruby • Blog: JRuby on App Engine Blog – http://jruby-appengine.blogspot.com/ 28 Saturday, November 21, 2009
  • 29. + × n Saturday, November 21, 2009