Joine Music

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 21 May 2007

JRuby on Rails - Agility for the Enterprise (TS-9370 at JavaOne 2007)

Posted on 02:51 by Unknown
These are the notes I took on Charles and Toms talk at the 2007 JavaOne conference. The slides are also available and I'll link to the presentation when its up too, though for now, you have to put up with this...

"See how the other 8% lives"
Ruby is gaining in popularity and developer mindshare. This is largely due to the killer app that is Ruby on Rails (or "RoR"). JRuby is a Java implementation of the Ruby Interpreter (commonly referred to as "Matz's Ruby Interpreter" or MRI after its creator). Because Rails is written in Ruby, it is possible to run Rails apps on JRuby. Charles Nutter and Thomas Enebo have come to talk about it.

Charles started off life as a Java EE architect. Tom was a web app architect. Now they are both working on JRuby after having been hired by Sun. The aim is for it to become a first class language citizen on the JVM.

"What is Ruby?"
  • It's a dynamically typed language
  • It's fully object oriented
  • It is designed to be simple, productive and fun to use
  • It is interpreted (rather than compiled)
  • The original interpreter, MRI, is written in C (and is sometimes referred to as "CRuby" by the JRuby crowd
  • The implementation (which is open source) is the only specification (though this may change)
  • It was created to be "more powerful than Perl and more OO than Python"
Pure OO
Example:
7.class => Fixnum
There is also sweet syntactic sugar for literals:
  • For regex
  • Literal arrays on 1 line
  • Associative arrays / hashes
  • Strings: "foo"
Dynamically Typed
Ruby doesn't care about an Objects type, only about the operations which it can perform. Consequently it throws "no method error" runtime exceptions.

Modules
Ruby only has single inheritance. However it also includes Modules (also called "Mixins") which you can include in your classes to provide additional functionality. They are a mix between Java's Interfaces and Abstract Classes.

Blocks
Blocks (which are also referred to as "closures" in other languages) are methods that you can pass around your code and invoke when you want to. This invokation is on the end of the method call and means that you can remove repetitive code and defer things such as the logic of iteration to collections themselves, allowing them to call out to the block for the processing logic at each step.

They also allow you to internalise transaction code. E.g.
File.open(filename) { | file | line = file.gets }
In this example the file is autoamtically closed. You need not worry about this as a programmer.

It is for these reasons that closures are under consideration for inclusion in the Java language.

Meta Programming
In Ruby Classes and Modules are always open. This means that you can dynamically include them at any point. You can also provide dispatch methods such as method_missing which intercepts and safely handles calls to non existent methods. There is an equivalent const_missing variable.

"What is JRuby?"
The JRuby project was started in 2002 and is a Pure Java, open source implementation of MRI. It is aiming for full compatability with the current Ruby (v. 1.8). This compatability is the primary focus, over performance.

It integrates with Java via the Bean Scripting Framework, JSR-223 and Spring. It is supported by a growing set of external projects such as Goldspike and ActiveRecord-JDBC.

"Why JRuby over Ruby?"
  • Soon it will be faster (the team are working on a compiler so you can run your Ruby applications as JVM bytecode)
  • Scales better (it uses native threads whereas CRuby uses green threads)
  • Native unicode support (CRuby is working on this now, JRuby leverages Java)
  • Integration with the Java libraries (include "java")
  • Easier path into the enterprise - how? See below...
"Why JRuby over Java?"
  • Language features available now (blocks, modules, metaprogramming)
  • Ruby applications / libraries (Rails, RSpec, Rake, Raven, etc)
Ruby on Rails
Rails is a full stack MVC framework written in Ruby which is open sourced under the MIT licence. It was released in 2004 and was written by David Heinemeier Hansson. RoR books already outsell those on Perl. It has a single threaded, share-nothing architecture and ships with MacOS X Leopard.

Rails Precepts
  • Convention over configuration - Based on the philosophy of "why punish the common cases?" this encourges standard practices by making them as simple as possible. In many cases, there is nothing for the developer to do at all. This makes everything simpler and smaller
  • Don't Repeat Yourself ("DRY") - Everything in RoR is written with the minimum of repetition. Repeated code is hard to adapt, maintain and less agile
  • Agility - RoR apps run from the forst command you type. There is no configuration of your environment. This allows for true iterative development from the very beginning. You can show what you do and see your changes live
"Why use Rails?"
  • Greatly Simplified - There is a lot less code in a Rails app than a comparable Java Web App
  • Instant Applications
  • Growing and excited community
  • Small applications are trivial to create
  • Excellent language
"Why use JRuby on Rails?"
  • You can deploy to Java Application Servers as a self contained WAR (using Goldspike)
  • These java web containers environments are already pervasive - it is easier for an enterprise to switch their MVC framework than a whole deployment architecture. Therefore the barrier to entry is reduced
  • Broader, more scalable database support (with ActiveRecord-JDBC)
  • Integration with Java libraries and legacy services - leverage your existing APIs and services
Rails Project Layout
Each Rails project has the same layout (Convention over Configuration at work).
myapp
app
controller - the "C" of MVC
helpers - DRY extracted code from the other app elements
model - the "M" of MVC
views - the "V" of MVC
config - config files
db - db config and migrations files
lib - libraries
public - static html content
test - unit tests
You put your code in the controllers and views. There is no need to wire everything up unlike in Struts or JSF.

Rails Tools - CLI
# rails myapp - Creates a rails app with the above structure called "myapp"
# ruby script/generate - Generates the MVC, migrations and scaffolding etc for your rails app
Components
  • ActiveRecord - "ORM on steroids"
  • ActivePack - View/Controller
  • ActiveWebServer
  • ActiveMail - Mail support
  • ActiveSupport
The Demo
NOTE: What follows are my notes from the demo of pertinent points made. No attempt is made to convey the content of the demo as a whole)
  • We are running in Rails development mode
  • "Migration" - This is a DB agnostic way to specify a DDL in Ruby. They are versioned and allow for a replayable record of DB schema changes (hence "migration"). This allows a developer to save these to VCS and in the future set up the DB to a specific schema version
  • Rake is like make/ant but written in Ruby. It's not just for Ruby
  • # rake db:migrate - generate a schema on your DB for the migration chosen
  • Scaffolding - allows you to be up and running quickly. It generates the simple MVC components for an entity
  • Deployment to a Java Application Server (e.g. Glassfish)
    • Use goldspike to create a WAR file automatically which contains my application and all the libaries (Ruby and Java) which I need to run my Rails app.
    • war.rb is the config file
    • Library dependencies are drawn from maven
    • # RAILSENV=PRODUCTION rake db : migration - Change to production mode
    • # rake war : standalone : create - WAR up your app. This is all you need to deploy
