Your SlideShare is downloading. ×
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Практики применения JRuby
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Практики применения JRuby

1,397

Published on

* История JRuby; …

* История JRuby;
* Платформа JVM и ее возможности;
* Почему стоит попробовать JRuby;
* Как мы в Хот Спот используем JRuby для разработки;
* Сравнение с другими JVM языками.

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

No Downloads
Views
Total Views
1,397
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
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
  • \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
  • \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
  • \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
  • \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
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. JRubyПрактика применения
    • 2. Short history
    • 3. Short history• 2001 - the first version of JRuby(by Jan Arne Petersen)
    • 4. Short history• 2001 - the first version of JRuby(by Jan Arne Petersen)• 2006 - version 0.9.0(by Charles Nutter, Thomas Enebo, Ola Bini and Nick Siege)
    • 5. Short history• 2001 - the first version of JRuby(by Jan Arne Petersen)• 2006 - version 0.9.0(by Charles Nutter, Thomas Enebo, Ola Bini and Nick Siege)• 2007 - version 1.0(passed all Rails tests)
    • 6. Why JRuby?
    • 7. Why JRuby?• Multithreading
    • 8. Why JRuby?• Multithreading• JVM
    • 9. Why JRuby?• Multithreading• JVM• Cross-platform
    • 10. Why JRuby?• Multithreading• JVM• Cross-platform• Just another .jar
    • 11. Why JRuby?• Multithreading• JVM• Cross-platform• Just another .jar• GUI
    • 12. Why JRuby?• Multithreading• JVM• Cross-platform• Just another .jar• GUI• Android
    • 13. JVM
    • 14. JVM• Concurrent threading
    • 15. JVM• Concurrent threading• Garbage collectors
    • 16. JVM• Concurrent threading• Garbage collectors• JIT compiler
    • 17. JVM• Concurrent threading• Garbage collectors• JIT compiler• invokedynamic(JDK 7)
    • 18. Missing features
    • 19. Missing features• Memory footprint
    • 20. Missing features• Memory footprint• No Kernel#fork
    • 21. Missing features• Memory footprint• No Kernel#fork• No continuations(callcc)
    • 22. Missing features• Memory footprint• No Kernel#fork• No continuations(callcc)• ObjectSpace off by default(-X+O to enable)
    • 23. Missing features• Memory footprint• No Kernel#fork• No continuations(callcc)• ObjectSpace off by default(-X+O to enable)• set_trace_func off by default(--debug to enable)
    • 24. C extensionssince JRuby 1.6(still experimental)
    • 25. Easy installing• rvm install jruby• rbenv install jruby-1.6.6 (*)• Download from http://jruby.org
    • 26. Compatibilities Ruby 1.8.7 & 1.9.2 compatible (default 1.8)flag `jruby --1.9` for 1.9.2 compatibility
    • 27. Nailgun(since 1.3.0 version)
    • 28. Nailgun (since 1.3.0 version)Nailgun is a client, protocol, and server for running Java programs in the server.
    • 29. Nailgun (since 1.3.0 version)Nailgun is a client, protocol, and server for running Java programs in the server. $ jruby --ng-server & $ jruby --ng -e "puts 1"
    • 30. Multi-VM support many apps in one process
    • 31. Multi-VM support many apps in one process JVM
    • 32. Multi-VM support many apps in one processJRuby JRuby JRuby JRuby JRuby JVM
    • 33. Benchmarksjruby 1.7.0.dev(JDK 6) jruby 1.7.0.dev(JDK 7) invokedynamic=falsejruby 1.7.0.dev(JDK 7) ruby 1.9.3-p0
    • 34. Benchmarks jruby 1.7.0.dev(JDK 6) jruby 1.7.0.dev(JDK 7) invokedynamic=false jruby 1.7.0.dev(JDK 7) ruby 1.9.3-p043210 bench/bench_red_black.rb (sec)
    • 35. Benchmarks jruby 1.7.0.dev(JDK 6) jruby 1.7.0.dev(JDK 7) invokedynamic=false jruby 1.7.0.dev(JDK 7) ruby 1.9.3-p043210 bench/bench_red_black.rb (sec)
    • 36. Benchmarks jruby 1.7.0.dev(JDK 6) jruby 1.7.0.dev(JDK 7) invokedynamic=false jruby 1.7.0.dev(JDK 7) ruby 1.9.3-p043210 bench/bench_red_black.rb (sec)
    • 37. Benchmarks jruby 1.7.0.dev(JDK 6) jruby 1.7.0.dev(JDK 7) invokedynamic=false jruby 1.7.0.dev(JDK 7) ruby 1.9.3-p043210 bench/bench_red_black.rb (sec)
    • 38. Benchmarks jruby 1.7.0.dev(JDK 6) jruby 1.7.0.dev(JDK 7) invokedynamic=false jruby 1.7.0.dev(JDK 7) ruby 1.9.3-p043210 bench/bench_red_black.rb (sec)
    • 39. jvisualvm
    • 40. jvisualvm
    • 41. jvisualvm
    • 42. JVM + JRuby
    • 43. JVM + JRuby• Swing, SWT
    • 44. JVM + JRuby• Swing, SWT• JavaFX
    • 45. JVM + JRuby• Swing, SWT• JavaFX• Spring & Hibernate
    • 46. JVM + JRuby• Swing, SWT• JavaFX• Spring & Hibernate• Scala, Groovy, Jython, Clojure, ...
    • 47. JVM + JRuby Swing
    • 48. JVM + JRuby Swing
    • 49. RedCar SWT
    • 50. Java + Ruby
    • 51. Java + Ruby• require ‘java’
    • 52. Java + Ruby• require ‘java’• Java namespace
    • 53. Java + Ruby• require ‘java’• Java namespace• Snake case(get_some vs getSome)
    • 54. Java + Ruby• require ‘java’• Java namespace• Snake case(get_some vs getSome)• Ruby-style accessors(length= vs setLength)
    • 55. Java + Ruby• require ‘java’• Java namespace• Snake case(get_some vs getSome)• Ruby-style accessors(length= vs setLength)• Converting types
    • 56. Java + Ruby• require ‘java’• Java namespace• Snake case(get_some vs getSome)• Ruby-style accessors(length= vs setLength)• Converting types• Swing IRB(command: jirb_swing)
    • 57. Java bridge Collections
    • 58. Java bridge CollectionsJava List:java_list[0]java_list << 5java_list += 7
    • 59. Java bridge CollectionsJava List: Java Map:java_list[0] java_list[‘key’]java_list << 5 java_list[‘key’] = 5java_list += 7
    • 60. Java bridge CollectionsJava List: Java Map:java_list[0] java_list[‘key’]java_list << 5 java_list[‘key’] = 5java_list += 7 Ruby List: [1, 2, 3].to_java :int [“string”].to_java :string
    • 61. Java bridge OverloadingJava:public class Test { public boolean isSome(String arg) {...} public boolean isSome(int arg) {...} public boolean isSome(long arg) {...} public boolean isSome(Object arg) {...}}
    • 62. Java bridge OverloadingRuby:Test.new.java_send :isSome, [Java::long], 1_000orclass Test java_alias :is_some, :isSome, [Java::long] ...end
    • 63. Java bridge AnnotationsJava:@Bean(scope = Scope.PROTOTYPE)public class Person { ...}
    • 64. Java bridge AnnotationsRuby:java_import Beanjava_import Scopeclass PersonendPerson.add_class_annotation(Bean: { ‘scope’ => Scope.PROTOTYPE})Person.become_java!
    • 65. Java bridge InterfacesRuby:class Posts include java.util.Iteratorend
    • 66. JRuby compiler Ahead-Of-Time Compilation$ jrubyc <script name>.rb$ java -cp .:/path/to/jruby.jar <script name>
    • 67. JRuby compiler Generate .java classes from .rb$ jrubyc --java <script name>.rb
    • 68. JRuby compilerRuby:require javaclass Vec def initialize(x, y) @xcoord = x @ycoord = y endend
    • 69. JRuby compilerRuby:require javaclass Vec java_signature Vec(double x, double y) def initialize(x, y) @xcoord = x @ycoord = y endend
    • 70. JRuby compilerJava:import org.jruby.Ruby;import org.jruby.RubyObject;import org.jruby.RubyClass;...public class Vec extends RubyObject { ... public Vec(double x, double y) { ... }}
    • 71. Rake + Ant
    • 72. Rake + AntAnt tasks like Rake tasks:task :ant_import do ant_importend
    • 73. Buildr http://buildr.apache.org Apache Buildr is a build system for Java-basedapplications, including support for Scala, Groovy and a growing number of JVM languages and tools.
    • 74. Buildrhttp://buildr.apache.org
    • 75. Buildr http://buildr.apache.org• Projects and sub-projects
    • 76. Buildr http://buildr.apache.org• Projects and sub-projects• Compiling, copying and filtering resources, test cases, Javadoc and more
    • 77. Buildr http://buildr.apache.org• Projects and sub-projects• Compiling, copying and filtering resources, test cases, Javadoc and more• Builds what has changed since the last release
    • 78. Buildr http://buildr.apache.org• Projects and sub-projects• Compiling, copying and filtering resources, test cases, Javadoc and more• Builds what has changed since the last release• Support Maven 2.0
    • 79. Buildr http://buildr.apache.org• Projects and sub-projects• Compiling, copying and filtering resources, test cases, Javadoc and more• Builds what has changed since the last release• Support Maven 2.0• Support Ant
    • 80. Buildr http://buildr.apache.org• Projects and sub-projects• Compiling, copying and filtering resources, test cases, Javadoc and more• Builds what has changed since the last release• Support Maven 2.0• Support Ant• Buildr is Ruby all the way down
    • 81. Buildr http://buildr.apache.orgbuildfile:repositories.remote "http://repo.typesafe.com/typesafe/releases/"desc "The Springmongodb project"define "SpringMongoDB" do project.version = "0.1" project.group = "SpringMongoDB" run.with "org.jruby:jruby-complete:jar:1.6.6", "org.mongodb:mongo-java-driver:jar:2.7.2", "org.springframework:spring-core:jar:3.1.0.RELEASE", "org.springframework:spring-context:jar:3.1.0.RELEASE", "org.springframework:spring-beans:jar:3.1.0.RELEASE", org.springframework.data:spring-data-commons-core:jar:1.1.0.RELEASE, "org.springframework.data:spring-data-mongodb:jar:1.0.0.RC1" run.using main: [org.jruby.Main, _(:src, :main, :ruby, "app.rb")]end
    • 82. Rawr http://rawr.rubyforge.orgRawr, a packaging and deployment tool, that allows turns yourcode into an executable jar, a .exe for Windows, and a .app forOS X.
    • 83. Rawrhttp://rawr.rubyforge.org $ gem install rawr $ rawr install ... $ rake rawr:jar
    • 84. Deployment
    • 85. JRuby-Rack Servlet JRuby-Rack Rack Rackcontainer servlet filter application
    • 86. JRuby servers
    • 87. JRuby servers WEBrick
    • 88. JRuby servers WEBrick Trinidad
    • 89. JRuby servers WEBrick Trinidad TorqueBox
    • 90. TorqueBoxhttp://torquebox.org
    • 91. TorqueBoxhttp://torquebox.org
    • 92. TorqueBox http://torquebox.orgInstallation:jruby -S gem install torquebox-server --pre
    • 93. TorqueBox http://torquebox.orgUsage:torquebox deploy ~/Projects/rails_apptorquebox run
    • 94. Warbler Warbler is a gem to make a Java jar or war fileout of any Ruby, Rails, Merb, or Rack application.
    • 95. WarblerInstallation:jruby -S gem install warbler
    • 96. WarblerUsage:
    • 97. Warbler
    • 98. WarblerStandalone application:
    • 99. Tuning flags
    • 100. Tuning flags• --server - server compiler
    • 101. Tuning flags• --server - server compiler• -Xmx - max heap size
    • 102. Tuning flags• --server - server compiler• -Xmx - max heap size• -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC - new GC(JDK 7)
    • 103. Clouds• Amazon Elastic Beans(http://aws.amazon.com/ elasticbeanstalk/)• Jelastic(http://jelastic.com)• Engine Yard(http://www.engineyard.com)• Google App Engine(http:// appengine.google.com)
    • 104. Hot Spot
    • 105. Bot Hunter
    • 106. Bot Hunter• Multithreading
    • 107. Bot Hunter• Multithreading• Some logic on Scala
    • 108. Yukihiro Matsumoto: “I would remove thethread and add actors or some other moreadvanced concurrency features”.
    • 109. Akka http://akka.io/Simpler Concurrency, Scalability & Fault- tolerance through Actors slidesha.re/akka-scala-days-2010
    • 110. Actor Model of Concurrency slidesha.re/akka-scala-days-2010
    • 111. Actor Model of Concurrency• Implements Message-Passing Concurrency slidesha.re/akka-scala-days-2010
    • 112. Actor Model of Concurrency• Implements Message-Passing Concurrency• Share nothing slidesha.re/akka-scala-days-2010
    • 113. Actor Model of Concurrency• Implements Message-Passing Concurrency• Share nothing• Isolated lightweight process slidesha.re/akka-scala-days-2010
    • 114. Actor Model of Concurrency• Implements Message-Passing Concurrency• Share nothing• Isolated lightweight process• Communicates through messages slidesha.re/akka-scala-days-2010
    • 115. Actor Model of Concurrency• Implements Message-Passing Concurrency• Share nothing• Isolated lightweight process• Communicates through messages• Asynchronous and non-blocking slidesha.re/akka-scala-days-2010
    • 116. Actor Model of Concurrency• Implements Message-Passing Concurrency• Share nothing• Isolated lightweight process• Communicates through messages• Asynchronous and non-blocking• Each actor has a mailbox(message queue) slidesha.re/akka-scala-days-2010
    • 117. Two different models slidesha.re/akka-scala-days-2010
    • 118. Two different models• Thread-based slidesha.re/akka-scala-days-2010
    • 119. Two different models• Thread-based• Event-based slidesha.re/akka-scala-days-2010
    • 120. Two different models• Thread-based• Event-based • Very lightweight(~300 bytes per actor) slidesha.re/akka-scala-days-2010
    • 121. Two different models• Thread-based• Event-based • Very lightweight(~300 bytes per actor) • Can easily create millions on a single workstation slidesha.re/akka-scala-days-2010
    • 122. Example slidesha.re/akka-scala-days-2010
    • 123. Server codeclass HelloWorldActor extends UntypedActor { public void onReceive(Object msg) { getContext().tryReply(msg + " World"); }}remote().start("localhost", 2552).register( "hello-service", actorOf(HelloWorldActor.class)); slidesha.re/akka-scala-days-2010
    • 124. Client codeactor = Actors.remote.actorFor( "hello-service", "localhost", 2552)res = actor.ask("Hello").get slidesha.re/akka-scala-days-2010
    • 125. The Bad
    • 126. java.lang.NullPointerException
    • 127. Groovy
    • 128. Questions?Email: klimtimothy@gmail.com

    ×