Fusioncube

The online journey of a technophile, by Steve Brownlee

Archive for August, 2006

When to use Java over ColdFusion – Part I

  • Filed under: cfml, java
Wednesday
Aug 23,2006

I’m investigating some basic, everyday operations that many web application developers face.  Using very simple test cases, I’m determining if there is a time savings by writing Java code and calling it from ColdFusion.  If there is a savings, is it worth the extra coding time and overhead* for using Java.  Here’s the result of my first, basic test.

File Read/Write Operations

I was actually surprised how much faster invoking a Java I/O class was than the equivalent code in ColdFusion.  Using only a 90k byte file, I wrote a Java class to read it, parse it on a delimiter of the pattern ‘x\s’ and output each line.

public String outputScannedFile() throws IOException
{
   Scanner s = null;
   String output = "";
   try {
       s = new Scanner(new BufferedReader(new FileReader("C:\\inputfile\\xanadu.txt")));
       s.useDelimiter("x\\s*");
       while (s.hasNext()) {
      	  output += s.next();
       }
   } finally {
       if (s != null) s.close();
   }
   return output;
}

This is executed by creating an instance of a class and invoking a method (I use cfscript for Java objects… easier to read)

<cfscript>
output = createobject("java", "orbwave.StringTest");
</cfscript>
<cfdump var="#output.outputScannedFile()#">

This executed at a good pace.

Execution Time

Total Time Avg Time Count Template
3078 ms 3078 ms 1 C:\jboss-4.0.4\server\default\.\deploy\brownlees.war\scribble.cfm

The equivalent code in ColdFusion is much easier to write

<cffile action="read" file="C:\\inputfile\\xanadu.txt" variable="input">
<cfloop from="1" to="#ListLen(input,'x')#" index="span">
	<cfoutput>#ListGetAt(input,span,'x')#</cfoutput>
</cfloop>

It also took over twice as long to execute.

Execution Time

Total Time Avg Time Count Template
7484 ms 7484 ms 1 C:\jboss-4.0.4\server\default\.\deploy\brownlees.war\scribble.cfm

As one would expect, using Java to handle the I/O is faster. However, I did not expect the compilation and execution of a simple set of ColdFusion commands to take over 4 seconds longer on such a basic operation.

Is It Worth It?

In situations where you’re performing a significant amount of file I/O, I would suggest writing some simple Java classes, compressing them to a JAR and installing it on your app server.

* By overhead, I’m not talking about system resource overhead, but the additional resources needed to maintain Java in addition to ColdFusion, such as source control measures, training (if necessary), compile-time and build-time.

Wednesday
Aug 23,2006

I stumbled across this great article that Terry Ford wrote when CFMX 6.1 was released.  It’s still relevant and one of the best beginner tutorials on Java resource usage I’ve seen.

Macromedia – Developer Center : Using Java and J2EE Elements in ColdFusion MX Applications

Windows Live Writer – Not This Release

  • Filed under: errata
Tuesday
Aug 15,2006

The blogosphere is hopping about Windows Live Writer and here’s my take on it… wait a few releases before giving it a serious shot.

After playing with it for about an hour, I’d have to say it does an adequate job for blogs that use standard templates and bloggers with simple needs. However, it does a horrible job when you have multiple CSS layers or three column layouts. It’s a good first attempt to be a one-size-fits-all blog editor, but it doesn’t replace the custom editor for WordPress or Moveable Type. In fact, it’s not even close to being as good a the Performancing editor which is integrated into the browser (which, when combined with Flock is all you need).

Having a seperate program to run for editing my blog just doesn’t make sense to me. However, as is almost always the case, Microsoft will continue to refine the program and make it more friendly and universal, and in a few releases have a kick-ass blog editor.

Gantt Chart Component

  • Filed under: cfml
Thursday
Aug 10,2006

I had a need for a Gantt chart to show stages of a project, but my choices out there were limited. I either needed to pay for a solution that I had little control over, or settle for some Javascript implementations that were half-hearted at best. In the end I decided to take a stab at writing my own ColdFusion Component. My first release is a good working solution, but there are still some features that I’d like to implement to make it more powerful.

I made a significant effort to have the chart data drawn almost exclusively by Javascript, otherwise the document size quickly grows out of control. Take a look at the source for the sample chart to see how small the actual document is compare to how much HTML is generated.