"Why Run on Glassfish?"
  • Multithreading - when you run Rails in an application server extra JRuby servers spin up as you need them. In CRuby you need a "pack" of single threaded Mongrel web servers.
  • Pool DB connections (there is no DB connection pooling on CRuby Rails)
  • Access any JNDI API resource from your Rails app
  • Access any JPA datasource
  • Therefore this is a new way to do the front end of your Java EE application
Futures
  • Rubify the JEE platform APIs
  • Port the Ruby native libraries (some Ruby libraries are partially or wholly written in C and cannot be used with JRuby)
  • Mingle from Thoughtworks - Software tool to manage agile IT projects written totally in JRuby
  • ActiveJPA and ActiveHibernate
Email ThisBlogThis!Share to XShare to Facebook
Posted in jruby rails javaone charlesnutter thomasenebo | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • (no title)
    The Significance and Importance of Quotes in JSTL EL I just spent a few hours debuggung a null pointer in a Portlet JSP I'm writing. It...
  • (no title)
    Agile Development Ramblings: Part I Introduction I've just completed my first Agile development project. We developed a fully functiona...
  • EJB 3.0 Outside the Container, Inside the JVM - Part 2: Configuring JPA Declaratively
    Welcome to part two of this blog entry introducing using EJB3.0 inside the JVM. Click here to view the first part. As we've seen, JPA ...
  • Reuse (ii): Definition of Done
    As I said in my previous post , our project has suddenly taken a new path. There are two bits of collateral which I'd recently produced...
  • Notes from the FindBugs BOF9231 at JavaOne 2007
    NOTE: These are my incomplete notes from the FindBugs BOF at JavaOne 2007. I got in late due to the crush outside so missed the start of th...
  • Writing Unit Tests to Ensure Your "@Transactional ... rollbackFor" Annotations are Honoured
    Thanks to Russ Hart for providing the info on how to get this to work.  I just cut and paste, and then blogged it. It's nice to write un...
  • (no title)
    Can Your Own Demo I found something great on t'internet the other day. I had been asked to do a demo of our new ystem to some users but...
  • JavaOne Bred Over-Enthusiasm...
    I want to build and fiddle with Wonderland , and my own JDK ! The problem is my graphics card sucks (I need acceleration) and I'm runnin...
  • Booting Apache Derby ("JavaDB") with your Java App's Startup
    If you're embedding the Derby RDBMS with your java desktop application and want it to start when you start your app, you need to make th...
  • STS and RTC – Getting them to Play Nice
    We’re developing our new app using Spring 3.0 RC1 and we want the best tools available. We’ve picked the following: SpringSource Tools ...

