Your SlideShare is downloading. ×
0
When Two Worlds Collide:                       Java and Ruby in the Enterprise                                            ...
Ben Browning•TorqueBox Core Contributor•Red Hat Senior Engineer•twitter.com/bbrowning•github.com/bbrowning
TorqueBox Extended Team
Ruby and Java in the    Enterprise
TorqueBox in the   Enterprise
Why Ruby?
Why Ruby?•Productivity
Why Ruby?•Productivity•Choice
Why Ruby?
JRuby•Marriage of the JVM and Ruby•the library level integrate at Lets Java and Ruby
JRubyrequire ‘java’java.lang.System.setProperty(‘key’, ‘value’)java_import java.util.HashMaphashmap = HashMap.newhashmap[‘...
JRubyrequire ‘java’java_import java.util.concurrent.CountDownLatchjava_import java.util.concurrent.TimeUnitlatch = CountDo...
TorqueBox
TorqueBox•Marriage of JBoss AS7 and JRuby•the application levelintegrate at Lets Java and Ruby•in the same application ser...
But Can’t I Already Run JRubyApps in My Java App Server?
But Can’t I Already Run JRubyApps in My Java App Server?Yes, if you don’t mind disguising your Ruby       application as a...
So Why TorqueBox?
So Why TorqueBox?Ruby as a first-class citizen in the           enterprise
Familiar to Ruby DevsMake changes then refresh the browser
Familiar to Java Devs  Just JBoss AS7 underneath
So Why TorqueBox?Ruby interfaces to services provided     by the application server
Ruby!APIs!/!Programming!Models                               Java!APIs!/!Programming!Models                               ...
TorqueBox•applications & Rack Rails, Sinatra,
TorqueBox•applications & Rack Rails, Sinatra,•More than just web •Messaging •Jobs •Services •Caching
Installation For Java Devswget http://torquebox.org/release/org/torquebox/torquebox-dist/2.0.0.beta3/torquebox-dist-2.0.0....
Installation For Ruby Devsrvm install jruby-1.6.5.1rvm use jruby-1.6.5.1jruby -J-Xmx1024m -S gem install torquebox-server-...
Usagetorquebox deploy ~/my_ruby_apptorquebox run
TorqueBox•applications & Rack Rails, Sinatra,•More than just web •Messaging •Jobs •Services •Caching
Messaging
Message Processorsapp/models/print_handler.rbinclude TorqueBox::Messagingclass PrintHandler < MessageProcessor  def on_mes...
Message Processorsconfig/torquebox.ymlqueues:  /queues/receipts:messaging:  /queues/receipts:    PrintHandler:      concur...
Backgroundable
Regular Classclass Something def foo  sleep 5 endend
Blocking Invocationssomething = Something.newsomething.foo
Backgroundableclass Something include TorqueBox::Messaging::Backgroundable def foo end def bar endend
Non-Blocking Invocationssomething = Something.newsomething.background.foo
See The Futuresomething = Something.newfuture = something.background.foo
See The Futurefuture.started?future.complete?future.error?future.result
See The Futureclass Something def foo  ...  count += 1  future.status = count  ... endend
See The Future# on the client sidefuture.status_changed?future.status # => 42
Scheduled Jobs
Scheduled Jobsapp/jobs/newsletter_sender.rbclass NewsletterSender   def run    subscriptions = Subscription.find(:all)    s...
Scheduled Jobsconfig/torquebox.ymljobs:  monthly_newsletter:   description: first of month   job: NewsletterSender   cron: ...
Services
Servicesapp/services/time_machine.rbclass TimeMachine def initialize(opts)   @queue = Queue.new(opts[queue]) end def start...
Servicesapp/services/time_machine.rbclass TimeMachine def run  until @done   @queue.publish(Time.now)   sleep(1)  end endend
Servicesconfig/torquebox.ymlservices: TimeMachine:  config:    queue: /queue/time
Caching
Rails Caching config/application.rbmodule MyApp class Application < Rails::Application  ...  config.cache_store = :torque_b...
Explicit Cachinginclude ActiveSupport::CachemyCache =  TorqueBoxStore.new(:name => MyCache,                     :mode => :...
Clusteringtorquebox run --clustered
Better Java Integration•Deploy Java and Ruby side-by-side•Injection of Java components - CDI, objects bound to JNDI, etc•S...
Java Component Injection# messaging destinationsinject(‘/queues/something’)# CDI resourcesinject(com.mycorp.MyJavaService)...
Java & Ruby Messaging producer.javaInitialContext ic = new InitialContext();ConnectionFactory cf = (ConnectionFactory) ic....
Java & Ruby Messagingconsumer.rbqueue = inject(‘/queues/my_queue’)message = queue.receive(:decode => false)puts message.te...
PicketLink & Rubyauthenticator = TorqueBox::Authenticator[‘jmx-console’]authenticator.authenticate(‘username’, ‘password’)...
Java Management
Resources•http://torquebox.org•https://github.com/torquebox•#torquebox on FreeNode•@torquebox on Twitter
Questions?                             Don’t Be ShyImage Attributions:Tools - http://www.flickr.com/photos/jrvogt81/426457...
When Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the Enterprise
Upcoming SlideShare
Loading in...5
×

When Two Worlds Collide: Java and Ruby in the Enterprise

2,834

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,834
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
18
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • Several of us are employed by Red Hat and work on TorqueBox full time but most aren&amp;#x2019;t.\n
  • Since this is a JBoss User Group, hopefully most attendees either already use JBoss or are open to the idea of moving to JBoss. So, what this really means is -&gt;\n
  • \n
  • \n
  • Ask any Rubyist why they use the language and &amp;#x201C;Because with Ruby I&amp;#x2019;m more productive than when using X&amp;#x201D; will likely be one of their reasons\n
  • Give your developers several tools to choose from and let them pick which is the best for each job\n
  • \n
  • \n
  • Ruby running on top of the JVM\n
  • A few examples of Java library usage from JRuby\n
  • JRuby has real threads and real concurrency\n
  • \n
  • TorqueBox is additive to JBoss AS7 - it&amp;#x2019;s still JBoss AS7 underneath and you can still deploy Java applications to TorqueBox\nTorqueBox just adds on the Ruby support\n
  • \n
  • warbler, jruby-rack\n
  • \n
  • \n
  • no bundling or compilation step, no redeploying or restarting server\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • This download includes a full JBoss AS7 w/ TorqueBox and a bundled JRuby runtime\n
  • JRuby 1.6.6 and onwards won&amp;#x2019;t require passing Xmx to the gem install command\n
  • $TORQUEBOX_HOME/jboss/bin/standalone.sh if you prefer\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Clustered sessions, Infinispan cache, HornetQ destinations, HA Singletons\njust runs standalone.sh -server-config standalone-ha.xml underneath\n
  • \n
  • \n
  • \n
  • :decode =&gt; false since we&amp;#x2019;re receiving from Java and not using a standard TorqueBox encoding when sending\n
  • PicketLink is included in JBoss AS 7\nYou can authenticate against configured AS7 security domains in Ruby\n
  • \n
  • \n
  • \n
  • Transcript of "When Two Worlds Collide: Java and Ruby in the Enterprise"

    1. 1. When Two Worlds Collide: Java and Ruby in the Enterprise Ben BrowningCreative Commons BY-SA 3.0 ATL JBUG Jan 31 2012
    2. 2. Ben Browning•TorqueBox Core Contributor•Red Hat Senior Engineer•twitter.com/bbrowning•github.com/bbrowning
    3. 3. TorqueBox Extended Team
    4. 4. Ruby and Java in the Enterprise
    5. 5. TorqueBox in the Enterprise
    6. 6. Why Ruby?
    7. 7. Why Ruby?•Productivity
    8. 8. Why Ruby?•Productivity•Choice
    9. 9. Why Ruby?
    10. 10. JRuby•Marriage of the JVM and Ruby•the library level integrate at Lets Java and Ruby
    11. 11. JRubyrequire ‘java’java.lang.System.setProperty(‘key’, ‘value’)java_import java.util.HashMaphashmap = HashMap.newhashmap[‘key’] = ‘value’
    12. 12. JRubyrequire ‘java’java_import java.util.concurrent.CountDownLatchjava_import java.util.concurrent.TimeUnitlatch = CountDownLatch.new(1)Thread.new { sleep 5 latch.count_down}latch.await(15, TimeUnit::SECONDS)
    13. 13. TorqueBox
    14. 14. TorqueBox•Marriage of JBoss AS7 and JRuby•the application levelintegrate at Lets Java and Ruby•in the same application server Run Java and Ruby applications
    15. 15. But Can’t I Already Run JRubyApps in My Java App Server?
    16. 16. But Can’t I Already Run JRubyApps in My Java App Server?Yes, if you don’t mind disguising your Ruby application as a Java application
    17. 17. So Why TorqueBox?
    18. 18. So Why TorqueBox?Ruby as a first-class citizen in the enterprise
    19. 19. Familiar to Ruby DevsMake changes then refresh the browser
    20. 20. Familiar to Java Devs Just JBoss AS7 underneath
    21. 21. So Why TorqueBox?Ruby interfaces to services provided by the application server
    22. 22. Ruby!APIs!/!Programming!Models Java!APIs!/!Programming!Models Message Processors Polyglot WebSockets InjectionSinatra Rails Jobs STOMP POJO REST Servlet Rack Daemons Tasks Spring JMS JavaEE JRuby!Component!Deployers!&!Gems Java!Enterprise!Services JBoss Web Messaging Infinispan Cache TorqueBox HornetQ Transactions Core Quartz Security TorqueBox Core PicketLink JRuby with JIT Managed Services Container Java Virtual Machine
    23. 23. TorqueBox•applications & Rack Rails, Sinatra,
    24. 24. TorqueBox•applications & Rack Rails, Sinatra,•More than just web •Messaging •Jobs •Services •Caching
    25. 25. Installation For Java Devswget http://torquebox.org/release/org/torquebox/torquebox-dist/2.0.0.beta3/torquebox-dist-2.0.0.beta3-bin.zipunzip torquebox-dist-2.0.0.beta3-bin.zipexport TORQUEBOX_HOME=`pwd`/torquebox-2.0.0.beta3export PATH=$TORQUEBOX_HOME/jruby/bin:$PATH
    26. 26. Installation For Ruby Devsrvm install jruby-1.6.5.1rvm use jruby-1.6.5.1jruby -J-Xmx1024m -S gem install torquebox-server--pre
    27. 27. Usagetorquebox deploy ~/my_ruby_apptorquebox run
    28. 28. TorqueBox•applications & Rack Rails, Sinatra,•More than just web •Messaging •Jobs •Services •Caching
    29. 29. Messaging
    30. 30. Message Processorsapp/models/print_handler.rbinclude TorqueBox::Messagingclass PrintHandler < MessageProcessor  def on_message(body)    puts "Processing #{body} of #{message}"  endend
    31. 31. Message Processorsconfig/torquebox.ymlqueues: /queues/receipts:messaging: /queues/receipts: PrintHandler: concurrency: 5
    32. 32. Backgroundable
    33. 33. Regular Classclass Something def foo sleep 5 endend
    34. 34. Blocking Invocationssomething = Something.newsomething.foo
    35. 35. Backgroundableclass Something include TorqueBox::Messaging::Backgroundable def foo end def bar endend
    36. 36. Non-Blocking Invocationssomething = Something.newsomething.background.foo
    37. 37. See The Futuresomething = Something.newfuture = something.background.foo
    38. 38. See The Futurefuture.started?future.complete?future.error?future.result
    39. 39. See The Futureclass Something def foo ... count += 1 future.status = count ... endend
    40. 40. See The Future# on the client sidefuture.status_changed?future.status # => 42
    41. 41. Scheduled Jobs
    42. 42. Scheduled Jobsapp/jobs/newsletter_sender.rbclass NewsletterSender   def run    subscriptions = Subscription.find(:all)    subscriptions.each do |e|      send_newsletter(e)    end  end end
    43. 43. Scheduled Jobsconfig/torquebox.ymljobs: monthly_newsletter: description: first of month job: NewsletterSender cron: ‘0 0 0 1 * ?’
    44. 44. Services
    45. 45. Servicesapp/services/time_machine.rbclass TimeMachine def initialize(opts) @queue = Queue.new(opts[queue]) end def start Thread.new { run } end def stop @done = true endend
    46. 46. Servicesapp/services/time_machine.rbclass TimeMachine def run until @done @queue.publish(Time.now) sleep(1) end endend
    47. 47. Servicesconfig/torquebox.ymlservices: TimeMachine: config: queue: /queue/time
    48. 48. Caching
    49. 49. Rails Caching config/application.rbmodule MyApp class Application < Rails::Application ... config.cache_store = :torque_box_store endend
    50. 50. Explicit Cachinginclude ActiveSupport::CachemyCache = TorqueBoxStore.new(:name => MyCache, :mode => :replicated, :sync => true)
    51. 51. Clusteringtorquebox run --clustered
    52. 52. Better Java Integration•Deploy Java and Ruby side-by-side•Injection of Java components - CDI, objects bound to JNDI, etc•Send JMS messages in vice-versa consume in Ruby and Java to•Share caches between Java and Ruby•PicketLink authentication in Ruby•Java Management Tools
    53. 53. Java Component Injection# messaging destinationsinject(‘/queues/something’)# CDI resourcesinject(com.mycorp.MyJavaService)# JNDI entriesinject(‘java:comp/env/that_thing’)# JBoss MSC Servicesinject(‘jboss.web’)
    54. 54. Java & Ruby Messaging producer.javaInitialContext ic = new InitialContext();ConnectionFactory cf = (ConnectionFactory) ic.lookup(“/ConnectionFactory”);Queue queue = (Queue) ic.lookup(“/queues/my_queue”);Connection connection = cf.createConnection();Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);MessageProducer producer = session.createProducer(queue);TextMessage message = session.createTextMessage(“hi”);producer.send(message);
    55. 55. Java & Ruby Messagingconsumer.rbqueue = inject(‘/queues/my_queue’)message = queue.receive(:decode => false)puts message.text# prints “hi”
    56. 56. PicketLink & Rubyauthenticator = TorqueBox::Authenticator[‘jmx-console’]authenticator.authenticate(‘username’, ‘password’) do some_authenticated_actionend
    57. 57. Java Management
    58. 58. Resources•http://torquebox.org•https://github.com/torquebox•#torquebox on FreeNode•@torquebox on Twitter
    59. 59. Questions? Don’t Be ShyImage Attributions:Tools - http://www.flickr.com/photos/jrvogt81/4264575563/Mailboxes - http://www.flickr.com/photos/joanet/5094833752/Now and Laters - http://www.flickr.com/photos/jcorduroy/3725077603/Hand Calendar - http://www.flickr.com/photos/joelanman/366190064/Cruise Ship Staff - http://www.flickr.com/photos/maethlin/2547037443/
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×