You can see the sample chart shown below in action before going into the code.
Gantt Chart Screenshot

The code has two components: the chart itself and individual rows.

GanttChart Component Properties

<cfproperty name="width" type="numeric" default="0" />
<cfproperty name="startDate" type="date" />
<cfproperty name="endDate" type="date" />
<cfproperty name="rows" type="numeric" default="0" />
<cfproperty name="scale" hint="Daily | Monthly | Yearly" type="string" />
<cfproperty name="title" type="string" />
<cfproperty name="rowLabel" type="string" />
<cfproperty name="scrollToDate" type="date" />  

You can create the basic chart in one of two ways. This example shows setting the individual properties.

<cfscript>
jbossChart = createobject("component", "com.orbwave.charts.gantt.GanttChart").constructor();
jbossChart.setStartDate('8/12/06');
jbossChart.setEndDate('12/30/08');
jbossChart.setTitle('JBoss Deployment');
jbossChart.setWidth(640);
jbossChart.setScale('monthly');
</cfscript>

You can also pass many of the parameters into the constructor

<cfscript>
jbossChart = createobject("component", "com.orbwave.charts.gantt.GanttChart").constructor('JBoss Deployment',640,'8/12/06','12/30/08');
jbossChart.setScale('daily');
</cfscript>

GanttChartRow Component Properties

<cfproperty name="label" type="string" />
<cfproperty name="style" type="string" />
<cfproperty name="ranges" type="array" />

The ranges property I added in so that each row of data could show several sub-stages with different colors. Each range its own start and end date and a row must have at least one range.

GanttChartRow Range Properties

  • StartDate [string, required]
  • EndDate [string, required]
  • Style [string, solid (default) | striped]

Here’s the code for the rows in the sample chart

<cfscript>
row1 = createobject("component", "com.orbwave.charts.gantt.GanttChartRow").constructor('Setup web server');
row1.addRange('08/15/06','11/15/06','olive');
jbossChart.addRow(row1);

row2 = createobject("component", "com.orbwave.charts.gantt.GanttChartRow").constructor('Connect PHP','striped');
row2.addRange('11/22/06','03/25/07','indianred');
row2.addRange('03/26/07','05/01/07','black');
row2.addRange('05/02/07','09/01/07','goldenrod');
jbossChart.addRow(row2);

row3 = createobject("component", "com.orbwave.charts.gantt.GanttChartRow").constructor('Connect .NET');
row3.addRange('03/13/07','06/01/07','darkslategray');
jbossChart.addRow(row3);

row4 = createobject("component", "com.orbwave.charts.gantt.GanttChartRow").constructor('Complete URL Rewrites','striped');
row4.addRange('06/05/07','10/30/07','blue');
jbossChart.addRow(row4);
</cfscript>

Once you set all the properties for the chart and each row, you just call the draw() method.

<cfset jbossChart.draw() />

Things left to do for the next version:

  • Allow multiple blocks of tasks
  • Validation of row ranges to prevent overlaps
  • Scroll-to dates to take user to a specific date in the chart
  • General validation of dates to prevent end dates earlier than start dates

Download Gantt Chart source code

Steelers Training Camp Visit

  • Filed under: steelers
Monday
Aug 7,2006

Got a chance to go to a VIP event at Steelers Training Camp on Friday. It was a nice experience (if a tad hot) as we watched the highlight DVD from last season, got to walk on the field while the players stretched…

did drills…

and scrimmaged…

We then ate in ‘Rooney’ tent while Heath Miller and Casey Hampton signed autographs.

It was a great time and they guys looked fast and ready to win another Super Bowl.

Latest Tweets

  • Watch video on this page to see a quick shot my family's biz and a heapin' helpin' of Pittsburghese - http://bit.ly/aMxuLN
  • Ever wonder how insignifcant the Earth is on a cosmic scale? http://bit.ly/PV4o
  • How did I miss this highlight??? Hasek takes out Gaborik http://su.pr/1KZtN2
  • Rooted & upgraded my HTC Hero w/#Froyo. Holy shit is it faster and have improved features. Painless, too. http://bit.ly/cBjvuH #fusprint
  • @Antipimp You will do what Father Jobs tell you to do, peon.