SlideShare a Scribd company logo
1 of 92
Download to read offline
When Java meets Ruby


     Creative Commons BY-SA 3.0




Thursday, December 8, 11
@abstractj
          Java há 12 anos, Ruby n00b
          TorqueBox Contributor
          DynJS Contributor
          Caelum & ConcreteS


Thursday, December 8, 11
DISCLAIMER



Thursday, December 8, 11
Java

                   927 JSRS!
               nooooooooooooooo!

Thursday, December 8, 11
import java.util.Calendar;
                           public class Beer {
                             private Long beerId;
                             private String description;
                             private Calendar createdAt;
                             public Long getBeerId() {
                                return beerId;
                             }
                             public void setBeerId(Long beerId) {

Expressiva?                  }
                                this.beerId = beerId;

                             public String getDescription() {
                                return description;
                             }
                             public void setDescription(String description)
                                this.description = description;
                             }
                             public Calendar getCreatedAt() {
                                return createdAt;
                             }
                             public void setCreatedAt(Calendar createdAt)
                                this.createdAt = createdAt;
                             }
Thursday, December 8, 11
                           }
ENTERPRISE



Thursday, December 8, 11
JAXR                         Java-FX     JAXP
                           JSTL                         StAX JME
                                  JDOM       JVM
         JAX-RPC                                      EJB
                                              AWT           JMX
                  Swing
      EAR Struts          JAAS                        JCP
                 JavaBean
         NPE                                                Spring
     JAX-WS                  ENTERPRISE                        RMI
           JSE               JNI      JNDI               NIO
                                                   SOA          JSP
      JSF JAXB                          WAR             JDO
  JAX-RS JPQL                                  JAF         POJO
               EJBQL                                  JRE
    JEE

Thursday, December 8, 11
Thursday, December 8, 11
Mas escala né?!




Thursday, December 8, 11
Scala            Clojure
                                   Jython


                                    JVM
                                    DynJS
                  Rhino                     Groovy




Thursday, December 8, 11
Ruby
     Mais expressiva que Java

      class Beer
        attr_accessor :beer_id, :description, :created_at
      end




Thursday, December 8, 11
DRY



       “It is tempting, if the only tool you have is a
       hammer, to treat everything as if it were a
       nail.” - Abraham Maslow

Thursday, December 8, 11
JRuby
                           Java + Ruby




Thursday, December 8, 11
JRuby
    require 'java'

    pdf = com.itextpdf.text.Document.new
    para = com.itextpdf.text.Paragraph.new 'Brought to you by JRuby'
    file = java.io.FileOutputStream.new 'pdf_demo.pdf'
    com.itextpdf.text.pdf.PdfWriter.get_instance pdf, file

    pdf.open
    pdf.add para
    pdf.close




Thursday, December 8, 11
“You get true multithreading that
                can use all your computer’s cores
                from one process, plus a virtual
                machine that’s been tuned for a
                decade and a half.”

                            Using JRuby - Bringing Ruby to Java




Thursday, December 8, 11
Server Side



Thursday, December 8, 11
Ruby App
                             Sinatra      Rails
                                   Rack
                             Passenger/Thin


                             Apache/Nginx




Thursday, December 8, 11
Ruby App
                             Sinatra      Rails
                                   Rack
                             Passenger/Thin       Jobs


                             Apache/Nginx         crond




Thursday, December 8, 11
Ruby App
                                      Sinatra      Rails
                                            Rack
                           Tasks      Passenger/Thin       Jobs
                        Resque/
                       DelayedJob     Apache/Nginx         crond




Thursday, December 8, 11
Ruby App
                                      Sinatra      Rails
                                            Rack
                           Tasks      Passenger/Thin       Jobs
                        Resque/
                       DelayedJob     Apache/Nginx         crond


                                         Daemons


                                       god/monit



Thursday, December 8, 11
JBoss
     Tomcat




Thursday, December 8, 11
JBoss
     HornetQ




Thursday, December 8, 11
JBoss
     Quartz




Thursday, December 8, 11
JBoss
     Clustering




Thursday, December 8, 11
AS 7
     Redução do footprint de memória
     Class loader modular
     Queda no tempo de startup
     EE6 compliant




Thursday, December 8, 11
TorqueBox
                           “The power of JBoss with the
                             expressiveness of Ruby”
                                       Jim Crossley - MagicRuby Conference




