Miles to go …

May 21, 2007

jMaki publish/subscribe and debugging

Filed under: web2.0 — arungupta @ 11:36 am

So far you’ve been playing with jMaki and created some Web and/or Rails applications. Let’s say you’ve gone a step ahead and some widgets in your application use jMaki’s publish/subscribe mechanism to talk with each other. Some jMaki widgets, such as Menu and Dynamic Container are pre-configured to publish and subscribe to the same topic. So if you develop a simple menu-based application then it’ll work without adding any glue code. Another example is Yahoo GeoCoder publishing and Yahoo Maps and Google Maps subscribing. This allows you to drop all three widgets together on the same page and if you enter a city and state in GeoCoder, the coordinates will show up in both the maps. So far so good, but what if you are writing custom publish and subscribe code and it’s not working. Lets see how we can debug that.

Let’s say there is a Yahoo Calendar and Data Table widget in the page. The Data Table displays stock tickers by pulling the data from quote servers for the current date. You’d like to modify the application such that whenever a date is selected in the Calendar widget, the Data Table refreshes itself by pulling quotes for that date.

The Calendar widget already publishes an event to “/yahoo/calendar/onSelect” topic. All you need to do is modify ‘component.js‘ in Web pages, resources, yahoo, dataTable subtree and listen to that topic. For that, you add the following statement:

jmaki.subscribe("/yahoo/calendar/onSelect", calendarListener);

on line 172 of ‘component.js‘. The ‘calendarListener’ function is defined as:

function calendarListener(item) {
    var targetDiv = document.getElementById("newpage");
    targetDiv.innerHTML = item.value;
}

On ‘index.jsp‘, where both the widgets live together, a new <div> is added:

<div id="newpage"></div>

Now any date selected in the calendar is printed on the page. The ‘calendarListener‘ function can be easily modified such that the dataTable is refreshed after processing the date.

We created a simple, yet powerful example, demonstrating jMaki publish/subscribe mechanism.

The mechanism is simple so it should just work even if there are custom widgets and they publish events to their own topic. But this is software so in all likelihood don’t be surprised if it does not :) But jMaki at least provide a way to debug that situation. Open ‘Web pages‘, ‘resources‘, ‘jmaki.js‘. Search for ‘this.debugGlue=false;this.debug=false;‘ in this file. Change the ‘false‘ to ‘true‘ and save the file. After you refresh your application in the browser window, the bottom-right portion of your browser window shows all the topics and messages published on it as shown below:

Happy debugging!

All jMaki Web applications can be deployed on GlassFish or Rails applications can be WARed and then deployed on GlassFish.

Technorati: jmaki glassfish rails rubyonrails

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

Gmail equivalence

Filed under: General — arungupta @ 10:49 am

a.r.u.n.g.u.p.t.a@gmail.com is the same as arungupta@gmail.com or a.rungup.ta@gmail.com.

Read for more details. New learning every day :)

Technorati: gmail

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

May 20, 2007

Tim Bray’s keynote session at Rails Conf

Filed under: web2.0 — arungupta @ 9:13 am

Tim Bray, Web Guy from Sun Microsystems gave the keynote session at Rails Conf 2007 yesterday (May 19). With 1600 attendees, it was quite a different experience from JavaOne last week which had approx 16,000 people. The session was to start @ 9am and we were made to wait until 8:55am outside the Ballroom.

Anyway, once the session started it was packed!

Tim started the session by asking questions and here is a sampler:

  • How many people work for startups ? – Approx 40%
  • How many work for non-startups, like Sun ? – Approx 40%
  • How many for service providers, like ThoughtWorks – Approx 20%
  • How many are using Ruby as the first programming language – Approx 5%
  • How many came to Ruby from:
    • Java – Approx 70%
    • Microsoft – Approx 40%
    • PHP – Approx 40%

He also announced Sun will donate servers to open-source Ruby projects. Showed screen shots of Mephisto source code in NetBeans 6 and RHTML debugging.

Tim invited Charles Nutter, JRuby core developer on the stage and asked "Why JRuby ?".

Charles: JRuby is a new different way of looking at Ruby. Because it runs on Java, it scales very well, tested thoroughly, allows Ruby to get into enterprises where Ruby and/or Rails have never entered and there is a vast amount of Java libraries accessible to Ruby developers.

Tim: Any gotchas ?
Charles: If not feeling the pain under Ruby, keep doing it. JRuby is not a solution to all problems. If you want to scale better or differently, then this may be your solution. This gets you into enterprises where there is no Ruby or Rails presence.

