Skip to content

Ramblings

Musings of Matt Williams
  • Blog
  • About
  • Chibi
  • Ruby Blender
  • Archives
  • Log in
 
Less
More
Trim
Untrim
« Older
Home
Loading
Newer »
Archive for the 'jruby' Category
22Jun12 cygwin and torquebox and rvm, oh my!
cygwin gotchas jruby tips torquebox
0 Comments

rvm, despite being wonderful, doesn’t play very well with torquebox under cygwin. In particular, the gem paths are not working. So, in order to fix this, simply do:

rvm use system

And then it will work right. Once you’re done with the torquebox work, you can go back to using rvm.

09Jun10 Torquebox and Cygwin: Take I
gotchas jboss jruby rails torquebox
0 Comments

Torquebox and Cygwin don’t work as nicely together as one might hope.

That said, here are a couple of findings:

  1. In order to deploy, you need to set the $JBOSS_HOME with the Windows path.  You can do this via export JBOSS_PATH=`cygpath -w PATH_TO_JBOSS`.
  2. Additionally, the JRUBY_HOME needs to be a windows path as well.   Otherwise you will see:

    org.jruby.exceptions.RaiseException: no such file to load — date

That’s it so far, more to follow as discovered….

02Mar10 Rails & JRuby in a Jar
gotchas jruby rails tips
7 Comments

For political reasons, I needed to ship a single jar file.  I didn’t want to have the overhead of a war & an appserver, so I set out to embed my rails app within a single jar file.  I needed to make some changes in order to get it to work.

This assumes Rails 2.3.5 and JRuby 1.4.0.

First, you need to create your rails app.   Freeze rails and any gems required.

Next download jruby-complete.  Once you’ve done so, unzip it.  I’m assuming you’ve unzipped it to complete.

Note: When you repackage the jar file, DO NOT use jar.  Use zip.  This is very important.  If you don’t, you’ll trash your jruby instance.

Copy your rails instance to complete/META-INF/jruby.home. I assume it will be complete/META-INF/jruby.home/rails.

Next create complete/META-INF/jruby.home/bin/server with the following content:


#!/usr/bin/env ruby

RAILS_ROOT = File.join(File.dirname(File.dirname(__FILE__)),'rails')

require File.join(RAILS_ROOT,'config/boot')
require 'commands/server'

The RAILS_ROOT needs to be set in order to have the proper paths within the jar file.

Next, edit complete/META-INF/jruby.home/rails/vendor/rails/railties/lib/initializer.rb In the set_root_path method, edit it so it looks like this:


    def set_root_path!
      raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT)
      raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT)
      # I changed this... mkw21 20100301
      @root_path = RAILS_ROOT
        # Pathname is incompatible with Windows, but Windows doesn't have
        # real symlinks so File.expand_path is safe.
#        if RUBY_PLATFORM =~ /(:?mswin|mingw)/
#          File.expand_path(::RAILS_ROOT)#

        # Otherwise use Pathname#realpath which respects symlinks.
#        else
#          Pathname.new(::RAILS_ROOT).realpath.to_s
#        end

      Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
      ::RAILS_ROOT.replace @root_path
    end

This is related to paths within the jar file.

Additionally, you need to change the initialize_logger method. (this might not be needed, see below). Change


          logger = ActiveSupport::BufferedLogger.new(configuration.log_path)

to


          logger = ActiveSupport::BufferedLogger.new("/tmp/transfer.log")

The idea is to change it to something definitely outside the jar. The reason I did this, and didn’t change the config in environment.rb was that the changes in environment.rb were not getting picked up. I’ve since come to the belief that this is due to an issue with the Rack LogTailer detailed at https://rails.lighthouseapp.com/projects/8994/tickets/2350-logtailer-ignores-configlog_path. So complete/META-INF/jruby.home/rails/vendor/rails/railties/lib/rails/rack/log_tailer.rb needs to be edited. Edit the EnvironmentLog assignment to match the file we’d specified. (You may be able to substitute RAILS_DEFAULT_LOGGER but I have not tested that)


      EnvironmentLog = "/tmp/transfer.log"      

