TorqueBox - When Java meets Ruby
Upcoming SlideShare
Loading in...5
×
 

TorqueBox - When Java meets Ruby

on

  • 2,104 views

 

Statistics

Views

Total Views
2,104
Views on SlideShare
2,083
Embed Views
21

Actions

Likes
1
Downloads
16
Comments
0

3 Embeds 21

http://paper.li 10
http://a0.twimg.com 7
http://us-w1.rockmelt.com 4

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

TorqueBox - When Java meets Ruby TorqueBox - When Java meets Ruby Presentation Transcript

  • When Java meets Ruby Creative Commons BY-SA 3.0Thursday, December 8, 11
  • @abstractj Java há 12 anos, Ruby n00b TorqueBox Contributor DynJS Contributor Caelum & ConcreteSThursday, December 8, 11
  • DISCLAIMERThursday, 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 }
  • ENTERPRISEThursday, 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 JEEThursday, December 8, 11
  • Thursday, December 8, 11
  • Mas escala né?!Thursday, December 8, 11
  • Scala Clojure Jython JVM DynJS Rhino GroovyThursday, December 8, 11
  • Ruby Mais expressiva que Java class Beer attr_accessor :beer_id, :description, :created_at endThursday, 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 MaslowThursday, December 8, 11
  • JRuby Java + RubyThursday, 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.closeThursday, 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 JavaThursday, December 8, 11
  • Server SideThursday, December 8, 11
  • Ruby App Sinatra Rails Rack Passenger/Thin Apache/NginxThursday, December 8, 11
  • Ruby App Sinatra Rails Rack Passenger/Thin Jobs Apache/Nginx crondThursday, December 8, 11
  • Ruby App Sinatra Rails Rack Tasks Passenger/Thin Jobs Resque/ DelayedJob Apache/Nginx crondThursday, December 8, 11
  • Ruby App Sinatra Rails Rack Tasks Passenger/Thin Jobs Resque/ DelayedJob Apache/Nginx crond Daemons god/monitThursday, December 8, 11
  • JBoss TomcatThursday, December 8, 11
  • JBoss HornetQThursday, December 8, 11
  • JBoss QuartzThursday, December 8, 11
  • JBoss ClusteringThursday, December 8, 11
  • AS 7 Redução do footprint de memória Class loader modular Queda no tempo de startup EE6 compliantThursday, December 8, 11
  • TorqueBox “The power of JBoss with the expressiveness of Ruby” Jim Crossley - MagicRuby ConferenceThursday, December 8, 11
  • TorqueBoxThursday, December 8, 11
  • Instalação TorqueBox do zeroThursday, 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-supportThursday, 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:$PATHThursday, December 8, 11
  • Rails rails new beer -m $TORQUEBOX_HOME/share/rails/template.rbThursday, December 8, 11
  • Estrutura Diretórios do TorqueBoxThursday, December 8, 11
  • Rake tasks rake torquebox:deploy rake torquebox:undeploy rake torquebox:runThursday, December 8, 11
  • Deployment Make knobs, not WAR!Thursday, December 8, 11
  • beer-knob.yml application: root: /Users/Bruno/javaonebrasil/beer environment: developmentThursday, December 8, 11
  • Thursday, December 8, 11
  • AplicaçãoThursday, 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, RailsThursday, 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 endThursday, December 8, 11
  • Thursday, December 8, 11
  • Clustering ➜ torquebox run --clusteredThursday, 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 endThursday, December 8, 11
  • Cache distribuído!Thursday, December 8, 11
  • mod_cluster httpd-based load balancerThursday, December 8, 11
  • Infinispan CachingThursday, December 8, 11
  • Invalidation Cache Cache Server1 Server2Thursday, December 8, 11
  • Invalidation Notificação Cache Cache Server1 Server2 NEW Cache DesatualizadoThursday, December 8, 11
  • ../config/application.rb module Beer class Application < Rails::Application config.cache_store = :torque_box_store end endThursday, December 8, 11
  • Replicated Cache Server2 Cache Server1 Sync Cache Sync Server2 Cache Server2Thursday, December 8, 11
  • ../config/application.rb module Beer class Application < Rails::Application config.cache_store = :torque_box_store, {:mode => replicated, :sync =>false} end endThursday, December 8, 11
  • Scheduling Agendamento de JobsThursday, 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 endThursday, December 8, 11
  • ../config/torquebox.yml jobs: sync_agenda: job: JobDemo cron: 0 0 12 * * ? endThursday, December 8, 11
  • Mensageria Java Messaging Service + HornetQThursday, December 8, 11
  • O Ministério da Saúde adverte: NOSQL COMO MENSAGERIA PODE TRAZER DANOS A SUA SAÚDE E A DE SEUS FAMILIARESThursday, December 8, 11
  • Greenfield REST + NoSQL Request/Responsext NoSQL RAILS APP pub/sub SINATRA APPThursday, December 8, 11
  • Real World Nobody Cares! Request/Responsext NoSQL RAILS APP pub/sub MAINFRAMEThursday, 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 endThursday, 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 endThursday, 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 endThursday, 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 ) endThursday, December 8, 11
  • FutureThursday, December 8, 11
  • Future class EmailerTask def send_welcome(payload) to = "#{payload[:name]} <#{payload[:address]}>" # long running task end endThursday, 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 endThursday, 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
  • ServicesThursday, 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 endThursday, December 8, 11
  • Singleton Services Clustered Server1 Server2 BeerService BeerServiceThursday, December 8, 11
  • Singleton Services Clustered Server1 Server2 BeerService BeerServiceThursday, December 8, 11
  • Services ➜ torquebox run --clustered ../config/torquebox.yml services: BeerService: singleton: true endThursday, December 8, 11
  • CDI Injeção de dependênciasThursday, 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.jarThursday, 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 endThursday, December 8, 11
  • JNDI class MyService include TorqueBox::Injectors def initialize opts={} @factory = inject("java:comp/env/jdbc/myDB") end endThursday, December 8, 11
  • Destinations class MyService include TorqueBox::Injectors def initialize opts={} @inbound = inject("/topic/beerpub") @outbound = inject("/queue/beer") end endThursday, December 8, 11
  • Transactions Queue Database Infinispan Rails Application Topic XA Distributed, multi resource transactionThursday, December 8, 11
  • XA (2PC) HornetQ ✔ Infinispan ✔ TorqueBox + ActiveRecord ✔Thursday, December 8, 11
  • Outras features Autenticação + WebsocketsThursday, December 8, 11
  • BackStageThursday, December 8, 11
  • Stomp Box TorqueBox deployment supportThursday, December 8, 11
  • Thursday, December 8, 11
  • What’s next?Thursday, December 8, 11
  • Polyglot Immutant Queue Queue TorqueBoxThursday, December 8, 11
  • Getting started Installing TorqueBox 2.0 http://vimeo.com/33299335Thursday, December 8, 11
  • Comunidade irc.freenode.net #torquebox http://torquebox.org http://github.com/torquebox twitter: @torqueboxThursday, December 8, 11
  • Obrigado! @abstractj http://github.com/abstractj Creative Commons BY-SA 3.0Thursday, December 8, 11