Tim: When will JRuby be released ?
Charles: JRuby RC is out and FCS will be released by month-end.

Charles also said to give JRuby tee-shirts (pretty cool looking and has Duke holding a Ruby gem) if you contribute to the project or submit patches. Here are some pictures of Tim:

One of the big questions that we were getting asked at the Sun pod was "What is Sun doing at Rails Conf ?". Tim answered that very clearly in his session:

Sun sells Computers, Infrastructures, Operating Systems (Solaris) which is driving biggest, hairiest, ugliest and yet highly-performant systems in the world. We have x4500 Thumper, M9000, Identity Management Solutions. And then we are a systems company so we have NetBeans – a highly productive Rails development environment, jMaki – rich set of widgets for Rails view, and GlassFish deployment of Rails applications.

Another couple of interesting topics that Tim touched on is:

  • How to make money on free products ?
    • Adoption – Aligns with Jonathan Schwartz (CEO of Sun) says "mindshare gets market share". Adoption is all about friction and the biggest is payment friction. Being open source allows you to get rid of that.
    • Deployment – After adoption, you see deployment.
    • Monetization at the point of value – The hypothesis is "No serious business will deploy any serious application on any serious solution unless it is supported."
  • Even if Rails is successful beyond our wildest dreams, Java, .NET and PHP will never go away. The solution is to deal with them and integrate them using REST. Here are some strong positives about Java – the platform, the language, a set of APIs, the community:
    • Highly concurrent with multiple threads in the JVM. This allows your application to scale much better.
    • Security in the JVM – Sandbox security allows to build robust internet-based applications
    • Universe of Java APIs is better than C, PHP and all other languages.
    • 6 million community of Java developers

I had to leave the session early because of setting up the booth but it was a great talk!

Check out the flickr stream for the show.

Technorati: railsconf sun jruby glassfish netbeans jmaki

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

May 19, 2007

7 miles on treadmill – boring

Filed under: Running — arungupta @ 8:24 am

One of the disadvantages of traveling on weekend is I miss my long distance road-running. This weekend because of Rails Conf 2007, I had to plan my long run on a treadmill. So anyway, I got up at 5:45am and planned a 10 miler on the treadmill (few more weeks for the marathon). I’m a road-runner and have never run that long a distance on treadmill but decided to give it a shot today. After running barely 4 miles I started feeling bored. I browsed through all the channels and it was either ‘Good Morning Weekend’ or something else. I finally hooked on to History channel which was showing a great program on F16 & F18. But even that couldn’t keep me around for long. The walls around me were the same, the scenery was not changing and I was sweating more than normal (what else to expect in a closed room!). I finally decided to stop at 7 miles, burnt lot of calories because I changed the gradient from 3 to 5 multiple times but it was quite boring!

I wonder how anybody can run 153.76 miles on a treadmill :)

Technorati: running treadmill

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

May 18, 2007

Sun @ Rails Conf 2007 – Keep coming!

Filed under: web2.0 — arungupta @ 4:36 pm


Sun is a diamond sponsor of Rails Conference 2007. At the booth we are showing how jMaki provides a rich set of widgets for Rails application. Also talk to us about how GlassFish V2 can provide a deployment environment for WAR-ed up RoR apps and how GlassFish V3 provides deployment of original packaging of RoR apps.

We are also showing the best platform for hosting Ruby on Rails — Sun Fire T2000, Sun Startup Essentials, NetBeans 6 great Ruby and Rails capabilities. And our booth is shared with Joyent. And then of course, we are giving a few sessions :)


We are loving the response so far, keep it coming!
 
Thanks to Lou for the pictures.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

jMaki Phobos made-for-each-other

Filed under: web2.0 — arungupta @ 6:00 am

If you could not attend JavaOne 2007 last week and would like to know how jMaki and Phobos are made-for-each-other, then watch this excerpt of the technical keynote (start @ 1:02 and finish @ 6:26). You’ll hear me presenting :-)

A complete detailed screen cast on how to build this demo is available here. I plan to post written instructions soon as well.

Technorati: javaone jmaki phobos web2.0

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

May 17, 2007

Getting Started with JRuby – Tutorial at RailsConf rails

Filed under: web2.0 — arungupta @ 1:01 pm
Earlier today, I attended Charles Nutter and Thomas Enebo "Your First Day with JRuby on Rails" tutorial at Rails Conf 2007. The key message is Ruby as the programming language and Java for the platform and libraries provides the best of both worlds to developers.

 

JRuby is 100% pure-Java implementation of the Ruby programming language. The goal is to use the power of Ruby programming language and leverage the power of Java platform. Read a more detailed tutorial here. All Ruby scripts work with JRuby instead of the original C-based implementation. Also the goal is NOT an attempt to alter Ruby or add incompatible features. You can download JRuby implementation, unzip it and set JRUBY_HOME to the installation directory. Here is a sample JRuby code:

1. require 'java'
2. include_class 'java.lang.ArrayList'
3. include_class 'javax.swing.JFrame'
4.
5. list  = ArrayList.new
6. frame = JFrame.new("Ruby SWINGS!")
7. list << frame
8. list.each { |f| f.set_size(200, 200) }
9. puts frame.title

The code above shows how Ruby and Java code can be mixed with each other. Line 1 includes Java support. Line 2 imports Java classes. Line 5 and 6 creates a new variables using a mix of Java and Ruby syntax. Line 7 and 8 uses the instance variables in Ruby syntax. Line 9 prints the title of the frame. If you run this code using JRuby interpreter then you get:

%JRUBY_HOME%/bin/jruby sample1.rb
Ruby SWINGS!

Here are some of the differences (from the original C-based implementation) in JRuby:

  1. Database support – This is required only if you want to re-use existing JDBC connection pool. Otherwise native adapter works fine and is preferred because of performance reasons.
    1. Change ‘database.yml‘ from

      development:
        adapter: mysql
        database: HelloWorld_development
        username: root
        password:
        host: localhost

      to

      development:
        adapter: jdbc
        driver: com.mysql.jdbc.Driver
        url: jdbc:mysql://localhost:3306/helloworld_development
        username: root
        password:

    2. Include "require 'jdbc_adapter'" in ‘environment.rb‘.
    3. Either set CLASSPATH to include JDBC driver (for example, MySQL Connector/J 5.0.5) or copy into ‘work/jruby/lib‘ directory.
  2. No Native extensions (at least, not until ports are available). Today, Mongrel, Hpricot are available. Database support and RMagick are in progress.
  3. Command-line performance – JVM performs much better after the first boot so don’t expect stellar command-line performance.

Here are some other points that the tutorial talked/showed:

  • Goldspike (nee rails-integration) that allows to WAR’up a RoR application.
  • Installation of GlassFish V3 as Ruby gem which will be released soon. This will allow the following interaction possible:

    gem install glassfish-rails
    jruby script/server glassfish
    => Starting GlassFish
    => Rails application on http://localhost:8080/8080
    => Rails application on http://localhost:8080/4848
    => Clustering enabled
    => Connecting pooling enabled
    => Load balancing enabled
    => Server Ready.

  • JvYAML is a Java port of RbYAML.- Java YAML 1.1 parser and emitter
  • Deployment of Mephisto on GlassFish V3
  • Powerful editing, code completion, re-factoring capabilities using NetBeans IDE 6 M9. You can find more details here.

The biggest pain point from the audience was Rails deployment. With JRuby and GlassFish, you can continue deploying your apps on Mongrel. Because of JRuby, it also allows you to deploy your RoR applications on GlassFish, open-source, production-quality, Java EE 5 compatible application server.