That’s pretty much it. Zip up your exploded jar from the complete directory: zip -r ../complete.zip *. Then you can run it via java -jar complete.jar -S server.

Enjoy!

25Aug09 Using jnp as a JBoss heartbeat
Computers jboss jruby
0 Comments

jnp is a JBoss protocol which exposes jndi.  It is, by default, bound to port 1099.  I’d been using that port as a heartbeat, but “cheating” — I would open a socket and then close it immediately.  However, this caused problems.  jnp is chatty.  And it got upset at my not letting it say ‘hi’ before I dropped the connection.   So, here’s a code snippet (jruby, the Java should be an exercise for the student) which allows you to actually do an intelligent check.

  def check_port(server)
    @logger.debug "check_port: #{server.fqdn}(#{server.host}:#{server.port})"
    begin

      env = java.util.Properties.new();
      env.set_property("java.naming.factory.initial",
                       "org.jnp.interfaces.NamingContextFactory");
      env.set_property("java.naming.provider.url",
                       "#{server.host}:#{server.port}");
      ctx = javax.naming.InitialContext.new(env);

      # if the server is not running, we'll get an error here because
      # it will timeout.
      ctx.list("")
      ctx.close
      @logger.debug "check_port: #{server.fqdn}(#{server.host}:#{server.port}): Succeeded"
    rescue javax.naming.CommunicationException => comm_error
      @logger.debug "check_port: #{server.fqdn}(#{server.host}:#{server.port}): Not Running"
      begin
        ctx.close
      rescue Exception => ignore_me
      end
      return false

    rescue Exception => e2
      @logger.info "check_port: #{server.fqdn}(#{server.host}:#{server.port}): FAILED: #{e2.to_s}"
      return false
    end
    return true
  end
Enhanced by Zemanta
05Feb09 Web Based Portable mysql tool suite
glassfish jruby mysql php tools utilities web
0 Comments

Are you limited in what software you can use at work?  This article details how to have a web based tool suite for mysql.  It currently has the following tools:

  • AjaxMyTop — a php implementation of mytop (think top for mysql) which runs in a browser.
  • rbdb — a phpmyadmin work-alike in progress.  It’s the result of the 2008 Rails Rumble contest.

So you’ve noticed that both a php and a ruby application are included.  Pretty spiffy, eh?

The magick partly lies in the container — I’m using GlassFish v3 prelude.  Another piece is Quercus, a Java implementation of PHP 5. JRuby is used for ruby.
Continue reading ‘Web Based Portable mysql tool suite’

23Jan09 Prawn’d by Scruffy, Gruff
jruby ruby
2 Comments

I’ve been putting together an automated report for my team, and decided to give prawn and scruffy a try.  I ended up using Gruff, but here are some of the lessons along the way:

  • Scruffy has issues with bar charts and values from 1-3 (actual values were [1,3,1]).  I was able to get around this by setting a minimum value of 0 and a maximum of (datapoints.max + 1)
  • Scruffy failed, miserably, when I just had one column.
  • Prawn has issues, potentially, with png’s generated by gruff (It’s actually a rmagick issue).  The easy way to get around this is to generate a jpg.
  • I’d seen indications that you could use to_blob to generate the jpg, and yes, you can, but it won’t
    1. Write the file
    2. If you attempt multiple generation types in sequence, it creates multiple copies of text in the resultant graph, and they don’t always line up.

Right now I’m working on packaging with rawr. Once that’s done, I’ll publish my results.

22Sep08 JRuby + jmx4r + rrd4j == Easy reporting on app servers (part I)
howto jruby monitoring programming
3 Comments

This is a how-to for using jmx and rrd4j, a java implementation of rrdtool, to report on app server statistics.

Thanks to Jeff Mesnil(author of jmx4r), Werner Schuster (JMX the Ruby way with jmx4r), sishen (JRobin sucks), and the rrd4j team.

You’ll need the following:

  1. JVM 1.5 or higher — JRE is not enough, you also need the JDK. Remember to set your JAVA_HOME — JRuby needs it.
  2. JRuby — I’m using 1.1.4. Note: You need to be sure to set the JRUBY_HOME and make sure that ${JRUBY_HOME}/bin comes in $PATH prior to any other ruby installation. Otherwise, your results will be indeterminate.
  3. jmx4r — this is a gem and can be installed by
    jruby -S gem install jmx4r
  4. rrd4j — in order to get this, you need to create an account on java.net. Once you’ve done that, you can download the library via subversion:
    svn co https://rrd4j.dev.java.net/svn/rrd4j/trunk rrd4j --username <em>username</em>

    Replace username with your java.net username. You’ll need ant to build it:

    cd rrd4j/rrd4j; ant

    Or you can download the jars: rrd4j jars

  5. An application which responds to jmx queries — this example is using jconsole since it is a standard part of the java distribution in 1.5 and after.

Before we do much else, let’s verify that jconsole is working:

jconsole -J-Dcom.sun.management.jmxremote.port=64850 -J-Dcom.sun.management.jmxremote.authenticate=false -J-Dcom.sun.management.jmxremote.ssl=false

Choose for the port some large nuimber…  Your screen will look something like this for 1.5 (ignore the cutoff bits, I’m writing this on chibi):

Portion of a JConsole screen

Portion of a JConsole screen

Ok, now that we’ve got that going, let’s attempt connecting via jmx4r…

$ jruby -S jirb
irb(main):001:0&gt; require 'rubygems'
=&gt; true
irb(main):002:0&gt; require 'jmx4r'
=&gt; true
irb(main):003:0&gt; require 'java'
=&gt; false
irb(main):004:0&gt; JMX::MBean.establish_connection :host =&gt; "localhost", :port =&gt; 64850
=&gt; #&lt;#:0x1bd06a0 @java_object=javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection@12f9ee1&gt;
irb(main):005:0&gt; memory =JMX::MBean.find_by_name "java.lang:type=Memory"
=&gt; #"NonHeapMemoryUsage", "verbose"=&gt;"Verbose", "object_pending_finalization_count"=&gt;"ObjectPendingFinalizationCount", "heap_memory_usage"=&gt;"HeapMemoryUsage"}, @mbsc=#&lt;#:0x1bd06a0 @java_object=javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection@12f9ee1&gt;, @operations={"gc"=&gt;["gc", []]}, @object_name=#&gt;
irb(main):006:0&gt; memory.heap_memory_usage
=&gt; #
irb(main):012:0&gt; memory.heap_memory_usage.keys
=&gt; #&lt;#:0x129dcc0 @java_object=[committed, init, max, used]&gt;
irb(main):015:0&gt; memory.heap_memory_usage.to_s
=&gt; "javax.management.openmbean.CompositeDataSupport(compositeType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))),contents={committed=7569408, init=0, max=66650112, used=3952968})"
irb(main):020:0&gt; memory.heap_memory_usage["committed"]
=&gt; 7569408
irb(main):021:0&gt; #trigger a gc
irb(main):022:0* memory.gc
=&gt; nil
irb(main):023:0&gt; memory =JMX::MBean.find_by_name "java.lang:type=Memory"
=&gt; #"NonHeapMemoryUsage", "verbose"=&gt;"Verbose", "object_pending_finalization_count"=&gt;"ObjectPendingFinalizationCount", "heap_memory_usage"=&gt;"HeapMemoryUsage"}, @mbsc=#&lt;#:0x1bd06a0 @java_object=javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection@12f9ee1&gt;, @operations={"gc"=&gt;["gc", []]}, @object_name=#&gt;
irb(main):024:0&gt; memory.heap_memory_usage["committed"]
=&gt; 7569408
irb(main):026:0&gt; memory.heap_memory_usage["max"]
=&gt; 66650112
irb(main):027:0&gt; memory.heap_memory_usage["used"]
=&gt; 4210824
irb(main):028:0&gt; exit
$

Cool! now we’re making progress!

22Sep08 JRuby to check connectivity…
jruby programming
0 Comments

I had an issue reported by a developer where their jboss connection pool wasn’t working properly. It looked good to me, so I decided to verify that everything worked in so far as connectivity from the box. So, I used the following jruby script to help:

