Exploiting JRuby: Building Domain-Specific Languages for the Java Virtual Machine

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Exploiting JRuby: Building Domain-Specific Languages for the Java Virtual Machine - Presentation Transcript

    1. Exploiting JRuby: Building Domain-Specific Languages for the Java Virtual Machine™ Rob Harrop VP Interface21 http://www.interface21.com TS-9294 2007 JavaOneSM Conference | Session TS-9294 |
    2. Goal of This Talk What you will gain Learn how to create and exploit domain-specific languages for the Java Virtual Machine™ (JVM™) using JRuby. The terms “Java Virtual Machine” and “JVM” mean a Virtual Machine for the Java™ platform. 2007 JavaOneSM Conference | Session TS-9294 | 2
    3. Agenda Introduction to DSLs DSLs in Action Techniques for DSLs in JRuby Decomposing DSLs Elements of DSL Style Summary Q&A 2007 JavaOneSM Conference | Session TS-9294 | 3
    4. Agenda Introduction to DSLs DSLs in Action Techniques for DSLs in JRuby Decomposing DSLs Elements of DSL Style Summary Q&A 2007 JavaOneSM Conference | Session TS-9294 | 4
    5. Introduction to DSLs What is a DSL? • Domain-specific language • Custom language designed for a specific purpose • Not just about business-specific domains • General purpose examples • Build language (rake) • Application management (MScript—coming soon!) • Business examples • Derivative calculation • Corporate action entitlement calculation 2007 JavaOneSM Conference | Session TS-9294 | 5
    6. Introduction to DSLs Why bother? • Greatly simplify repetitive tasks • Java Management Extensions (JMX™)? • Encapsulate boilerplate code • Provide an API that expresses the intent of the code clearly • Invest a little up front to save a lot in the future • DSLs should deliver clear value 2007 JavaOneSM Conference | Session TS-9294 | 6
    7. Introduction to DSLs Use cases for DSLs • Simplify/encapsulate some API • JMX API, for example • Abstract complex business problems • Corporate action processing • Support operational control of an application • Script maintenance tasks 2007 JavaOneSM Conference | Session TS-9294 | 7
    8. Introduction to DSLs Classifying DSLs • Type • External—XML • Internal—JRuby, Groovy • Target • General purpose—MScript • Business-specific—CAScript 2007 JavaOneSM Conference | Session TS-9294 | 8
    9. Agenda Introduction to DSLs DSLs in Action Techniques for DSLs in JRuby Decomposing DSLs Elements of DSL Style Summary Q&A 2007 JavaOneSM Conference | Session TS-9294 | 9
    10. DEMO DSLs in Action—Rake and MScript 2007 JavaOneSM Conference | Session TS-9294 | 10
    11. Agenda Introduction to DSLs DSLs in Action Techniques for DSLs in JRuby Decomposing DSLs Elements of DSL Style Summary Q&A 2007 JavaOneSM Conference | Session TS-9294 | 11
    12. Techniques for DSLs in JRuby Operator overloading • Operator overloading allows natural syntax for common functions • Concatenation, addition • Attribute/index access Example from MScript: puts mbean[:SomeAttribute] mbean[:SomeAttribute] = \"Hello World!\" 2007 JavaOneSM Conference | Session TS-9294 | 12
    13. Techniques for DSLs in JRuby Hashes and symbols • Symbols are a great way to identify objects in your DSL • Tasks in rake • Hashes are great for expressing relationships • Task dependency in rake task :run-application => :setup 2007 JavaOneSM Conference | Session TS-9294 | 13
    14. Techniques for DSLs in JRuby Blocks • Encapsulate executable logic • Paired with symbols to identify this logic • Task actions in rake task :run-application => :setup do ruby \"application.rb\" end 2007 JavaOneSM Conference | Session TS-9294 | 14
    15. Techniques for DSLs in JRuby Method missing • Great advantage over Java platform • No need to know all operations in advance— but get natural call syntax • JMX technology operations on a MBean proxy in MScript 2007 JavaOneSM Conference | Session TS-9294 | 15
    16. Techniques for DSLs in JRuby Dynamic type extension • Another brilliant advantage over Java platform • Dynamically add methods to classes and objects • Attribute access in MScript 2007 JavaOneSM Conference | Session TS-9294 | 16
    17. Techniques for DSLs in JRuby Java technology integration • Manipulate Java platform domain logic using JRuby • Take full advantage of existing investment • Add in DSLs where they make sense • Get the best of both worlds 2007 JavaOneSM Conference | Session TS-9294 | 17
    18. Techniques for DSLs in JRuby Options for Java technology integration • Access Java platform from Ruby using JRuby • include_class etc • Access Ruby from Java platform using JRuby API • This is reasonably complex • Bi-directional access • Critical for DSLs that aim to simplify Java technology usage • Spring integration • Create beans using JRuby 2007 JavaOneSM Conference | Session TS-9294 | 18
    19. DEMO Techniques for DSLs in JRuby 2007 JavaOneSM Conference | Session TS-9294 | 19
    20. Agenda Introduction to DSLs DSLs in Action Techniques for DSLs in JRuby Decomposing DSLs Elements of DSL Style Summary Q&A 2007 JavaOneSM Conference | Session TS-9294 | 20
    21. Decomposing DSLs • All DSLs are composed of these common building blocks • As expected a higher level of abstraction is provided so as not to appear like basic method calls • Let’s dive into the code and look at these techniques in action 2007 JavaOneSM Conference | Session TS-9294 | 21
    22. DEMO Decomposing DSLs 2007 JavaOneSM Conference | Session TS-9294 | 22
    23. Agenda Introduction to DSLs DSLs in Action Techniques for DSLs in JRuby Decomposing DSLs Elements of DSL Style Summary Q&A 2007 JavaOneSM Conference | Session TS-9294 | 23
    24. Elements of DSL Style Identify the problem, express the solution • DSLs are not simply Java code expressed in a dynamic language • Identify the problem and create a syntax that clearly expresses the solution task :run_application do ruby “application.rb” end 2007 JavaOneSM Conference | Session TS-9294 | 24
    25. Elements of DSL Style Metadata and behaviour • DSL expressions typically contain metadata and behaviour as part of a single expression corporate_action :bonus_issue do |position, payout| entitlement :stock => position.quantity * payout.rate end Don’t let DSLs become another configuration file 2007 JavaOneSM Conference | Session TS-9294 | 25
    26. Elements of DSL Style Thinking the Ruby way • Use type extension in favour of if/else • Use blocks rather than anonymous types • Use methods on objects rather than statics 2007 JavaOneSM Conference | Session TS-9294 | 26
    27. Elements of DSL Style Characteristics of a DSL • Limited in scope • Address a small part of your domain • Limited in functionality • Only the features needed to address that part 2007 JavaOneSM Conference | Session TS-9294 | 27
    28. For More Information • Books • Programming Ruby (Thomas, Fowler and Hunt) • The Ruby Way (Fulton) • Web • http://jruby.codehaus.org • http://blog.interface21.com 2007 JavaOneSM Conference | Session TS-9294 | 28
    29. Q&A 2007 JavaOneSM Conference | Session TS-9294 | 29
    30. Exploiting JRuby: Building Domain-Specific Languages for the Java Virtual Machine™ Rob Harrop VP Interface21 http://www.interface21.com TS-9294 2007 JavaOneSM Conference | Session TS-9294 |

    + adorepumpadorepump, 11 months ago

    custom

    285 views, 1 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 285
      • 285 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 4
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags