Your SlideShare is downloading. ×
  • Like
When Two Worlds Collide: Java and Ruby in the Enterprise
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

When Two Worlds Collide: Java and Ruby in the Enterprise

  • 2,781 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,781
On SlideShare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
18
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • \n
  • Several of us are employed by Red Hat and work on TorqueBox full time but most aren’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 ->\n
  • \n
  • \n
  • Ask any Rubyist why they use the language and “Because with Ruby I’m more productive than when using X” 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’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’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 => false since we’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

  • 1. When Two Worlds Collide: Java and Ruby in the Enterprise Ben BrowningCreative Commons BY-SA 3.0 ATL JBUG Jan 31 2012
  • 2. Ben Browning•TorqueBox Core Contributor•Red Hat Senior Engineer•twitter.com/bbrowning•github.com/bbrowning
  • 3. TorqueBox Extended Team
  • 4. Ruby and Java in the Enterprise
  • 5. TorqueBox in the Enterprise
  • 6. Why Ruby?
  • 7. Why Ruby?•Productivity
  • 8. Why Ruby?•Productivity•Choice
  • 9. Why Ruby?
  • 10. JRuby•Marriage of the JVM and Ruby•the library level integrate at Lets Java and Ruby
  • 11. JRubyrequire ‘java’java.lang.System.setProperty(‘key’, ‘value’)java_import java.util.HashMaphashmap = HashMap.newhashmap[‘key’] = ‘value’
  • 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. TorqueBox
  • 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. But Can’t I Already Run JRubyApps in My Java App Server?
  • 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. So Why TorqueBox?
  • 18. So Why TorqueBox?Ruby as a first-class citizen in the enterprise
  • 19. Familiar to Ruby DevsMake changes then refresh the browser
  • 20. Familiar to Java Devs Just JBoss AS7 underneath
  • 21. So Why TorqueBox?Ruby interfaces to services provided by the application server
  • 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. TorqueBox•applications & Rack Rails, Sinatra,
  • 24. TorqueBox•applications & Rack Rails, Sinatra,•More than just web •Messaging •Jobs •Services •Caching
  • 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. 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. Usagetorquebox deploy ~/my_ruby_apptorquebox run
  • 28. TorqueBox•applications & Rack Rails, Sinatra,•More than just web •Messaging •Jobs •Services •Caching
  • 29. Messaging
  • 30. Message Processorsapp/models/print_handler.rbinclude TorqueBox::Messagingclass PrintHandler < MessageProcessor  def on_message(body)    puts "Processing #{body} of #{message}"  endend
  • 31. Message Processorsconfig/torquebox.ymlqueues: /queues/receipts:messaging: /queues/receipts: PrintHandler: concurrency: 5
  • 32. Backgroundable
  • 33. Regular Classclass Something def foo sleep 5 endend
  • 34. Blocking Invocationssomething = Something.newsomething.foo
  • 35. Backgroundableclass Something include TorqueBox::Messaging::Backgroundable def foo end def bar endend
  • 36. Non-Blocking Invocationssomething = Something.newsomething.background.foo
  • 37. See The Futuresomething = Something.newfuture = something.background.foo
  • 38. See The Futurefuture.started?future.complete?future.error?future.result
  • 39. See The Futureclass Something def foo ... count += 1 future.status = count ... endend
  • 40. See The Future# on the client sidefuture.status_changed?future.status # => 42
  • 41. Scheduled Jobs
  • 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. Scheduled Jobsconfig/torquebox.ymljobs: monthly_newsletter: description: first of month job: NewsletterSender cron: ‘0 0 0 1 * ?’
  • 44. Services
  • 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. Servicesapp/services/time_machine.rbclass TimeMachine def run until @done @queue.publish(Time.now) sleep(1) end endend
  • 47. Servicesconfig/torquebox.ymlservices: TimeMachine: config: queue: /queue/time
  • 48. Caching
  • 49. Rails Caching config/application.rbmodule MyApp class Application < Rails::Application ... config.cache_store = :torque_box_store endend
  • 50. Explicit Cachinginclude ActiveSupport::CachemyCache = TorqueBoxStore.new(:name => MyCache, :mode => :replicated, :sync => true)
  • 51. Clusteringtorquebox run --clustered
  • 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. 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. 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. Java & Ruby Messagingconsumer.rbqueue = inject(‘/queues/my_queue’)message = queue.receive(:decode => false)puts message.text# prints “hi”
  • 56. PicketLink & Rubyauthenticator = TorqueBox::Authenticator[‘jmx-console’]authenticator.authenticate(‘username’, ‘password’) do some_authenticated_actionend
  • 57. Java Management
  • 58. Resources•http://torquebox.org•https://github.com/torquebox•#torquebox on FreeNode•@torquebox on Twitter
  • 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/