require 'rubygems'
require 'jdbc'
require 'java'
Java::oracle.jdbc.driver.OracleDriver
url = "jdbc:oracle:thin:@SERVER:1521:DB"
user = "user"
pass = "pass"
conn = java.sql.DriverManager.get_connection(url,user,pass)
stmt = conn.create_statement
query = "select 1 from dual"
rss = stmt.execute_query(query)
puts rss.next?                  # did we get anything?
 
Browse Archives »
  • administrivia (6)
  • books (1)
  • Computers (2)
  • css (3)
  • cygwin (1)
  • eating crow (1)
  • games (1)
  • glassfish (1)
  • gotchas (19)
  • howto (2)
  • idiocy (3)
  • javascript (4)
  • jboss (6)
  • jruby (8)
  • Just Enough Programming (7)
  • life hacking (2)
  • mini sagas (1)
  • miscellany (1)
  • monitoring (1)
  • mysql (1)
  • philosophy (4)
  • php (1)
  • programming (17)
  • rails (7)
  • rants (2)
  • refactoring (1)
  • ruby (14)
  • tips (10)
  • tools (2)
  • torquebox (2)
  • Uncategorized (9)
  • UNIX (1)
  • utilities (3)
  • web (5)
  • web design (3)
 

Latest

  • cygwin and torquebox and rvm, oh my!
  • JBoss Client Jars for Messaging
  • rsh hates nohup
  • Torquebox and Cygwin: Take I
  • Rails & JRuby in a Jar
  • Fractal Terrain Generation
  • Quick thought on programming and distractions
  • Using jnp as a JBoss heartbeat
  • z-index and events
  • JBoss port confusion

Flickr

layout_newm3headerTerrain Testa

Blogroll

  • Development Blog
  • Documentation
  • Plugins
  • Suggest Ideas
  • Support Forum
  • Themes
  • WordPress Planet

Search

Browse by Category

  • administrivia (6)
  • books (1)
  • Computers (2)
  • css (3)
  • cygwin (1)
  • eating crow (1)
  • games (1)
  • glassfish (1)
  • gotchas (19)
  • howto (2)
  • idiocy (3)
  • javascript (4)
  • jboss (6)
  • jruby (8)
  • Just Enough Programming (7)
  • life hacking (2)
  • mini sagas (1)
  • miscellany (1)
  • monitoring (1)
  • mysql (1)
  • philosophy (4)
  • php (1)
  • programming (17)
  • rails (7)
  • rants (2)
  • refactoring (1)
  • ruby (14)
  • tips (10)
  • tools (2)
  • torquebox (2)
  • Uncategorized (9)
  • UNIX (1)
  • utilities (3)
  • web (5)
  • web design (3)

Browse by Tag

  • 1.2.6
  • 2.1
  • administrivia
  • autotest
  • books
  • controller
  • css
  • feed-normalizer
  • feeds
  • gotchas
  • idiocy
  • irb
  • Java
  • javascript
  • jboss
  • jruby
  • just enough programming
  • mini sagas
  • open-uri
  • philosophy
  • php
  • pragmatism
  • programming
  • quotations
  • rails
  • rants
  • reading
  • restful_authentication
  • rspec
  • rss
  • ruby
  • rubygems
  • scriptaculous
  • setup
  • simplicity
  • sprites
  • statemachine
  • tips
  • treetop
  • utilities
  • web
  • web design
  • websense
  • yaml
  • zentest

Browse by Month

  • June 2012 (1)
  • November 2010 (1)
  • August 2010 (1)
  • June 2010 (1)
  • March 2010 (1)
  • September 2009 (1)
  • August 2009 (2)
  • July 2009 (2)
  • May 2009 (1)
  • April 2009 (1)
  • February 2009 (4)
  • January 2009 (2)
  • December 2008 (2)
  • November 2008 (5)
  • October 2008 (3)
  • September 2008 (12)
  • August 2008 (28)
 
 
  • Blog
  • About
  • Chibi
  • Ruby Blender
  • Archives
  • Log in
 


Theme Design by Jay Kwong | Powered by WordPress and K2

 

Home Top Archives Entries FeedComments Feed