Categories

  • 0
  • 2008
  • ant maven pimp build javaone 2008
  • apple ipod touch
  • asm
  • blog new ruby
  • blogtag list
  • bond casinoroyale mashup mi6 film movie
  • build
  • bytecode
  • CI
  • cobertura
  • communityone 2008 nutter jvm scala jruby groovy davinci
  • communityone 2008 opensocial socialsite
  • communityone javaone keynote oreilly
  • configuration
  • cowley
  • css div layout column ie firefox safari example
  • custom
  • darkstar mpk20 wonderland java3d commaboration SL
  • dashboard rss communication news development
  • db2 database SQL max min howto tip
  • db2 database ibm lessons tips
  • db2 database load batch howto example
  • db2 import upload data howto command
  • debt technical java annotation
  • debugging tips javaone 2008
  • development web2.0
  • findbugs JavaOne 2008 pugh
  • findbugs JavaOne BOF notes
  • gafter closures java javaone notes
  • google trouble patriarchal patriarchy
  • groovy metaprogramming javaone 2008
  • grubby oss data generation project announce
  • guice javaone 2008
  • gwt maven howto example simple
  • howto
  • hudson
  • hudson CI javaone 2008
  • ibm
  • invokeDynamic jvm dynamic ruby javaone
  • itinerant web2.0 portable desktop
  • jacl was websphere wsadmin trace logging
  • james gosling sun java open source tech days second life SL
  • jar java manifest properties config howto tip
  • java
  • java applet javaone 2008 reloaded jnlp
  • java javafxscript javaone 2008 fxscript
  • java javaone 2007 07
  • java javaone 2008 bytecode cobertura asm singleton testability
  • javaone
  • javaone keynote gage schwarz javafx
  • javaone semantic web bof notes web3
  • jazz
  • jruby rails javaone charlesnutter thomasenebo
  • jruby ruby netbeans development
  • kill dead laptop computer rebuild restore
  • lessonslearned
  • mac osx java gui shellscript classpath problem solution
  • maven plugin unittest test packager
  • mylin mylar javaone eclipse 2008
  • netbeans development ide
  • netbeans development ide RC
  • netbeans maven2 profiling
  • netbeans ruby sun tech days visual web pack roman strobl
  • ola bini java javaone 2008 thoughtworks ruby jruby
  • openjdk java javaone javafx wonderland
  • overheard
  • pojo ejb3.0 jpa orm java example howto
  • rant
  • rest restful jsr311 java web2.0 javaone ts-6411
  • rome rss feed blog rss atom propono java javaone
  • rsa uml profile plugin howto
  • ruby inheritance example
  • ruby jruby rss xml hpricot
  • ruby unless example
  • scm
  • setup
  • subversion svn xp windows cleanup
  • sun java soa web2.0 netbeans opensource javacaps
  • sun tech days java derby database rdbms london
  • sun tech days london impressions
  • terracotta java javaone 2008 android gwt
  • tip
  • tips
  • vwp netbeans JPA howto
  • was jython scripting nfr ibm pmi jvm
  • was tpv jython scripting nfr ibm pmi
  • webrick ruby jruby actadiurna investigation code howto
  • workitem

Blog Archive

  • ►  2012 (1)
    • ►  October (1)
  • ►  2010 (8)
    • ►  November (1)
    • ►  October (3)
    • ►  June (1)
    • ►  May (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2009 (9)
    • ►  December (1)
    • ►  November (5)
    • ►  March (2)
    • ►  February (1)
  • ►  2008 (22)
    • ►  December (1)
    • ►  November (3)
    • ►  May (15)
    • ►  March (1)
    • ►  January (2)
  • ▼  2007 (53)
    • ►  December (1)
    • ►  November (3)
    • ►  September (3)
    • ►  August (2)
    • ►  July (3)
    • ►  June (1)
    • ▼  May (12)
      • Notes from the FindBugs BOF9231 at JavaOne 2007
      • JavaOne 2007 - Closures for the Java Language - TS...
      • RESTful Web Services: JSR-311 (TS-6411) at JavaOne...
      • JRuby on Rails - Agility for the Enterprise (TS-93...
      • JavaOne Bred Over-Enthusiasm...
      • Dynamic Languages in the JVM - Discussion Notes fr...
      • Notes: Beyond Blogging: Feeds In Action Technical ...
      • Project Wonderland BOF (BOF-1306) @ JavaOne 2007
      • JavaOne 2007 Day One Keynote - Ubiquitous JVMs
      • JavaOne 2007 (Day 1 – CommunityOne) Keynote with ...
      • JavaOne 2007 (Day 1 – CommunityOne) Hot, Damn Hot
      • Going to JavaOne 2007...
    • ►  April (5)
    • ►  March (13)
    • ►  February (7)
    • ►  January (3)
  • ►  2006 (35)
    • ►  December (8)
    • ►  October (1)
    • ►  August (1)
    • ►  July (5)
    • ►  June (8)
    • ►  May (3)
    • ►  April (7)
    • ►  March (2)
Powered by Blogger.

About Me

Unknown
View my complete profile