Thursday, December 8, 11
TorqueBox




Thursday, December 8, 11
Instalação
                            TorqueBox do zero




Thursday, December 8, 11
Pré-requisitos
      ➜ java -version
      java version "1.6.0_07"
      Java(TM) SE Runtime Environment (build 1.6.0_07-b06-153)
      Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_07-b06-57,
      mixed mode)




Thursday, December 8, 11
➜ jruby -S gem install torquebox torquebox-capistrano-support




Thursday, December 8, 11
➜ wget http://repository-torquebox.forge.cloudbees.com/
     release/org/torquebox/torquebox-dist/2.0.0.beta1/torquebox-
     dist-2.0.0.beta1-bin.zip
     ➜ unzip torquebox-dist-2.0.0.beta1-bin.zip

     ➜ export TORQUEBOX_HOME=$PWD/torquebox-
     dist-2.0.0.beta1
     ➜ export JBOSS_HOME=$TORQUEBOX_HOME/jboss
     ➜ export JRUBY_HOME=$TORQUEBOX_HOME/jruby

     ➜ export PATH=$JRUBY_HOME/bin:$PATH




Thursday, December 8, 11
Rails
     rails new beer -m $TORQUEBOX_HOME/share/rails/template.rb




Thursday, December 8, 11
Estrutura
     Diretórios do TorqueBox




Thursday, December 8, 11
Rake tasks
      rake torquebox:deploy
      rake torquebox:undeploy
      rake torquebox:run




Thursday, December 8, 11
Deployment
                           Make knobs, not WAR!




Thursday, December 8, 11
beer-knob.yml
     application:
      root: /Users/Bruno/javaonebrasil/beer
      environment: development




Thursday, December 8, 11
Thursday, December 8, 11
Aplicação



Thursday, December 8, 11
source "http://torquebox.org/2x/builds/584/gem-
                           repo"
                           source 'http://rubygems.org'

                           gem 'rails', '3.1.1'



     Gemfile
                           gem 'activerecord-jdbcsqlite3-adapter'

                           gem 'jruby-openssl'
                           gem 'json'
                           gem 'jquery-rails'

                           gem "torquebox-rake-support", "2.x.incremental.
                           584"
                           gem "torquebox", "2.x.incremental.584"




Thursday, December 8, 11
Web
                           Rack, Sinatra, Rails




Thursday, December 8, 11
Caching
     class BeersController < ApplicationController

        caches_action :most_popular, :expires_in => 30.seconds

        def most_popular
         @popular_beers = Beer.most_popular(:limit => 25)
        end

     end




Thursday, December 8, 11
Thursday, December 8, 11
Clustering
     ➜ torquebox run --clustered




Thursday, December 8, 11
Internals
     class TorqueBoxCommand < Thor
      TASK_ORDER = %w(deploy undeploy start cli env help)

      map "run" => "start"
      desc "run", "Run TorqueBox"
      method_option :clustered,
                     :type => :boolean,
                     :desc => "Run TorqueBox in clustered mode"
      def start
       setup_environment
       TorqueBox::DeployUtils.run_server(:clustered => options.clustered,
                           :max_threads => options['max-threads'],
                           :bind_address => options['bind-address'])
      end
     end




Thursday, December 8, 11
Cache distribuído!



Thursday, December 8, 11
mod_cluster
                           httpd-based load balancer




Thursday, December 8, 11
Infinispan
                             Caching




Thursday, December 8, 11
Invalidation
                            Cache     Cache
                           Server1   Server2




Thursday, December 8, 11
Invalidation
                                     Notificação
                            Cache                  Cache
                           Server1                Server2


                           NEW                   Cache
                                              Desatualizado




Thursday, December 8, 11
../config/application.rb
     module Beer

      class Application < Rails::Application
       config.cache_store = :torque_box_store
      end
     end




Thursday, December 8, 11
Replicated
                                             Cache
                                            Server2
                            Cache
                           Server1   Sync
                                             Cache
                                     Sync   Server2



                                             Cache
                                            Server2




Thursday, December 8, 11
../config/application.rb
     module Beer

      class Application < Rails::Application
       config.cache_store = :torque_box_store, {:mode =>
     replicated, :sync =>false}
      end
     end