BTW, there is supposed to be wireless connectivity through out the conference but it’s very spotty :(

Technorati: glassfish rubyonrails ror netbeans railsconf

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

jMaki on Rails For Dummies

Filed under: web2.0 — arungupta @ 11:00 am

Craig announced jMaki on Rails. Here I provide detailed steps to read data from a MySQL database and display it in a jMaki-wrapped Yahoo DataTable widget.

  1. Download NetBeans 6.0 M9 (Full version) and configured to install only “Base IDE”, “Java IDE”, “Web and Java EE” and “Ruby” modules. A cutting-edge build can be obtained from the hudson build.
  2. Download and install jMaki plug-in in NetBeans update center.
    1. In NetBeans ‘Tools‘, ‘Plugins‘, select ‘Downloaded‘, click on ‘Add Plugins ...‘.
    2. Select the downloaded .NBM module, click on ‘Install’. This will install the jMaki plug-in and restart the IDE.
    3. To verify, go to ‘Tools‘, ‘Plugins‘, select ‘Installed‘. It should show ‘jMaki Ajax support‘ with ‘1.6.9.7‘ version number.
  3. Create a new "Ruby on Rails Application" Project, lets say named ‘jmaki_ror‘.
  4. Create a new controller by right-clicking the project, select ‘Generate ...‘, select ‘controller‘, specify the Name as ‘jmaki‘ and Views as ‘yahoo‘.
  5. jMaki-enable the Rails app
    1. Open a command prompt and go to your application directory. Make sure you have a SVN client configured on your machine. Then invoke the following commands:

      script/plugin source http://jmaki-goodies.googlecode.com/svn/trunk/rails_plugins
      script/plugin install jmaki_core
      script/plugin install jmaki_yahoo

      The first step adds the plug-in registry to the list of registries used for searching plug-ins. The second two steps install the core and yahoo plug-ins.

    2. Expand ‘Views‘, right-click on ‘layouts‘, select ‘New‘, select ‘Empty RHTML (Embedded Ruby) file ...‘. Enter the ‘File Name‘ as ‘standard‘. This will add ‘standard.rhtml‘ in layouts sub-tree. Enter the following fragment before <body>:

      <head>
        <%= stylesheet_link_tag "jmaki-standard", :media => "all" -%>
        <%= javascript_include_tag "jmaki" -%>
        <%= jmaki_setup -%>
      </head>

    3. Within <body>, add the following fragment:

      <%= @content_for_layout %>

    4. In ‘Controllers‘, ‘jmaki_controller.rb‘, add the following fragment before ‘def yahoo‘ line:

      layout "standard"

  6. Configure the MySQL database
    1. Create database using the command: ‘mysqladmin -u root create jmaki_ror_development‘. You need to make sure that the database name in this script is changed to match the project name.
    2. Right select the NetBeans project, select ‘Generate‘, select ‘model‘, specify the arguments as ‘grid‘, click ‘OK‘. This will generate, in NetBeans project, Database Migrations, migrate, 001_create_grids.rb.
    3. Open 001_create_grids.rb, change self.up helper method such that it looks like:

      def self.up
        create_table :grids do |t|
          t.column :company, :string
          t.column :price, :float
          t.column :change, :float
          t.column :percent_change, :float
          t.column :last_updated, :string
        end
      end 

    4. Right-select NetBeans project, select ‘Run Rake Target‘, ‘db‘, ‘migrate‘. This generates the database table. Execute the following query to insert data into the table:

      insert into grids values (1, 'A Co', 71.72, 0.02, 0.03, 'Jan 1, 2007, 10:00am' );
      insert into grids values (2, 'B Inc', 29.01, 0.42, 1.47, 'Feb 1, 2007, 10:00am' );
      insert into grids values (3, 'C Group Inc', 83.81, 0.28, 0.34, 'Mar 1, 2007, 10:00am' );
      insert into grids values (4, 'D Company', 52.55, 0.01, 0.02, 'Apr 1, 2007, 10:00am' );

  7. Add jMaki-wrapped Yahoo DataTable widget
    1. In NetBeans project, in ‘Views‘, ‘jmaki‘, ‘yahoo.rhtml‘, drag-and-drop ‘Data Table‘ widget from the ‘Yahoo‘ category of jMaki palette.
      1. Until the jMaki data model for grid and data widgets is consistent between Java and JRuby, you need to replace the generated code in ‘yahoo.rhtml‘ with the following:

        <%= jmaki_widget 'yahoo.dataTable',
            :args => {
                :columns => [
                    { :title => 'Company', :width => 200, :locked => false },
                    { :title => 'Price', :width => 75, :renderer => 'usMoney' },
                    { :title => 'Change', :width => 75, :renderer => 'change' },
                    { :title => '% Change', :width => 75, :renderer => 'pctChange' },
                    { :title => 'Last Updated', :width => 85, :renderer => 'italic' }
                ]
            },
        :value => @table_data
        -%>

      2. @table_data‘ is defined in ‘jmaki_controller‘ in ‘def yahoo‘ as:

        def yahoo
            @table_data = []
            Grid.find_all().each do |data|
              @table_data << [ data.company, data.price, data.change, data.percent_change, data.last_updated]
            end
        end

  8. That’s it, run your app and view the page at ‘http://localhost:3000/jmaki/yahoo‘. Now jMaki-wrapped Yahoo DataTable widget is picking data from the MySQL database. 

And as a next step, you can WAR’up this RoR application and deploy it on GlassFish V2 using these instructions.

Technorati: jmaki rubyonrails ror netbeans mysql glassfish

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

Database-enabled RoR WAR on GlassFish

Filed under: web2.0 — arungupta @ 7:00 am

UPDATE: Simplified steps for GlassFish V2 are available here and for V3 here.

Follow up from here.

In this post I’ll show how a Ruby-on-Rails (RoR) application, talking to MySQL database, can be deployed as a WAR file on GlassFish V2. Here are the steps I followed:

  1. Create a HelloWorld RoR app talking to MySQL database as described here.
  2. Expand NetBeans project, expand ‘Configuration‘ and open ‘database.yml‘. Change production database entry from:

    production:
      adapter: mysql
      database: HelloWorld_production
      username: root
      password:
      host: localhost

    to

    production:
      adapter: jdbc
      driver: com.mysql.jdbc.Driver
      url: jdbc:mysql://localhost:3306/helloworld_development
      username: root
      password:

    Notice, even though this is production setting we are using a "development" database.

  3. In ‘Configuration‘, ‘environment.rb‘, add

    require 'jdbc_adapter'

    right before

    Rails::Initializer.run do |config|

    On some platforms, this syntax has caused problems. In that case, it may alternatively be specified (step 9) as:

    if RUBY_PLATFORM =~ /java/
    require 'rubygems'
    RAILS_CONNECTION_ADAPTERS = %w(jdbc)
    end
  4. Recreate the WAR file by invoking the command ‘rake war:standalone:create‘ from your application directory.
  5. Drop this WAR file in "domains/domain1/autodeploy" directory of your GlassFish instance and you are done!

With this, you’ve deployed a Ruby-on-Rails application accessing MySQL database as a WAR file on GlassFish V2.

Technorati: glassfish rubyonrails ror netbeans jruby ruby

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

May 16, 2007

Database-enabled Hello World RoR app

Filed under: web2.0 — arungupta @ 3:22 pm

UPDATE: Simplified steps for GlassFish V2 are available here and for V3 here.

Follow up from here.

In this post I show how a Rails app can talk to database. Here are the steps I followed:

  1. Deploy a RoR application as WAR on GlassFish using these steps.
  2. Modify the application such that "Hello World!" is read from the controller instead of defined in the view (this is natural to RoR programmers anyway!).
    1. Define a new variable in controller as ‘@hello_string = "Hello World!"‘.
    2. Replace the string in view with ‘<%= @hello_string %>‘.
  3. Download and install MySQL Community Server 5.0 and MySQL Connector/J 5.0.5.
  4. Create database using the command: ‘mysqladmin -u root create helloworld_development‘.
  5. Right select the NetBeans project, select ‘Generate‘, select ‘model‘, specify the arguments as ‘table1‘, click ‘OK‘. This will generate, in NetBeans project, Database Migrations, migrate, 001_create_table1s.rb.
  6. Open 001_create_table1s.rb, change self.up helper method such that it looks like:
    def self.up
    create table :table1s do |t|
    t.column :data, :string
    end
    end
  7. Right-select NetBeans project, select ‘Run Rake Target‘, ‘db‘, ‘migrate‘. This generates the appropriate database tables.
  8. In NetBeans Runtime tab, right click on ‘Databases‘, ‘New Connection ...‘.
    1. In Name, select ‘New Driver ...‘ and specify the location of mysql-connector-java-5.0.5-bin.jar from the MySQL Connector/J installation directory.
    2. In Database URL, give ‘jdbc:mysql://localhost:3306/helloworld_development‘.
    3. Expand the newly added database node, expand Tables, right-select ‘table1s‘, select ‘Execute Command ...‘.
    4. Enter the following SQL "insert into table1s values (1, 'Hello from database')". Run the SQL.
  9. Change the controller such ‘hello_string‘ is initialized from the database. This is a contrived example but still convey the concept. Anyway, The code looks like:

    @hello_string = Table1.find(1).data

  10. Start MySQL database by giving the following command:

    mysqld --console

  11. Save all the files and refresh the page in the browser. If your controller name is ‘say‘ and view is ‘hello‘, then the URL will be ‘http://localhost:3000/say/hello‘. The browser will now display ‘Hello from database‘.

In a later post, I’ll describe how this same application can be deployed as WAR in GlassFish V2.

Technorati: glassfish rubyonrails ror netbeans jruby ruby

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
« Newer PostsOlder Posts »

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress