SlideShare une entreprise Scribd logo
1  sur  137
Télécharger pour lire hors ligne
JBoss
  Rules, Rails
JAOO, Australia, 2009
Sydney, Brisbane
Michael Neale
JBoss R&D
Red Hat Middleware




                        1
Michael Neale
R&D on Drools (rule engine).
Open source history (user -> fulltime
  developer).
Contribute to other jboss and non jboss
  projects
me on the web:

  www.michaelneale.net, twitter.com/michaelneale,
    michaelneale.blogspot.com


                            2
Agenda
•Doing more with less...
•But isn't java hard/slow?
•Quick introduction to Rails basics
•Setting up JBoss for Rails

•What are rules and why use them?
•Drools
                  3
More, with less
Does any one need to:
 Build apps of growing complexity
 Do it quicker and cheaper
 Cope with people changing their mind
 All the time
 At runtime
If not – you can go !
                    4
Drools:
 Logic and declarative programming for
   developers
 User friendly GUIs and management
   tools for the rest
 Allows controlled changes to business
   logic (even at runtime)




                  5
Rails
 Popular RESTful web-app framework
   (full stack)
 Runs just fine on the JVM
 Famous for productivity




                  6
Why the JVM?




        7
Its the platform..
Not the language !




                     8
9
A fan...


Oh that reminds me, twitter?




                  10
Languages

Ruby
Scala **
Groovy
Clojure
Java7????


            11
So not necessarily...
Big heavy and bloated
But it is a platform...




                     12
Introduction to
Ruby-on-Rails

       13
What is Rails?
Rails is a “lightweight”
MVC framework for
building websites in
Ruby.
           14
Rails MVC

•ActiveRecord for the models
• ERb templates for the view


•Simple ruby classes for the
  controllers

                15
ActiveRecord

Definitely is not
Hibernate, but works
well-enough.

           16
ActiveRecord
class Comment < ActiveRecord::Base

 belongs_to :post
 belongs_to :user

 validate_presence_of :text
 ...

end

                     17
ERb Templates
ERb allows snippets of
Ruby to be embedded
within HTML or other
templates.
             18
ERb Templates
<p>
There are <%= @post.comments.size %>
new comments since your last visit:
</p>

<% for comment in @post.comments %>
 <% div_for( comment ) do %>
  <%= comment.author.full_name %>
 <% end %>
<% end %>

                  19
ActionController
Your ActionController sub-
classes provides the logic
behind the pages and
forms.
            20
ActionController
class CommentsController < ApplicationController

 before_filter :load_post

 def create
  @comment = @post.comments.build( params[:comment] )
  ....
 end

 private

 def load_post
  @post = Post.find_by_slug( params[:slug] )
  redirect_to posts_url and return false unless @post
 end
end

                                 21
ActionController
                                                   Actions
class CommentsController < ApplicationController

 before_filter :load_post

 def create
  @comment = @post.comments.build( params[:comment] )
  ....
 end

 private

 def load_post
  @post = Post.find_by_slug( params[:slug] )
  redirect_to posts_url and return false unless @post
 end
end

                                 22
ActionController
                                                   Filters
class CommentsController < ApplicationController

 before_filter :load_post

 def create
  @comment = @post.comments.build( params[:comment] )
  ....
 end

 private

 def load_post
  @post = Post.find_by_slug( params[:slug] )
  redirect_to posts_url and return false unless @post
 end
end

                               23
Where’s the Java?
JRuby is a full and fast
Ruby interpreter built on
top of the Java Virtual
Machine.
            24
JRuby
JRuby is actively
developed by Charlie
Nutter, Thomas Enebo,
and others.
              25
Run Rails in the
JVM
After solving a few
issues, Rails runs
easily within most any
servlet container.
           26
Why JBoss, then?
•JBoss provides a perfectly nice servlet
  container.

•JBoss provides a whole lot more, too:
 •JMS
 • Transactions
 •Rules-Engine
 •Telecom
                  27
Rails is not enough
Rails is a great
solution...

    for the web.
              28
Beyond Rails
Apply the Ruby and
Rails philosophies to
enterprise-grade
services.
            29
Ruby is just a
syntax
Approach Ruby as just
another syntax for
driving JEE/JVM
technologies.
          30
Let’s get
started.



     31
Ingredients
    JDK6
    JBoss AS5
    JRuby
    Rails
    JBoss-Rails

          32
JDK6


• OpenJDK is very nice.

•Apple’s JDK6 works just
 fine.


             33
Install JBoss AS5.x

$ unzip jboss-5.0.1.GA-jdk6.zip
Archive: jboss-5.0.1.GA-jdk6.zip
  creating: jboss-5.0.1.GA/
  creating: jboss-5.0.1.GA/bin/
  ...



                  34
Set $JBOSS_HOME

$ cd jboss-5.0.1.GA

$ export JBOSS_HOME=$PWD

$ echo $JBOSS_HOME
/Users/mic/jboss-5.0.1.GA

              35
Install JRuby

$ unzip jruby-bin-1.2.0RC2.zip
Archive: jruby-bin-1.2.0RC2.zip
  creating: jruby-1.2.0RC2/
  creating: jruby-1.2.0RC2/bin/
  ...




                    36
Prefer JRuby


$ cd jruby-1.2.0RC2/
$ export JRUBY_HOME=$PWD
$ export
PATH=$JRUBY_HOME/bin:$PATH




               37
JRuby path
This pulls things like
rake and gem from
JRuby’s path instead of
C-Ruby’s.
            38
JBoss-Rails
                The Deployer


The first part of JBoss-
Rails is the deployer.

           39
JBoss-Rails
               The Deployer

The deployer makes
JBoss AS5 Rails-
aware.

          40
JBoss-Rails
                 The Deployer

Install it into the
server’s deployers/
directory

            41
Pick a Profile

AS5 provides several
configuration
profiles.
           42
The default profile


 $JBOSS_HOME/server/default/




             43
Drop in the
deployer




         44
(or copy it)


$ cp jboss-rails-deployer.jar 
 $JBOSS_HOME/server/default/deployers/




                   45
Remove ROOT.war


$ rm -Rf $JBOSS_HOME/server/*/deploy/ROOT.war/




                      46
JBoss-Rails
           jboss-rails-support

The second part of
JBoss-Rails is
application-support
library.
              47
JBoss-Rails
           jboss-rails-support


It goes right into your Rails
app.

   So we need a Rails app.

              48
Install Rails

$ gem install rails --version 2.2.2
Successfully installed   activesupport-2.2.2
Successfully installed   activerecord-2.2.2
Successfully installed   actionpack-2.2.2
Successfully installed   actionmailer-2.2.2
Successfully installed   activeresource-2.2.2
Successfully installed   rails-2.2.2
6 gems installed



                            49
Create an app
$ rails twiggl
  create
  create   app/controllers
  create   app/helpers
  create   app/models
  create   app/views/layouts
  create   config/environments
  create   config/initializers
  create   config/locales
  ...

                     50
Freeze Rails
$ rake rails:freeze:gems
Freezing to the gems for Rails 2.2.2
rm -rf vendor/rails
mkdir -p vendor/rails
cd vendor/rails
Unpacked gem: '/Users/bob/twiggl/vendor/rails/activesupport-2.2.2'
mv activesupport-2.2.2 activesupport
Unpacked gem: '/Users/bob/twiggl/vendor/rails/activerecord-2.2.2'
mv activerecord-2.2.2 activerecord
Unpacked gem: '/Users/bob/twiggl/vendor/rails/actionpack-2.2.2'
mv actionpack-2.2.2 actionpack
Unpacked gem: '/Users/bob/twiggl/vendor/rails/actionmailer-2.2.2'
mv actionmailer-2.2.2 actionmailer
Unpacked gem: '/Users/bob/twiggl/vendor/rails/activeresource-2.2.2'
mv activeresource-2.2.2 activeresource
Unpacked gem: '/Users/bob/twiggl/vendor/rails/rails-2.2.2'
cd -



                                      51
Why freeze?
Relying on system-wide
gems is a bad idea, and
impossible with JBoss-
Rails.
           52
JBoss-Rails
           jboss-rails-support

Now we can install the
application-support
library.

              53
JBoss-Rails
                       jboss-rails-support
$ cd vendor/plugins/
$ unzip ~/downloads/jboss-rails-support.zip
Archive: /Users/bob/downloads/jboss-rails-support.zip
  creating: jboss-rails-support/
  creating: jboss-rails-support/lib/
  creating: jboss-rails-support/lib/jboss/
  creating: jboss-rails-support/lib/jboss/endpoints/
  creating: jboss-rails-support/lib/jboss/jobs/
  creating: jboss-rails-support/lib/recipes/
  creating: jboss-rails-support/lib/tasks/
 inflating: jboss-rails-support/init.rb
 .....




                               54
Apps need
a database.


       55
PostgresSQL




        56
Create the DB stuff
postgres> create user twiggl
       with password 'twiggl';
CREATE ROLE
postgres> create database
       twiggl_development
       with owner twiggl
       encoding 'UTF8';
CREATE DATABASE

                   57
Set up your app
                 config/database.yml

development:
 adapter: postgresql
 database: twiggl_development
 username: twiggl
 password: twiggl
 host: localhost
 encoding: UTF8

                58
Set up your app
                 config/database.yml

development:
 adapter: postgresql
   Just like
 database: twiggl_development
 username: twiggl

 regular Rails!
 password: twiggl
 host: localhost
 encoding: UTF8

                59
Database access

Rails on JBoss can take
advantage of JDBC
drivers.

           60
Easy JDBC
The jboss-rails-support
library makes it easy to
set up your Rails app for
JDBC.
            61
Install the JDBC
gems
$ rake jboss:gems:jdbc:install




                 62
Install the JDBC
gems       activerecord-jdbc
$ rake jboss:gems:jdbc:install
INFO: Installing activerecord-jdbc
   adapter-0.8.3




                        63
Install the JDBC
gems           the result




           64
You’re ready!
•AS5 is ready to serve Rails apps.
•A bare database is setup.
•A bare Rails app is setup.
 • Configured to access the database.

 •Using JDBC.
•Extra JBoss goodness is installed.
                 65
Deploying a Rails
App
The jboss-rails-
support rake tasks
handle deploying and
undeploying.
           66
From your app


$ rake jboss:rails:deploy
Deployed twiggl




                  67
Deployment Descriptor
  $JBOSS_HOME/server/default/deploy/twiggl-
                                   rails.yml



application:
 RAILS_ENV: development
 RAILS_ROOT: /Users/bob/twiggl
web:
 context: /



                    68
Wait, AS isn’t
running!

        69
Start AS
$ rake jboss:as:run
(in /Users/bob/twiggl)
JBoss-Rails server: /Users/bob/jboss-5.0.1.GA/server/default
=========================================================================

 JBoss Bootstrap Environment

 JBOSS_HOME: /Users/bob/jboss-5.0.1.GA

 JAVA: /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home//bin/java

 JAVA_OPTS: -Dprogram.name=run.sh -Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss. resolver.warning=true -Dsun.
rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000

 CLASSPATH: /Users/bob/preso/jboss-5.0.1.GA/bin/run.jar

=========================================================================

13:44:45,281   INFO   [ServerImpl]   Starting JBoss (Microcontainer)...
13:44:45,283   INFO   [ServerImpl]   Release ID: JBoss [Morpheus] 5.0.1.GA (build: SVNTag=JBoss_5_0_1_GA date=200902232048)
13:44:45,283   INFO   [ServerImpl]   Bootstrap URL: null
13:44:45,283   INFO   [ServerImpl]   Home Dir: /Users/bob/j boss-5.0.1.GA
13:44:45,283   INFO   [ServerImpl]   Home URL: file:/Users/bob/jboss-5.0.1.GA/
13:44:45,287   INFO   [ServerImpl]   Library URL: fi le:/Users/bob/jboss-5.0.1.GA/lib/
13:44:45,288   INFO   [ServerImpl]   Patch URL: null
13:44:45,288   INFO   [ServerImpl]   Common Base URL: fi le:/Users/bob/jboss-5.0.1.GA/common/
13:44:45,288   INFO   [ServerImpl]   Common Library URL: file:/Users/bob/jboss-5.0.1.GA/common/lib/
13:44:45,288   INFO   [ServerImpl]   Server Name: default
13:44:45,289   INFO   [ServerImpl]   Server Base Dir: /Users/bob/jboss-5.0.1.GA/server
13:44:45,289   INFO   [ServerImpl]   Server Base URL: file:/Users/bob/jboss-5.0.1.GA/server/
13:44:45,289   INFO   [ServerImpl]   Server Confi g URL: file:/Users/bob/jboss-5.0.1.GA/server/default/conf/
13:44:45,289   INFO   [ServerImpl]   Server Home Dir: /Users/bob/jboss-5.0.1.GA/server/default
13:44:45,289   INFO   [ServerImpl]   Server Home URL: file:/Users/bob/jboss-5.0.1.GA/server/default/



                                                                       70
localhost:8080/index.html




           71
Create models
$ jruby ./script/generate resource twig




                      72
Create models
$ jruby ./script/generate resource twig
  ...
  create   app/models/twig.rb




                            73
Create models
$ jruby ./script/generate resource twig
  ...
  create   app/models/twig.rb
  ...
  create   db/migrate/20090308180254_create_twigs.rb




                                74
Create models
$ jruby ./script/generate resource twig
  ...
  create app/models/twig.rb
  ...
  create db/migrate/20090308180254_create_twigs.rb
  ...
  create app/controllers/twigs_controller.rb




                           75
Create models
$ jruby ./script/generate resource twig
  ...
  create app/models/twig.rb
  ...
  create db/migrate/20090308180254_create_twigs.rb
  ...
  create app/controllers/twigs_controller.rb
  ...
   route map.resources :twigs




                           76
Create models
         db/migrate/*_create_twigs.rb
class CreateTwigs < ActiveRecord::Migration
 def self.up
   create_table :twigs do |t|
    t.string :name, :limit=>42, :null=>false
    t.timestamps
   end
 end

 def self.down
  drop_table :twigs
 end
end


                           77
Blow it into the DB

$ rake db:migrate
(in /Users/bob/twiggl)
== CreateTwigs: migrating
===============
-- create_table(:twigs)
   -> 0.0669s
   -> 0 rows
== CreateTwigs: migrated (0.0683s) ======



                     78
Rough in a controller
app/controllers/twigs_controller.rb

class TwigsController < ApplicationController

 def index
  @twigs = Twig.find( :all )
 end

end




                          79
Rough in a template
  app/views/twigs/index.html.erb
<p>
There are <%= @twigs.size %> twigs.
</p>

<% for twig in @twigs %>
 <% div_for( twig ) do %>
  <%= twig.name %>
 <% end %>
<% end %>

                   80
Rough in a template
  app/views/twigs/index.html.erb
<p>
There are <%= @twigs.size %> twigs.
</p>

<% for twig in @twigs %>
 <% div_for( twig ) do %>
  <%= twig.name %>
 <% end %>
<% end %>

                   81
Rough in a template
  app/views/twigs/index.html.erb
<p>
There are <%= @twigs.size %> twigs.
</p>

<% for twig in @twigs %>
 <% div_for( twig ) do %>
  <%= twig.name %>
 <% end %>
<% end %>

                   82
Hit it!




          83
We didn’t restart
AS.
And we didn’t redeploy
our app, either. That’s
okay, we’re hacking hot
code.
           84
Twig management
app/controllers/twigs_controller.rb
class TwigsController < ApplicationController

 def new
  @twig = Twig.new
 end

 def create
  @twig = Twig.create( params[:twig] )
  redirect_to @twig
 end

end

                          85
Twig form
    app/views/twigs/new.html.erb


<% form_for @twig do %>
 <%= label :twig, :name %>
 <%= text_field :twig, :name %>
 <%= submit_tag 'Create twig!' %>
<% end %>



                   86
Twig management
app/controllers/twigs_controller.rb

class TwigsController < ApplicationController

 def show
  @twig = Twig.find_by_id( params[:id] )
  redirect_to twigs_url unless @twig
 end

end




                          87
Twig view
  app/views/twigs/show.html.erb



<% div_for @twig do %>
 <h1><%= @twig.name %></h1>
<% end %>




               88
Create a twig




         89
Create a twig




         90
Back to the index




         91
It’s just like
regular Rails.

        92
Beyond Rails
But, we have the entire
freakin’ JBoss AS5
there.

         Let’s use it.
            93
Job scheduling
Sometimes you need
some code to fire on a
recurring basis, outside of
the web context.
            94
Job Scheduling

•Nightly batches
•Polling RSS
•Checking email

•Watching directories

                 95
Jobs
            app/jobs/**/*.rb




       96
Job class
            app/jobs/twitter_sender.rb
class TwitterSender < JBoss::Jobs::BaseJob

  def run
    new_twigs = Twig.find( :all,
                           :conditions=>[
                             'created_at >= ?',
                             Time.now - 30.minutes
                           ] )
    return if new_twigs.empty?
    tweet( new_twigs.size )
  end

  def tweet(num_new_twigs)
    ..
  end

end


                             97
Job schedule
                      config/jobs.yml



twitter.sender:
 description: Send a tweet
 cron: 0 */30 * * * ?
 job: TwitterSender



                 98
Job schedule
                      config/jobs.yml



twitter.sender:
 description: Send a tweet
 cron: 0 */30 * * * ?
 job: TwitterSender



                 99
Job schedule
                      config/jobs.yml



twitter.sender:
 description: Send a tweet
 cron: 0 */30 * * * ?
 job: TwitterSender



                100
Job schedule
                       config/jobs.yml



twitter.sender:
 description: Send a tweet
 cron: 0 */30 * * * ?
 job: TwitterSender



                 101
Job schedule
                       config/jobs.yml



twitter.sender:
 description: Send a tweet
 cron: 0 */30 * * * ?
 job: TwitterSender



                 102
Redeploy the app


$ rake jboss:rails:deploy




                 103
Why redeploy?
Jobs are deployed when
your app is deployed.
Adding a job means you
need to redeploy your
app.
            104
Ta-da!

[RubyJob] Starting Ruby job:
twiggl.twitter.sender

...

[STDOUT] twittering [1 new twigs!]



                    105
Hot, hot code
Once your job is
deployed, you can
continue to edit the
actual service method.
           106
No further
redeployment is
necessary, unless you
add jobs or alter the
schedule.
             107
Some More Possibilities
Message Queues (MQ/JMS)

Legacy/JCA integration

WS style web services...

              108
Ruby Databinding

JBoss-Rails provides
automatic databinding
to XMLSchema types.

          109
Ruby Databinding
When WS deployed, the
WSDL is examined and
real Ruby classes are
created.
           110
Shifting gears...




          111
What are rules?

Business rules

Declarative statements

Logic/reasoning

                 112
What are rules?
Capture domain expert
knowledge as
statements/assertions of truth
(aka: business rules)

               113
What are rules?


An executable knowledge base




             114
Drools
Drools provides a runtime,
compiler and tools to develop
and manage executable
knowledge bases

(all open source of course)
               115
For example:
rule “age and history compliance”
  when
    Driver(age < 25, sex=”M”)
    not Accident(severity > 3)
    not Infringement(type==”dui”)
  then
    approveDriver(“Let this one through”)
end


                    116
For example:
rule “age and history compliance”
  when
    Driver(age < 25, sex=”M”)
    not Accident(severity > 3)
    not Infringement(type==”dui”)
  then
    approveDriver(“Let this one through”)
end


                    117
For example:
rule “age and history compliance”
  when
    Driver(age < 25, sex=”M”)
    not Accident(severity > 3)
    not Infringement(type==”dui”)
  then
    approveDriver(“Let this one through”)
end


                    118
For example:
rule “age and history compliance”
  when
    Driver(age < 25, sex=”M”)
    not Accident(severity > 3)
    not Infringement(type==”dui”)
  then
    approveDriver(“Let this one through”)
end


                    119
For example:
rule “age and history compliance”
  when
    Driver(age < 25, sex=”M”)
    not Accident(severity > 3)
    not Infringement(type==”dui”)
  then
    approveDriver(“Let this one through”)
end


                    120
For example:
rule “age and history compliance”
  when
    Driver(age < 25, sex=”M”)
    not Accident(severity > 3)
    not Infringement(type==”dui”)
  then
    approveDriver(“Let this one through”)
end


                    121
For example:
rule “age and history compliance”
  when
    Driver(age < 25, sex=”M”)
    not Accident(severity > 3)
    not Infringement(type==”dui”)
  then
    approveDriver(“Let this one through”)
end


                    122
Why?
You have domain experts

The rules change

Anti-spaghetti

if else if else if else ...

                              123
124
125
126
127
The Guvnor..


Repository and Web interface



              128
129
130
131
132
133
134
How?

In process on the JVM

As a decision service


             135
Where?
Logistics (Fedex – talk at J1)

Insurance, risk, fraud etc..

All domains..


                136
Questions!
For more info:


Contact me: http://twitter.com/michaelneale


http://oddthesis.org/theses/jboss-rails/projects/jboss-rails


http://jboss.org/drools




                               137

Contenu connexe

Tendances

Developing Plug-Ins for NetBeans
Developing Plug-Ins for NetBeansDeveloping Plug-Ins for NetBeans
Developing Plug-Ins for NetBeans
elliando dias
 
Enabling White-Box Reuse in a Pure Composition Language
Enabling White-Box Reuse in a Pure Composition LanguageEnabling White-Box Reuse in a Pure Composition Language
Enabling White-Box Reuse in a Pure Composition Language
elliando dias
 

Tendances (20)

Java presentation
Java presentationJava presentation
Java presentation
 
The State of Java under Oracle at JCertif 2011
The State of Java under Oracle at JCertif 2011The State of Java under Oracle at JCertif 2011
The State of Java under Oracle at JCertif 2011
 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
 
Managed Beans: When, Why and How
Managed Beans: When, Why and HowManaged Beans: When, Why and How
Managed Beans: When, Why and How
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)
 
Java 9 Modularity and Project Jigsaw
Java 9 Modularity and Project JigsawJava 9 Modularity and Project Jigsaw
Java 9 Modularity and Project Jigsaw
 
Preparing your code for Java 9
Preparing your code for Java 9Preparing your code for Java 9
Preparing your code for Java 9
 
Head toward Java 14 and Java 15 #LINE_DM
Head toward Java 14 and Java 15 #LINE_DMHead toward Java 14 and Java 15 #LINE_DM
Head toward Java 14 and Java 15 #LINE_DM
 
Developing Plug-Ins for NetBeans
Developing Plug-Ins for NetBeansDeveloping Plug-Ins for NetBeans
Developing Plug-Ins for NetBeans
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Enabling White-Box Reuse in a Pure Composition Language
Enabling White-Box Reuse in a Pure Composition LanguageEnabling White-Box Reuse in a Pure Composition Language
Enabling White-Box Reuse in a Pure Composition Language
 
LUGOD Raspberry Pi Hacking
LUGOD Raspberry Pi HackingLUGOD Raspberry Pi Hacking
LUGOD Raspberry Pi Hacking
 
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3 Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
 
Head toward Java 14 and Java 15
Head toward Java 14 and Java 15Head toward Java 14 and Java 15
Head toward Java 14 and Java 15
 
Devoxx17 - Préparez-vous à la modularité selon Java 9
Devoxx17 - Préparez-vous à la modularité selon Java 9Devoxx17 - Préparez-vous à la modularité selon Java 9
Devoxx17 - Préparez-vous à la modularité selon Java 9
 
Migrating to Java 9 Modules
Migrating to Java 9 ModulesMigrating to Java 9 Modules
Migrating to Java 9 Modules
 
Java fx smart code econ
Java fx smart code econJava fx smart code econ
Java fx smart code econ
 
Sun Java EE 6 Overview
Sun Java EE 6 OverviewSun Java EE 6 Overview
Sun Java EE 6 Overview
 
JavaEE 6 tools coverage
JavaEE 6 tools coverageJavaEE 6 tools coverage
JavaEE 6 tools coverage
 
Leaner microservices with Java 10
Leaner microservices with Java 10Leaner microservices with Java 10
Leaner microservices with Java 10
 

Similaire à Jaoo Michael Neale 09

JBoss, Rails and the cloud
JBoss, Rails and the cloudJBoss, Rails and the cloud
JBoss, Rails and the cloud
elliando dias
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
Keith Bennett
 
Dynamic Languages & Web Frameworks in GlassFish
Dynamic Languages & Web Frameworks in GlassFishDynamic Languages & Web Frameworks in GlassFish
Dynamic Languages & Web Frameworks in GlassFish
IndicThreads
 

Similaire à Jaoo Michael Neale 09 (20)

Crank Up Your Apps With TorqueBox
Crank Up Your Apps With TorqueBoxCrank Up Your Apps With TorqueBox
Crank Up Your Apps With TorqueBox
 
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
 
JBoss, Rails and the cloud
JBoss, Rails and the cloudJBoss, Rails and the cloud
JBoss, Rails and the cloud
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
 
Real World Technologies
Real World TechnologiesReal World Technologies
Real World Technologies
 
Ruby on Rails workshop for beginner
Ruby on Rails workshop for beginnerRuby on Rails workshop for beginner
Ruby on Rails workshop for beginner
 
Practical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusPractical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobus
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
 
Capybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using rubyCapybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using ruby
 
JRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudJRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the Cloud
 
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 
BPMS1
BPMS1BPMS1
BPMS1
 
BPMS1
BPMS1BPMS1
BPMS1
 
Rails is Easy*
Rails is Easy*Rails is Easy*
Rails is Easy*
 
Dynamic Languages Web Frameworks Indicthreads 2009
Dynamic Languages Web Frameworks Indicthreads 2009Dynamic Languages Web Frameworks Indicthreads 2009
Dynamic Languages Web Frameworks Indicthreads 2009
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on Rails
 
Dynamic Languages & Web Frameworks in GlassFish
Dynamic Languages & Web Frameworks in GlassFishDynamic Languages & Web Frameworks in GlassFish
Dynamic Languages & Web Frameworks in GlassFish
 

Plus de Michael Neale

Plus de Michael Neale (16)

Jenkins X intro (from google app dev conference)
Jenkins X intro (from google app dev conference)Jenkins X intro (from google app dev conference)
Jenkins X intro (from google app dev conference)
 
Devoxx 2014 michael_neale
Devoxx 2014 michael_nealeDevoxx 2014 michael_neale
Devoxx 2014 michael_neale
 
Cd syd
Cd sydCd syd
Cd syd
 
Cross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORSCross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORS
 
Microservices and functional programming
Microservices and functional programmingMicroservices and functional programming
Microservices and functional programming
 
Cors michael
Cors michaelCors michael
Cors michael
 
Osdc 2011 michael_neale
Osdc 2011 michael_nealeOsdc 2011 michael_neale
Osdc 2011 michael_neale
 
Scala sydoct2011
Scala sydoct2011Scala sydoct2011
Scala sydoct2011
 
Java one 2011_michaelneale
Java one 2011_michaelnealeJava one 2011_michaelneale
Java one 2011_michaelneale
 
Errors and handling them. YOW nights Sydney 2011
Errors and handling them. YOW nights Sydney 2011Errors and handling them. YOW nights Sydney 2011
Errors and handling them. YOW nights Sydney 2011
 
Sjug aug 2010_cloud
Sjug aug 2010_cloudSjug aug 2010_cloud
Sjug aug 2010_cloud
 
SJUG March 2010 Restful design
SJUG March 2010 Restful designSJUG March 2010 Restful design
SJUG March 2010 Restful design
 
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
 
Osdc Complex Event Processing
Osdc Complex Event ProcessingOsdc Complex Event Processing
Osdc Complex Event Processing
 
Scala Sjug 09
Scala Sjug 09Scala Sjug 09
Scala Sjug 09
 
Osdc Michael Neale 2008
Osdc Michael Neale 2008Osdc Michael Neale 2008
Osdc Michael Neale 2008
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Jaoo Michael Neale 09

  • 1. JBoss Rules, Rails JAOO, Australia, 2009 Sydney, Brisbane Michael Neale JBoss R&D Red Hat Middleware 1
  • 2. Michael Neale R&D on Drools (rule engine). Open source history (user -> fulltime developer). Contribute to other jboss and non jboss projects me on the web: www.michaelneale.net, twitter.com/michaelneale, michaelneale.blogspot.com 2
  • 3. Agenda •Doing more with less... •But isn't java hard/slow? •Quick introduction to Rails basics •Setting up JBoss for Rails •What are rules and why use them? •Drools 3
  • 4. More, with less Does any one need to: Build apps of growing complexity Do it quicker and cheaper Cope with people changing their mind All the time At runtime If not – you can go ! 4
  • 5. Drools: Logic and declarative programming for developers User friendly GUIs and management tools for the rest Allows controlled changes to business logic (even at runtime) 5
  • 6. Rails Popular RESTful web-app framework (full stack) Runs just fine on the JVM Famous for productivity 6
  • 8. Its the platform.. Not the language ! 8
  • 9. 9
  • 10. A fan... Oh that reminds me, twitter? 10
  • 12. So not necessarily... Big heavy and bloated But it is a platform... 12
  • 14. What is Rails? Rails is a “lightweight” MVC framework for building websites in Ruby. 14
  • 15. Rails MVC •ActiveRecord for the models • ERb templates for the view •Simple ruby classes for the controllers 15
  • 16. ActiveRecord Definitely is not Hibernate, but works well-enough. 16
  • 17. ActiveRecord class Comment < ActiveRecord::Base belongs_to :post belongs_to :user validate_presence_of :text ... end 17
  • 18. ERb Templates ERb allows snippets of Ruby to be embedded within HTML or other templates. 18
  • 19. ERb Templates <p> There are <%= @post.comments.size %> new comments since your last visit: </p> <% for comment in @post.comments %> <% div_for( comment ) do %> <%= comment.author.full_name %> <% end %> <% end %> 19
  • 20. ActionController Your ActionController sub- classes provides the logic behind the pages and forms. 20
  • 21. ActionController class CommentsController < ApplicationController before_filter :load_post def create @comment = @post.comments.build( params[:comment] ) .... end private def load_post @post = Post.find_by_slug( params[:slug] ) redirect_to posts_url and return false unless @post end end 21
  • 22. ActionController Actions class CommentsController < ApplicationController before_filter :load_post def create @comment = @post.comments.build( params[:comment] ) .... end private def load_post @post = Post.find_by_slug( params[:slug] ) redirect_to posts_url and return false unless @post end end 22
  • 23. ActionController Filters class CommentsController < ApplicationController before_filter :load_post def create @comment = @post.comments.build( params[:comment] ) .... end private def load_post @post = Post.find_by_slug( params[:slug] ) redirect_to posts_url and return false unless @post end end 23
  • 24. Where’s the Java? JRuby is a full and fast Ruby interpreter built on top of the Java Virtual Machine. 24
  • 25. JRuby JRuby is actively developed by Charlie Nutter, Thomas Enebo, and others. 25
  • 26. Run Rails in the JVM After solving a few issues, Rails runs easily within most any servlet container. 26
  • 27. Why JBoss, then? •JBoss provides a perfectly nice servlet container. •JBoss provides a whole lot more, too: •JMS • Transactions •Rules-Engine •Telecom 27
  • 28. Rails is not enough Rails is a great solution... for the web. 28
  • 29. Beyond Rails Apply the Ruby and Rails philosophies to enterprise-grade services. 29
  • 30. Ruby is just a syntax Approach Ruby as just another syntax for driving JEE/JVM technologies. 30
  • 32. Ingredients JDK6 JBoss AS5 JRuby Rails JBoss-Rails 32
  • 33. JDK6 • OpenJDK is very nice. •Apple’s JDK6 works just fine. 33
  • 34. Install JBoss AS5.x $ unzip jboss-5.0.1.GA-jdk6.zip Archive: jboss-5.0.1.GA-jdk6.zip creating: jboss-5.0.1.GA/ creating: jboss-5.0.1.GA/bin/ ... 34
  • 35. Set $JBOSS_HOME $ cd jboss-5.0.1.GA $ export JBOSS_HOME=$PWD $ echo $JBOSS_HOME /Users/mic/jboss-5.0.1.GA 35
  • 36. Install JRuby $ unzip jruby-bin-1.2.0RC2.zip Archive: jruby-bin-1.2.0RC2.zip creating: jruby-1.2.0RC2/ creating: jruby-1.2.0RC2/bin/ ... 36
  • 37. Prefer JRuby $ cd jruby-1.2.0RC2/ $ export JRUBY_HOME=$PWD $ export PATH=$JRUBY_HOME/bin:$PATH 37
  • 38. JRuby path This pulls things like rake and gem from JRuby’s path instead of C-Ruby’s. 38
  • 39. JBoss-Rails The Deployer The first part of JBoss- Rails is the deployer. 39
  • 40. JBoss-Rails The Deployer The deployer makes JBoss AS5 Rails- aware. 40
  • 41. JBoss-Rails The Deployer Install it into the server’s deployers/ directory 41
  • 42. Pick a Profile AS5 provides several configuration profiles. 42
  • 43. The default profile $JBOSS_HOME/server/default/ 43
  • 45. (or copy it) $ cp jboss-rails-deployer.jar $JBOSS_HOME/server/default/deployers/ 45
  • 46. Remove ROOT.war $ rm -Rf $JBOSS_HOME/server/*/deploy/ROOT.war/ 46
  • 47. JBoss-Rails jboss-rails-support The second part of JBoss-Rails is application-support library. 47
  • 48. JBoss-Rails jboss-rails-support It goes right into your Rails app. So we need a Rails app. 48
  • 49. Install Rails $ gem install rails --version 2.2.2 Successfully installed activesupport-2.2.2 Successfully installed activerecord-2.2.2 Successfully installed actionpack-2.2.2 Successfully installed actionmailer-2.2.2 Successfully installed activeresource-2.2.2 Successfully installed rails-2.2.2 6 gems installed 49
  • 50. Create an app $ rails twiggl create create app/controllers create app/helpers create app/models create app/views/layouts create config/environments create config/initializers create config/locales ... 50
  • 51. Freeze Rails $ rake rails:freeze:gems Freezing to the gems for Rails 2.2.2 rm -rf vendor/rails mkdir -p vendor/rails cd vendor/rails Unpacked gem: '/Users/bob/twiggl/vendor/rails/activesupport-2.2.2' mv activesupport-2.2.2 activesupport Unpacked gem: '/Users/bob/twiggl/vendor/rails/activerecord-2.2.2' mv activerecord-2.2.2 activerecord Unpacked gem: '/Users/bob/twiggl/vendor/rails/actionpack-2.2.2' mv actionpack-2.2.2 actionpack Unpacked gem: '/Users/bob/twiggl/vendor/rails/actionmailer-2.2.2' mv actionmailer-2.2.2 actionmailer Unpacked gem: '/Users/bob/twiggl/vendor/rails/activeresource-2.2.2' mv activeresource-2.2.2 activeresource Unpacked gem: '/Users/bob/twiggl/vendor/rails/rails-2.2.2' cd - 51
  • 52. Why freeze? Relying on system-wide gems is a bad idea, and impossible with JBoss- Rails. 52
  • 53. JBoss-Rails jboss-rails-support Now we can install the application-support library. 53
  • 54. JBoss-Rails jboss-rails-support $ cd vendor/plugins/ $ unzip ~/downloads/jboss-rails-support.zip Archive: /Users/bob/downloads/jboss-rails-support.zip creating: jboss-rails-support/ creating: jboss-rails-support/lib/ creating: jboss-rails-support/lib/jboss/ creating: jboss-rails-support/lib/jboss/endpoints/ creating: jboss-rails-support/lib/jboss/jobs/ creating: jboss-rails-support/lib/recipes/ creating: jboss-rails-support/lib/tasks/ inflating: jboss-rails-support/init.rb ..... 54
  • 57. Create the DB stuff postgres> create user twiggl with password 'twiggl'; CREATE ROLE postgres> create database twiggl_development with owner twiggl encoding 'UTF8'; CREATE DATABASE 57
  • 58. Set up your app config/database.yml development: adapter: postgresql database: twiggl_development username: twiggl password: twiggl host: localhost encoding: UTF8 58
  • 59. Set up your app config/database.yml development: adapter: postgresql Just like database: twiggl_development username: twiggl regular Rails! password: twiggl host: localhost encoding: UTF8 59
  • 60. Database access Rails on JBoss can take advantage of JDBC drivers. 60
  • 61. Easy JDBC The jboss-rails-support library makes it easy to set up your Rails app for JDBC. 61
  • 62. Install the JDBC gems $ rake jboss:gems:jdbc:install 62
  • 63. Install the JDBC gems activerecord-jdbc $ rake jboss:gems:jdbc:install INFO: Installing activerecord-jdbc adapter-0.8.3 63
  • 64. Install the JDBC gems the result 64
  • 65. You’re ready! •AS5 is ready to serve Rails apps. •A bare database is setup. •A bare Rails app is setup. • Configured to access the database. •Using JDBC. •Extra JBoss goodness is installed. 65
  • 66. Deploying a Rails App The jboss-rails- support rake tasks handle deploying and undeploying. 66
  • 67. From your app $ rake jboss:rails:deploy Deployed twiggl 67
  • 68. Deployment Descriptor $JBOSS_HOME/server/default/deploy/twiggl- rails.yml application: RAILS_ENV: development RAILS_ROOT: /Users/bob/twiggl web: context: / 68
  • 70. Start AS $ rake jboss:as:run (in /Users/bob/twiggl) JBoss-Rails server: /Users/bob/jboss-5.0.1.GA/server/default ========================================================================= JBoss Bootstrap Environment JBOSS_HOME: /Users/bob/jboss-5.0.1.GA JAVA: /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home//bin/java JAVA_OPTS: -Dprogram.name=run.sh -Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss. resolver.warning=true -Dsun. rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 CLASSPATH: /Users/bob/preso/jboss-5.0.1.GA/bin/run.jar ========================================================================= 13:44:45,281 INFO [ServerImpl] Starting JBoss (Microcontainer)... 13:44:45,283 INFO [ServerImpl] Release ID: JBoss [Morpheus] 5.0.1.GA (build: SVNTag=JBoss_5_0_1_GA date=200902232048) 13:44:45,283 INFO [ServerImpl] Bootstrap URL: null 13:44:45,283 INFO [ServerImpl] Home Dir: /Users/bob/j boss-5.0.1.GA 13:44:45,283 INFO [ServerImpl] Home URL: file:/Users/bob/jboss-5.0.1.GA/ 13:44:45,287 INFO [ServerImpl] Library URL: fi le:/Users/bob/jboss-5.0.1.GA/lib/ 13:44:45,288 INFO [ServerImpl] Patch URL: null 13:44:45,288 INFO [ServerImpl] Common Base URL: fi le:/Users/bob/jboss-5.0.1.GA/common/ 13:44:45,288 INFO [ServerImpl] Common Library URL: file:/Users/bob/jboss-5.0.1.GA/common/lib/ 13:44:45,288 INFO [ServerImpl] Server Name: default 13:44:45,289 INFO [ServerImpl] Server Base Dir: /Users/bob/jboss-5.0.1.GA/server 13:44:45,289 INFO [ServerImpl] Server Base URL: file:/Users/bob/jboss-5.0.1.GA/server/ 13:44:45,289 INFO [ServerImpl] Server Confi g URL: file:/Users/bob/jboss-5.0.1.GA/server/default/conf/ 13:44:45,289 INFO [ServerImpl] Server Home Dir: /Users/bob/jboss-5.0.1.GA/server/default 13:44:45,289 INFO [ServerImpl] Server Home URL: file:/Users/bob/jboss-5.0.1.GA/server/default/ 70
  • 72. Create models $ jruby ./script/generate resource twig 72
  • 73. Create models $ jruby ./script/generate resource twig ... create app/models/twig.rb 73
  • 74. Create models $ jruby ./script/generate resource twig ... create app/models/twig.rb ... create db/migrate/20090308180254_create_twigs.rb 74
  • 75. Create models $ jruby ./script/generate resource twig ... create app/models/twig.rb ... create db/migrate/20090308180254_create_twigs.rb ... create app/controllers/twigs_controller.rb 75
  • 76. Create models $ jruby ./script/generate resource twig ... create app/models/twig.rb ... create db/migrate/20090308180254_create_twigs.rb ... create app/controllers/twigs_controller.rb ... route map.resources :twigs 76
  • 77. Create models db/migrate/*_create_twigs.rb class CreateTwigs < ActiveRecord::Migration def self.up create_table :twigs do |t| t.string :name, :limit=>42, :null=>false t.timestamps end end def self.down drop_table :twigs end end 77
  • 78. Blow it into the DB $ rake db:migrate (in /Users/bob/twiggl) == CreateTwigs: migrating =============== -- create_table(:twigs) -> 0.0669s -> 0 rows == CreateTwigs: migrated (0.0683s) ====== 78
  • 79. Rough in a controller app/controllers/twigs_controller.rb class TwigsController < ApplicationController def index @twigs = Twig.find( :all ) end end 79
  • 80. Rough in a template app/views/twigs/index.html.erb <p> There are <%= @twigs.size %> twigs. </p> <% for twig in @twigs %> <% div_for( twig ) do %> <%= twig.name %> <% end %> <% end %> 80
  • 81. Rough in a template app/views/twigs/index.html.erb <p> There are <%= @twigs.size %> twigs. </p> <% for twig in @twigs %> <% div_for( twig ) do %> <%= twig.name %> <% end %> <% end %> 81
  • 82. Rough in a template app/views/twigs/index.html.erb <p> There are <%= @twigs.size %> twigs. </p> <% for twig in @twigs %> <% div_for( twig ) do %> <%= twig.name %> <% end %> <% end %> 82
  • 83. Hit it! 83
  • 84. We didn’t restart AS. And we didn’t redeploy our app, either. That’s okay, we’re hacking hot code. 84
  • 85. Twig management app/controllers/twigs_controller.rb class TwigsController < ApplicationController def new @twig = Twig.new end def create @twig = Twig.create( params[:twig] ) redirect_to @twig end end 85
  • 86. Twig form app/views/twigs/new.html.erb <% form_for @twig do %> <%= label :twig, :name %> <%= text_field :twig, :name %> <%= submit_tag 'Create twig!' %> <% end %> 86
  • 87. Twig management app/controllers/twigs_controller.rb class TwigsController < ApplicationController def show @twig = Twig.find_by_id( params[:id] ) redirect_to twigs_url unless @twig end end 87
  • 88. Twig view app/views/twigs/show.html.erb <% div_for @twig do %> <h1><%= @twig.name %></h1> <% end %> 88
  • 91. Back to the index 91
  • 93. Beyond Rails But, we have the entire freakin’ JBoss AS5 there. Let’s use it. 93
  • 94. Job scheduling Sometimes you need some code to fire on a recurring basis, outside of the web context. 94
  • 95. Job Scheduling •Nightly batches •Polling RSS •Checking email •Watching directories 95
  • 96. Jobs app/jobs/**/*.rb 96
  • 97. Job class app/jobs/twitter_sender.rb class TwitterSender < JBoss::Jobs::BaseJob def run new_twigs = Twig.find( :all, :conditions=>[ 'created_at >= ?', Time.now - 30.minutes ] ) return if new_twigs.empty? tweet( new_twigs.size ) end def tweet(num_new_twigs) .. end end 97
  • 98. Job schedule config/jobs.yml twitter.sender: description: Send a tweet cron: 0 */30 * * * ? job: TwitterSender 98
  • 99. Job schedule config/jobs.yml twitter.sender: description: Send a tweet cron: 0 */30 * * * ? job: TwitterSender 99
  • 100. Job schedule config/jobs.yml twitter.sender: description: Send a tweet cron: 0 */30 * * * ? job: TwitterSender 100
  • 101. Job schedule config/jobs.yml twitter.sender: description: Send a tweet cron: 0 */30 * * * ? job: TwitterSender 101
  • 102. Job schedule config/jobs.yml twitter.sender: description: Send a tweet cron: 0 */30 * * * ? job: TwitterSender 102
  • 103. Redeploy the app $ rake jboss:rails:deploy 103
  • 104. Why redeploy? Jobs are deployed when your app is deployed. Adding a job means you need to redeploy your app. 104
  • 105. Ta-da! [RubyJob] Starting Ruby job: twiggl.twitter.sender ... [STDOUT] twittering [1 new twigs!] 105
  • 106. Hot, hot code Once your job is deployed, you can continue to edit the actual service method. 106
  • 107. No further redeployment is necessary, unless you add jobs or alter the schedule. 107
  • 108. Some More Possibilities Message Queues (MQ/JMS) Legacy/JCA integration WS style web services... 108
  • 109. Ruby Databinding JBoss-Rails provides automatic databinding to XMLSchema types. 109
  • 110. Ruby Databinding When WS deployed, the WSDL is examined and real Ruby classes are created. 110
  • 112. What are rules? Business rules Declarative statements Logic/reasoning 112
  • 113. What are rules? Capture domain expert knowledge as statements/assertions of truth (aka: business rules) 113
  • 114. What are rules? An executable knowledge base 114
  • 115. Drools Drools provides a runtime, compiler and tools to develop and manage executable knowledge bases (all open source of course) 115
  • 116. For example: rule “age and history compliance” when Driver(age < 25, sex=”M”) not Accident(severity > 3) not Infringement(type==”dui”) then approveDriver(“Let this one through”) end 116
  • 117. For example: rule “age and history compliance” when Driver(age < 25, sex=”M”) not Accident(severity > 3) not Infringement(type==”dui”) then approveDriver(“Let this one through”) end 117
  • 118. For example: rule “age and history compliance” when Driver(age < 25, sex=”M”) not Accident(severity > 3) not Infringement(type==”dui”) then approveDriver(“Let this one through”) end 118
  • 119. For example: rule “age and history compliance” when Driver(age < 25, sex=”M”) not Accident(severity > 3) not Infringement(type==”dui”) then approveDriver(“Let this one through”) end 119
  • 120. For example: rule “age and history compliance” when Driver(age < 25, sex=”M”) not Accident(severity > 3) not Infringement(type==”dui”) then approveDriver(“Let this one through”) end 120
  • 121. For example: rule “age and history compliance” when Driver(age < 25, sex=”M”) not Accident(severity > 3) not Infringement(type==”dui”) then approveDriver(“Let this one through”) end 121
  • 122. For example: rule “age and history compliance” when Driver(age < 25, sex=”M”) not Accident(severity > 3) not Infringement(type==”dui”) then approveDriver(“Let this one through”) end 122
  • 123. Why? You have domain experts The rules change Anti-spaghetti if else if else if else ... 123
  • 124. 124
  • 125. 125
  • 126. 126
  • 127. 127
  • 128. The Guvnor.. Repository and Web interface 128
  • 129. 129
  • 130. 130
  • 131. 131
  • 132. 132
  • 133. 133
  • 134. 134
  • 135. How? In process on the JVM As a decision service 135
  • 136. Where? Logistics (Fedex – talk at J1) Insurance, risk, fraud etc.. All domains.. 136
  • 137. Questions! For more info: Contact me: http://twitter.com/michaelneale http://oddthesis.org/theses/jboss-rails/projects/jboss-rails http://jboss.org/drools 137