Thursday, December 8, 11
Scheduling
                           Agendamento de Jobs




Thursday, December 8, 11
Internals
      public class RubyJobProxy implements Job {

          @Override
          public void execute(JobExecutionContext context) throws JobExecutionException {
            Ruby ruby = null;
            try {
               ruby = this.runtimePool.borrowRuntime( resolver.getComponentName() );
               JobComponent job = (JobComponent)resolver.resolve( ruby );
               job.run();
            } catch (Exception e) {
               throw new JobExecutionException( e );
            } finally {
               if (ruby != null) {
                   this.runtimePool.returnRuntime( ruby );
               }
            }
          }




Thursday, December 8, 11
Internals
      public class RubyJobProxy implements Job {

          @Override
          public void execute(JobExecutionContext context) throws JobExecutionException {
            Ruby ruby = null;
            try {
               ruby = this.runtimePool.borrowRuntime( resolver.getComponentName() );
               JobComponent job = (JobComponent)resolver.resolve( ruby );
               job.run();
            } catch (Exception e) {
               throw new JobExecutionException( e );
            } finally {
               if (ruby != null) {
                   this.runtimePool.returnRuntime( ruby );
               }
            }
          }




Thursday, December 8, 11
../app/jobs
     class JobDemo

         def initialize
          #Codigo de inicializacao
         end

      def run
       # O que você quer executar
      end
     end


Thursday, December 8, 11
../config/torquebox.yml
     jobs:
      sync_agenda:
       job: JobDemo
       cron: '0 0 12 * * ?'
     end




Thursday, December 8, 11
Mensageria
     Java Messaging Service + HornetQ




Thursday, December 8, 11
O Ministério da Saúde adverte:

                      NOSQL COMO MENSAGERIA
                                PODE
                     TRAZER DANOS A SUA SAÚDE
                       E A DE SEUS FAMILIARES




Thursday, December 8, 11
Greenfield
                                 REST + NoSQL

                                 Request/Responsext


                                     NoSQL

                    RAILS APP        pub/sub          SINATRA APP




Thursday, December 8, 11
Real World
                                  Nobody Cares!
                                   Request/Responsext


                                       NoSQL

                      RAILS APP        pub/sub          MAINFRAME




Thursday, December 8, 11
../config/torquebox.yml
     /topics/beerTopic
     /queues/queueBeer:




Thursday, December 8, 11
Tasks
     class EmailerTask < TorqueBox::Messaging::Task
      def send_welcome(payload)
       to = "#{payload[:name]} <#{payload[:address]}>"
       # send welcome email to the user
      end
     end




Thursday, December 8, 11
Tasks
     class UserController < ApplicationController
      def register
       user = User.new(params[:user])

       EmailerTask.async(:send_welcome, :address =>
     user.email, :name => user.name)
      end
     end




Thursday, December 8, 11
Processors
     include TorqueBox::Messaging

     class PrintHandler < MessageProcessor
       def on_message(body)
         puts "Processing #{body} of #{message}"
       end
       def configure(opts)
         @color = opts['color']
       end
     end




Thursday, December 8, 11
Queues
     include TorqueBox
     req = Messaging::Queue.new '/queues/questions'
     res = Messaging::Queue.new '/queues/answers'
      
     Thread.new do
       req.publish "What time is it?"
       puts res.receive( :timeout => 1000 )
     end




Thursday, December 8, 11
Future




Thursday, December 8, 11
Future
     class EmailerTask

      def send_welcome(payload)
       to = "#{payload[:name]} <#{payload[:address]}>"
       # long running task
      end
     end




Thursday, December 8, 11
Future
     class EmailerTask

         include TorqueBox::Messaging::Backgroundable
         always_background :send_welcome

      def send_welcome(payload)
       to = "#{payload[:name]} <#{payload[:address]}>"
       # long running task
      end
     end




Thursday, December 8, 11
Future
       future = @emailTask.send_welcome(:send_welcome)

       future.started?

       future.complete?

       future.error?

       future.result
       future.result(10000)




Thursday, December 8, 11
Services



Thursday, December 8, 11
Services
     class BeerService
      def initialize
       @queue = Messaging::Queue.new(“beer”)
      end
      def start
       @queue.publish “Testing”
      end
      def stop
       # O que fazer quando o serviço receber um stop
      end
     end




Thursday, December 8, 11
Singleton Services
                                     Clustered
                           Server1                  Server2




            BeerService                          BeerService




Thursday, December 8, 11
Singleton Services
                                     Clustered
                           Server1                  Server2




            BeerService                          BeerService




Thursday, December 8, 11
Services
     ➜ torquebox run --clustered



     ../config/torquebox.yml
     services:
      BeerService:
       singleton: true
     end




Thursday, December 8, 11
CDI
                           Injeção de dependências




Thursday, December 8, 11
Pra quê?



Thursday, December 8, 11
Java
     package br.com.javaonebrasil;

     public class Beer {
       //gets e sets
       public void say(String message) { // Execução do método }
     }

     Deploy do jar na aplicação
     app/
     models/
     views/
     controllers/
     lib/beer.jar




Thursday, December 8, 11
Ruby
     class BeerController < ApplicationController

          include TorqueBox::Injectors

          def create
           beer = inject(br.com.javaonebrasil.Beer )
           beer.say “Ruby is for Java”
          end

     end




Thursday, December 8, 11
JNDI
   class MyService
    include TorqueBox::Injectors

    def initialize opts={}
     @factory = inject("java:comp/env/jdbc/myDB")
    end
   end




Thursday, December 8, 11
Destinations
      class MyService
       include TorqueBox::Injectors

       def initialize opts={}
        @inbound = inject("/topic/beerpub")
        @outbound = inject("/queue/beer")
       end
      end




Thursday, December 8, 11
Transactions
          Queue               Database   Infinispan



                   Rails Application       Topic


        XA Distributed, multi resource transaction




Thursday, December 8, 11
XA (2PC)
      HornetQ ✔
      Infinispan ✔
       TorqueBox + ActiveRecord ✔




Thursday, December 8, 11
Outras features
     Autenticação + Websockets




Thursday, December 8, 11
BackStage




Thursday, December 8, 11
Stomp Box
                           TorqueBox deployment support




Thursday, December 8, 11
Thursday, December 8, 11
What’s next?



Thursday, December 8, 11
Polyglot
     Immutant

                           Queue   Queue

   TorqueBox




Thursday, December 8, 11
Getting started

                       Installing TorqueBox 2.0
                      http://vimeo.com/33299335



Thursday, December 8, 11
Comunidade
           irc.freenode.net #torquebox
           http://torquebox.org
           http://github.com/torquebox
           twitter: @torquebox

Thursday, December 8, 11
Obrigado!
                                            @abstractj
                                   http://github.com/abstractj



      Creative Commons BY-SA 3.0




Thursday, December 8, 11

More Related Content

What's hot

ZK_Arch_notes_20081121
ZK_Arch_notes_20081121ZK_Arch_notes_20081121
ZK_Arch_notes_20081121
WANGCHOU LU
 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011
tobiascrawley
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011
tobiascrawley
 
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
 

What's hot (20)

TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyists
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
JUDCon 2010 Boston : TorqueBox
JUDCon 2010 Boston : TorqueBoxJUDCon 2010 Boston : TorqueBox
JUDCon 2010 Boston : TorqueBox
 
JUDCon 2010 Boston : BoxGrinder
JUDCon 2010 Boston : BoxGrinderJUDCon 2010 Boston : BoxGrinder
JUDCon 2010 Boston : BoxGrinder
 
ZK_Arch_notes_20081121
ZK_Arch_notes_20081121ZK_Arch_notes_20081121
ZK_Arch_notes_20081121
 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011
 
Spring into rails
Spring into railsSpring into rails
Spring into rails
 
First Day With J Ruby
First Day With J RubyFirst Day With J Ruby
First Day With J Ruby
 
Ruby 2.4 Internals
Ruby 2.4 InternalsRuby 2.4 Internals
Ruby 2.4 Internals
 
JRuby @ Boulder Ruby
JRuby @ Boulder RubyJRuby @ Boulder Ruby
JRuby @ Boulder Ruby
 
Find bottleneck and tuning in Java Application
Find bottleneck and tuning in Java ApplicationFind bottleneck and tuning in Java Application
Find bottleneck and tuning in Java Application
 
Hybrid Applications
Hybrid ApplicationsHybrid Applications
Hybrid Applications
 
자바 성능 강의
자바 성능 강의자바 성능 강의
자바 성능 강의
 
Scala
ScalaScala
Scala
 
Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 Features
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Java/Spring과 Node.js의공존
Java/Spring과 Node.js의공존Java/Spring과 Node.js의공존
Java/Spring과 Node.js의공존
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 

Similar to TorqueBox - When Java meets Ruby

Deploying JRuby Web Applications
Deploying JRuby Web ApplicationsDeploying JRuby Web Applications
Deploying JRuby Web Applications
Joe Kutner
 
Deploy, Scale and Sleep at Night with JRuby
Deploy, Scale and Sleep at Night with JRubyDeploy, Scale and Sleep at Night with JRuby
Deploy, Scale and Sleep at Night with JRuby
Joe Kutner
 
Rcos presentation
Rcos presentationRcos presentation
Rcos presentation
mskmoorthy
 
JRuby on Rails Deployment: What They Didn't Tell You
JRuby on Rails Deployment: What They Didn't Tell YouJRuby on Rails Deployment: What They Didn't Tell You
JRuby on Rails Deployment: What They Didn't Tell You
elliando dias
 
Complex Made Simple: Sleep Better With TorqueBox
Complex Made Simple: Sleep Better With TorqueBoxComplex Made Simple: Sleep Better With TorqueBox
Complex Made Simple: Sleep Better With TorqueBox
Lance Ball
 

Similar to TorqueBox - When Java meets Ruby (20)

Coding, Scaling, and Deploys... Oh My!
Coding, Scaling, and Deploys... Oh My!Coding, Scaling, and Deploys... Oh My!
Coding, Scaling, and Deploys... Oh My!
 
JRuby and You
JRuby and YouJRuby and You
JRuby and You
 
Practical JRuby
Practical JRubyPractical JRuby
Practical JRuby
 
Deploying JRuby Web Applications
Deploying JRuby Web ApplicationsDeploying JRuby Web Applications
Deploying JRuby Web Applications
 
Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010
 
Deploy, Scale and Sleep at Night with JRuby
Deploy, Scale and Sleep at Night with JRubyDeploy, Scale and Sleep at Night with JRuby
Deploy, Scale and Sleep at Night with JRuby
 
Rcos presentation
Rcos presentationRcos presentation
Rcos presentation
 
JSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklJSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph Pickl
 
Active Record Introduction - 3
Active Record Introduction - 3Active Record Introduction - 3
Active Record Introduction - 3
 
Morning with MongoDB Paris 2012 - MongoDB Basic Concepts
Morning with MongoDB Paris 2012 - MongoDB Basic ConceptsMorning with MongoDB Paris 2012 - MongoDB Basic Concepts
Morning with MongoDB Paris 2012 - MongoDB Basic Concepts
 
JRuby on Rails Deployment: What They Didn't Tell You
JRuby on Rails Deployment: What They Didn't Tell YouJRuby on Rails Deployment: What They Didn't Tell You
JRuby on Rails Deployment: What They Didn't Tell You
 
Pocket Knife JS
Pocket Knife JSPocket Knife JS
Pocket Knife JS
 
Complex Made Simple: Sleep Better With TorqueBox
Complex Made Simple: Sleep Better With TorqueBoxComplex Made Simple: Sleep Better With TorqueBox
Complex Made Simple: Sleep Better With TorqueBox
 
Play 2 pip
Play 2 pipPlay 2 pip
Play 2 pip
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby
 
Java, Ruby & Rails
Java, Ruby & RailsJava, Ruby & Rails
Java, Ruby & Rails
 
Play framework
Play frameworkPlay framework
Play framework
 
JBoss AS 7 from a user perspective
JBoss AS 7 from a user perspectiveJBoss AS 7 from a user perspective
JBoss AS 7 from a user perspective
 
Java 7 Dolphin manjula kollipara
Java 7 Dolphin manjula kolliparaJava 7 Dolphin manjula kollipara
Java 7 Dolphin manjula kollipara
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration Backend
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+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@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
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...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
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?
 
+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...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

TorqueBox - When Java meets Ruby

  • 1. When Java meets Ruby Creative Commons BY-SA 3.0 Thursday, December 8, 11
  • 2. @abstractj Java há 12 anos, Ruby n00b TorqueBox Contributor DynJS Contributor Caelum & ConcreteS Thursday, December 8, 11
  • 4. Java 927 JSRS! nooooooooooooooo! Thursday, December 8, 11
  • 5. import java.util.Calendar; public class Beer { private Long beerId; private String description; private Calendar createdAt; public Long getBeerId() { return beerId; } public void setBeerId(Long beerId) { Expressiva? } this.beerId = beerId; public String getDescription() { return description; } public void setDescription(String description) this.description = description; } public Calendar getCreatedAt() { return createdAt; } public void setCreatedAt(Calendar createdAt) this.createdAt = createdAt; } Thursday, December 8, 11 }
  • 7. JAXR Java-FX JAXP JSTL StAX JME JDOM JVM JAX-RPC EJB AWT JMX Swing EAR Struts JAAS JCP JavaBean NPE Spring JAX-WS ENTERPRISE RMI JSE JNI JNDI NIO SOA JSP JSF JAXB WAR JDO JAX-RS JPQL JAF POJO EJBQL JRE JEE Thursday, December 8, 11
  • 9. Mas escala né?! Thursday, December 8, 11
  • 10. Scala Clojure Jython JVM DynJS Rhino Groovy Thursday, December 8, 11
  • 11. Ruby Mais expressiva que Java class Beer attr_accessor :beer_id, :description, :created_at end Thursday, December 8, 11
  • 12. DRY “It is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail.” - Abraham Maslow Thursday, December 8, 11
  • 13. JRuby Java + Ruby Thursday, December 8, 11
  • 14. JRuby require 'java' pdf = com.itextpdf.text.Document.new para = com.itextpdf.text.Paragraph.new 'Brought to you by JRuby' file = java.io.FileOutputStream.new 'pdf_demo.pdf' com.itextpdf.text.pdf.PdfWriter.get_instance pdf, file pdf.open pdf.add para pdf.close Thursday, December 8, 11
  • 15. “You get true multithreading that can use all your computer’s cores from one process, plus a virtual machine that’s been tuned for a decade and a half.” Using JRuby - Bringing Ruby to Java Thursday, December 8, 11
  • 17. Ruby App Sinatra Rails Rack Passenger/Thin Apache/Nginx Thursday, December 8, 11
  • 18. Ruby App Sinatra Rails Rack Passenger/Thin Jobs Apache/Nginx crond Thursday, December 8, 11
  • 19. Ruby App Sinatra Rails Rack Tasks Passenger/Thin Jobs Resque/ DelayedJob Apache/Nginx crond Thursday, December 8, 11
  • 20. Ruby App Sinatra Rails Rack Tasks Passenger/Thin Jobs Resque/ DelayedJob Apache/Nginx crond Daemons god/monit Thursday, December 8, 11
  • 21. JBoss Tomcat Thursday, December 8, 11
  • 22. JBoss HornetQ Thursday, December 8, 11
  • 23. JBoss Quartz Thursday, December 8, 11
  • 24. JBoss Clustering Thursday, December 8, 11
  • 25. AS 7 Redução do footprint de memória Class loader modular Queda no tempo de startup EE6 compliant Thursday, December 8, 11
  • 26. TorqueBox “The power of JBoss with the expressiveness of Ruby” Jim Crossley - MagicRuby Conference Thursday, December 8, 11
  • 28. Instalação TorqueBox do zero Thursday, December 8, 11
  • 29. Pré-requisitos ➜ java -version java version "1.6.0_07" Java(TM) SE Runtime Environment (build 1.6.0_07-b06-153) Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_07-b06-57, mixed mode) Thursday, December 8, 11
  • 30. ➜ jruby -S gem install torquebox torquebox-capistrano-support Thursday, December 8, 11
  • 31. ➜ wget http://repository-torquebox.forge.cloudbees.com/ release/org/torquebox/torquebox-dist/2.0.0.beta1/torquebox- dist-2.0.0.beta1-bin.zip ➜ unzip torquebox-dist-2.0.0.beta1-bin.zip ➜ export TORQUEBOX_HOME=$PWD/torquebox- dist-2.0.0.beta1 ➜ export JBOSS_HOME=$TORQUEBOX_HOME/jboss ➜ export JRUBY_HOME=$TORQUEBOX_HOME/jruby ➜ export PATH=$JRUBY_HOME/bin:$PATH Thursday, December 8, 11
  • 32. Rails rails new beer -m $TORQUEBOX_HOME/share/rails/template.rb Thursday, December 8, 11
  • 33. Estrutura Diretórios do TorqueBox Thursday, December 8, 11
  • 34. Rake tasks rake torquebox:deploy rake torquebox:undeploy rake torquebox:run Thursday, December 8, 11
  • 35. Deployment Make knobs, not WAR! Thursday, December 8, 11
  • 36. beer-knob.yml application: root: /Users/Bruno/javaonebrasil/beer environment: development Thursday, December 8, 11
  • 39. source "http://torquebox.org/2x/builds/584/gem- repo" source 'http://rubygems.org' gem 'rails', '3.1.1' Gemfile gem 'activerecord-jdbcsqlite3-adapter' gem 'jruby-openssl' gem 'json' gem 'jquery-rails' gem "torquebox-rake-support", "2.x.incremental. 584" gem "torquebox", "2.x.incremental.584" Thursday, December 8, 11
  • 40. Web Rack, Sinatra, Rails Thursday, December 8, 11
  • 41. Caching class BeersController < ApplicationController caches_action :most_popular, :expires_in => 30.seconds def most_popular @popular_beers = Beer.most_popular(:limit => 25) end end Thursday, December 8, 11
  • 43. Clustering ➜ torquebox run --clustered Thursday, December 8, 11
  • 44. Internals class TorqueBoxCommand < Thor TASK_ORDER = %w(deploy undeploy start cli env help) map "run" => "start" desc "run", "Run TorqueBox" method_option :clustered, :type => :boolean, :desc => "Run TorqueBox in clustered mode" def start setup_environment TorqueBox::DeployUtils.run_server(:clustered => options.clustered, :max_threads => options['max-threads'], :bind_address => options['bind-address']) end end Thursday, December 8, 11
  • 46. mod_cluster httpd-based load balancer Thursday, December 8, 11
  • 47. Infinispan Caching Thursday, December 8, 11
  • 48. Invalidation Cache Cache Server1 Server2 Thursday, December 8, 11
  • 49. Invalidation Notificação Cache Cache Server1 Server2 NEW Cache Desatualizado Thursday, December 8, 11
  • 50. ../config/application.rb module Beer class Application < Rails::Application config.cache_store = :torque_box_store end end Thursday, December 8, 11
  • 51. Replicated Cache Server2 Cache Server1 Sync Cache Sync Server2 Cache Server2 Thursday, December 8, 11
  • 52. ../config/application.rb module Beer class Application < Rails::Application config.cache_store = :torque_box_store, {:mode => replicated, :sync =>false} end end Thursday, December 8, 11
  • 53. Scheduling Agendamento de Jobs Thursday, December 8, 11
  • 54. Internals public class RubyJobProxy implements Job { @Override public void execute(JobExecutionContext context) throws JobExecutionException { Ruby ruby = null; try { ruby = this.runtimePool.borrowRuntime( resolver.getComponentName() ); JobComponent job = (JobComponent)resolver.resolve( ruby ); job.run(); } catch (Exception e) { throw new JobExecutionException( e ); } finally { if (ruby != null) { this.runtimePool.returnRuntime( ruby ); } } } Thursday, December 8, 11
  • 55. Internals public class RubyJobProxy implements Job { @Override public void execute(JobExecutionContext context) throws JobExecutionException { Ruby ruby = null; try { ruby = this.runtimePool.borrowRuntime( resolver.getComponentName() ); JobComponent job = (JobComponent)resolver.resolve( ruby ); job.run(); } catch (Exception e) { throw new JobExecutionException( e ); } finally { if (ruby != null) { this.runtimePool.returnRuntime( ruby ); } } } Thursday, December 8, 11
  • 56. ../app/jobs class JobDemo def initialize #Codigo de inicializacao end def run # O que você quer executar end end Thursday, December 8, 11
  • 57. ../config/torquebox.yml jobs: sync_agenda: job: JobDemo cron: '0 0 12 * * ?' end Thursday, December 8, 11
  • 58. Mensageria Java Messaging Service + HornetQ Thursday, December 8, 11
  • 59. O Ministério da Saúde adverte: NOSQL COMO MENSAGERIA PODE TRAZER DANOS A SUA SAÚDE E A DE SEUS FAMILIARES Thursday, December 8, 11
  • 60. Greenfield REST + NoSQL Request/Responsext NoSQL RAILS APP pub/sub SINATRA APP Thursday, December 8, 11
  • 61. Real World Nobody Cares! Request/Responsext NoSQL RAILS APP pub/sub MAINFRAME Thursday, December 8, 11
  • 62. ../config/torquebox.yml /topics/beerTopic /queues/queueBeer: Thursday, December 8, 11
  • 63. Tasks class EmailerTask < TorqueBox::Messaging::Task def send_welcome(payload) to = "#{payload[:name]} <#{payload[:address]}>" # send welcome email to the user end end Thursday, December 8, 11
  • 64. Tasks class UserController < ApplicationController def register user = User.new(params[:user]) EmailerTask.async(:send_welcome, :address => user.email, :name => user.name) end end Thursday, December 8, 11
  • 65. Processors include TorqueBox::Messaging class PrintHandler < MessageProcessor   def on_message(body)     puts "Processing #{body} of #{message}"   end   def configure(opts)     @color = opts['color']   end end Thursday, December 8, 11
  • 66. Queues include TorqueBox req = Messaging::Queue.new '/queues/questions' res = Messaging::Queue.new '/queues/answers'   Thread.new do   req.publish "What time is it?"   puts res.receive( :timeout => 1000 ) end Thursday, December 8, 11
  • 68. Future class EmailerTask def send_welcome(payload) to = "#{payload[:name]} <#{payload[:address]}>" # long running task end end Thursday, December 8, 11
  • 69. Future class EmailerTask include TorqueBox::Messaging::Backgroundable always_background :send_welcome def send_welcome(payload) to = "#{payload[:name]} <#{payload[:address]}>" # long running task end end Thursday, December 8, 11
  • 70. Future future = @emailTask.send_welcome(:send_welcome) future.started? future.complete? future.error? future.result future.result(10000) Thursday, December 8, 11
  • 72. Services class BeerService def initialize @queue = Messaging::Queue.new(“beer”) end def start @queue.publish “Testing” end def stop # O que fazer quando o serviço receber um stop end end Thursday, December 8, 11
  • 73. Singleton Services Clustered Server1 Server2 BeerService BeerService Thursday, December 8, 11
  • 74. Singleton Services Clustered Server1 Server2 BeerService BeerService Thursday, December 8, 11
  • 75. Services ➜ torquebox run --clustered ../config/torquebox.yml services: BeerService: singleton: true end Thursday, December 8, 11
  • 76. CDI Injeção de dependências Thursday, December 8, 11
  • 78. Java package br.com.javaonebrasil; public class Beer { //gets e sets public void say(String message) { // Execução do método } } Deploy do jar na aplicação app/ models/ views/ controllers/ lib/beer.jar Thursday, December 8, 11
  • 79. Ruby class BeerController < ApplicationController include TorqueBox::Injectors def create beer = inject(br.com.javaonebrasil.Beer ) beer.say “Ruby is for Java” end end Thursday, December 8, 11
  • 80. JNDI class MyService include TorqueBox::Injectors def initialize opts={} @factory = inject("java:comp/env/jdbc/myDB") end end Thursday, December 8, 11
  • 81. Destinations class MyService include TorqueBox::Injectors def initialize opts={} @inbound = inject("/topic/beerpub") @outbound = inject("/queue/beer") end end Thursday, December 8, 11
  • 82. Transactions Queue Database Infinispan Rails Application Topic XA Distributed, multi resource transaction Thursday, December 8, 11
  • 83. XA (2PC) HornetQ ✔ Infinispan ✔ TorqueBox + ActiveRecord ✔ Thursday, December 8, 11
  • 84. Outras features Autenticação + Websockets Thursday, December 8, 11
  • 86. Stomp Box TorqueBox deployment support Thursday, December 8, 11
  • 89. Polyglot Immutant Queue Queue TorqueBox Thursday, December 8, 11
  • 90. Getting started Installing TorqueBox 2.0 http://vimeo.com/33299335 Thursday, December 8, 11
  • 91. Comunidade irc.freenode.net #torquebox http://torquebox.org http://github.com/torquebox twitter: @torquebox Thursday, December 8, 11
  • 92. Obrigado! @abstractj http://github.com/abstractj Creative Commons BY-SA 3.0 Thursday, December 8, 11