Ramblings

18 Nov, 2008

Signs I’ve not had enough sleep

Posted by: Matt Williams In: idiocy

I just named a rails controller class ElmoController, because it gets invoked by a tickler…

Tags:

14 Nov, 2008

Concatenation Note to Self

Posted by: Matt Williams In: gotchas

To concatenate in PHP you use a ‘.’, not a ‘+’.  Likewise, you don’t use ‘.’ to reference an object’s members, you use ‘->’. 

Move along, nothing to see.

Tags:

12 Nov, 2008

DIY Maps and Linux Firefox/Flash Quirks

Posted by: Matt Williams In: gotchas| javascript

First off, let me say that I really like DIY Map. It’s quick, and responsive, with an easy to use interface, as well as allowing you to make changes on the fly easily.

That said, I discovered lastnight / this morning that there are some quirks with its updating through the Flash JavaScript Integration Kit.

First of all, the only way I’ve been able to get paths to resources to work is via relative paths.  More on why I think that is the case in a moment.  I was finding that resources were not being found until I used relative paths.  Once I did so, that part worked just fine.

Second, in order to be able to update the map, it needs to be fed an XML data file, which is fine.  Wherein lies the trouble is when you are attempting to feed a dynamic file (like a cgi script or php) — I’ve not been able to get it to work, despite having the right data in the output and the proper content type — the data works just fine when loaded from a file, however…  So, my workaround is to write to a temporary file and use that file to make the changes.

Third, and this was a kicker….  The Javascript integration kit isn’t talking to Flash 9 on Firefox 3.0.3 under linux.  The messages get lost out on the bit bucket.  Just to make sure it wasn’t me, I also tried the examples which came with the app.  They, however, work on Firefox under windows.  So, I don’t know if it is something having to do with my box or what…  But it ain’t working.

4+ hours spent  on this.  Meh.  It’d be a bit more amusing if I’d gotten more sleep.  I napped for about an hour around midnight, and another nap at 7:30am until I had to get up for work @ 9.

11 Nov, 2008

YUI Datasources

Posted by: Matt Williams In: gotchas

Been a while since I’ve written.  I’ve been sick and working on a side project.  That said, I’ll be writing more……

Today’s note/reminder is a gotcha about YUI datasources.  If you have JSON feeding the datasource and you’re getting back more fields in the results than you’re expecting, the datasource will not behave properly.  For example, if you’ve declared that you’re getting back

  • name
  • id

But in reality you get

  • name
  • id
  • address
  • email

it will just sit there. Very frustrating. Very fun trying to debug, too!

Tags: ,

20 Oct, 2008

New Favorite Pencils

Posted by: Matt Williams In: life hacking| miscellany| tools

I’m a stationary supply junkie.  I admit it.  I love pens, papers, notebooks….  I’ve just found a new favorite pencil.  Barnes & Noble has a small section of art supplies in a local store and one of the items they have are graphite stick pencils.  At first grasp, they feel a little heavy — about 2-3 times the weight of a Dixon ticonderoga.  But after the initial shock, I really like their solid feeling.  And they really flow well across the paper.  A set of 10, with  two each of HB, 2B, 4B, 6B, and 8B pencils is $5. 

I was not compensated in any way for this post…  Just a happy user.

08 Oct, 2008

Semantic Web

Posted by: Matt Williams In: philosophy| programming

I have been doing some site scraping of late.  And as a result, I have really come to appreciate the semantic web.  It’d make life infinitely easier for grabbing data.  Of course there are other, better reasons for using the semantic web, but right now, it’d make a difference in my life.

07 Oct, 2008

Dear Mr. Designer

Posted by: Matt Williams In: idiocy| rants

Generally, if you are working with an external library, such as yui, it’s not a good idea to override the css for a widget’s css class.  That means that every instance of the widget will have that property, whether you want it to or not.  Moreover, it means that in order to fix it, you need to find and override every instance of the widget.

‘k thx bye

Tags: , ,

25 Sep, 2008

JBoss run.sh may be harmful

Posted by: Matt Williams In: gotchas| jboss

A coworker and I discovered an issue with jboss’ run.sh (which starts the app server).  The problem lies in different flavours of unix (or unix-like) shells returning different values for wait.

The relevant code is:

      # Wait until the background process exits
      WAIT_STATUS=0
      while [ "$WAIT_STATUS" -ne 127 ]; do
         JBOSS_STATUS=$WAIT_STATUS
         wait $JBOSS_PID 2>/dev/null
         WAIT_STATUS=$?
      done

This is all well and good in linux — redhat uses /bin/bash and ubuntu uses /bin/dash for /bin/sh — both of which return 127 when waiting for a process which does not exist. However, Solaris’ /bin/sh returns 0 (/bin/ksh returns 127).

So, the run.sh goes into an infinite loop, thrashing, badly. CPU gets pegged and all that fun stuff.

How to fix? Well in order to make it OS/shell dependant, we’ll determine the value which is returned by wait when a process does not exist. We’re guaranteed that there is one process id which won’t be used in unix — 0. So, we wait on PID 0, and use the return value, $? to determine how the environment handles the wait. The “fixed” code looks like:

      wait 0 2>/dev/null
      NO_SUCH_PID=$?
      # Wait until the background process exits
      WAIT_STATUS=0
      while [ "$WAIT_STATUS" -ne $NO_SUCH_PID ]; do
         JBOSS_STATUS=$WAIT_STATUS
         wait $JBOSS_PID 2>/dev/null
         WAIT_STATUS=$?
      done

EDIT:
This was fixed in 4.2.3 GA with the following code:

# Wait until the background process exits
      WAIT_STATUS=128
      while [ "$WAIT_STATUS" -ge 128 ]; do
         wait $JBOSS_PID 2>/dev/null
         WAIT_STATUS=$?
         if [ "${WAIT_STATUS}" -gt 128 ]; then
            SIGNAL=`expr ${WAIT_STATUS} - 128`
            SIGNAL_NAME=`kill -l ${SIGNAL}`
            echo "*** JBossAS process (${JBOSS_PID}) received ${SIGNAL_NAME} signal. ***" >&2
         fi
      done
      if [ "${WAIT_STATUS}" -lt 127 ]; then
         JBOSS_STATUS=$WAIT_STATUS
      else
         JBOSS_STATUS=0
      fi

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!

22 Sep, 2008

JRuby to check connectivity…

Posted by: Matt Williams In: jruby| programming

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?
Tags: , ,

Categories

DrakNet Web Hosting

  • John: Hi Matt, Sorry to hear about the time wasted and that the map didn't work out for you. I've tried to design it to be easy to setup and configure.
  • Jason Jackson: Also worth noting that if your not connecting to JBoss on localhost, make sure you have DNS set up, or a host file entry, or else you will get an exce
  • Matt Williams: Yes, there's not a lot of debugging info. One thing that I've found is that if your grammar isn't constructed "properly", it won't complain and you w

Flickr PhotoStream

    layout_newm3headerTerrain Testa

About

Matt Williams is a geekly jack of all trades residing in Columbus, OH, USA.

Recommend Me


Adopt a Dragon from Dragcave
Adopt one today!Adopt one today!Adopt one today!Adopt one today! Adopt one today! Adopt one today!Adopt one today! Adopt one today! Adopt one today! Adopt one today!