The amazing adventures of Doug Hughes

Archive for June, 2007

Heading Out to CFUnited

I’m headed out within the next few hours on a 6 hour drive up to Maryland for the CFUnited conference. Although I’ll be attending a few sessions, my main motive is not educational this year. Instead, I’ll be up there looking to drum up business and “pressing the flesh”.

If you or your company have a need for some world-class ColdFusion or Flex consulting please look for either myself or Scott Stroz. We’ll be happy to discuss whatever is on you mind!
I hope to see you at CFunited.

Frameworks BOF at CFunited, Wednesday at 9pm

As Joe announced yesterday, on Wednesday at 9pm there will be a frameworks BOF (birds of a feather) session. I expect Ill be there to represent Reactor and, maybe, an as of yet unannounced framework. Maybe, just maybe, if you attend the BOF youll learn the (suggestive) name of this new framework!

At the same time, Scott will be giving his Prototyping Applications in Flex presentation as a BOF session. This was moved due to a scheduling conflict with another presentation.

Whichever you choose, we (Alagad) hope to see you there!

Off to Flexmaniacs, then CFUnited

I am getting ready to make the hour or so trip down to Washington DC for Flexmaniacs. If you have not heard of it, Flexmaniacs is the first Flex-centric conference on the East Coast. I am giving two presentation during the 2 day conference. My session topics are ‘Printing in Flex 2’ and ‘Sorting, Filtering and Paginating Data in Flex 2’.

After the conference ends on Tuesday, I will be heading up the road for CFUnited. As I mentioned here, there were some scheduling issues with my ‘Prototyping Applications in Flex’ session. TeraTech has graciously given me a ‘Birds Of a Feather’ (BOF) session on Wednesday night, at 9:00 PM, to discuss the materials which would have been presented during the originally scheduled time slot.

Its going to be a busy, but fun week. Hope to see you at one or both of the conferences!

Variables.Instance

This week I was walking through some code in a code review and the question came up, why do I use the “extra” instance structure within my components. For example, in my init() function for every component, I have a line of code that looks like this:

<cfset variables.instance = structNew() />

Then, when I setup a new attribute for the component, I would store it in a variable like this:

<cfset variables.instance.foo = "bar" />

So, beyond personal habit, why do I do this? There are several reasons, some of which may be more valid in different contexts.

  1. It tends to make variables more obvious in the code so that you know what is a local variable for a function versus a global attribute for the component.
  2. You can dump this structure and see a quick snap shot of the ‘state’ of the component. While you can dump the variables scope, you will not only get the variables but also lots of function meta data which is not always desirable.
  3. For the OO purists out there, having all of the attributes contained within a structure like this makes it very simple to write the equivalent of a “copy” constructor.
  4. For components that might be extended in the future by yourself or another developer, you run the risk of variable collisions – that is variables with the same name in the base component as well as the extended component. By using a specially named structure for your instance variables, this can be prevented.

I don’t know if this was reason enough to convince my colleague, but it is reason enough for me to keep doing this in my components. Is this a wide spread best practice or am I the only one?

Give it to me!!!

If you are going to be attending CFUnited and would like to help the Make-a-Wish Foundation as well as get out some pent up frustration, check out what’s happening Wednesday night.

Service Layers, an Analogy

I’ve been working with a programmer recently who is new to both design patterns and object oriented programming. He’s been maintaining some old code I wrote a while back and trying to change how it behaves. Obviously, this could be challenging for someone who’s new to OO.

So, the other day he asked me to explain what Service Objects are. I tried to explain the nature of the Faade design pattern and how a service is simply a faade for more complex operations in your system. I tried to explain that it’s a good practice to wrap all of your model objects to make it easier to expose this functionality to various systems.

Honestly I wasn’t terribly successful with this explanation. In his particular case his service was going to use a gateway object (yet another design pattern) to get a query and return it. But, if the service is returning a query, how does the service differ from the gateway?

I had to think about how to explain this, and what I came up with was this analogy:

Let’s say I ask you to get me a nice frosty mug of beer. If you agree to get me this cool, refreshing, beer, you’ll be performing the service of getting a beer. You, you’re a service object. You perform a service.

Now, personally, and I’m not trying to be rude here, I honestly don’t care how you get the beer. You could run to the store and buy a mug, some dry ice, and a six pack. You could go to the neighborhood pub and run off with a fresh drawn beer. More likely, you’ll just walk (heck, you could run or skip, for all I care) to the fridge, grab a beer and poor it into a mug, and bring it back to me. And, just to illustrate my point again, you could use a bottle opener, your teeth or any other mechanism to open the beer. To me, those are just (implementation) details that don’t matter, so long as I get my frosty mug of beer back.

Now, let’s think about what you care about as the service. Do you care how the fridge stays cold? Do you care how it was manufactured? Do you care how the beer was brewed? You might care what brand of beer (microbrews only, please), but chances are that’s already a constraint of the system you’re running in. You don’t care how long the beer was fermented. You don’t care how long the mugs are kept cold to make them frosty. All these details are the responsibility of other systems that, though essential ultimately, to you, my BeerService, being able to successfully get me my beer.

So, lets break the analogy down a bit. Who are the players and what do they represent?

Me/I. I represent any system which uses your service. I could be a remote faade used by flex. I could be a controller in your MVC framework. I could be another service that just really needs a beer.

You. You’re a BeerService component (or maybe a BarTenderService). You have a set of methods related to beer (or bartending, I guess, as the case may be). For example, getBeer(), restockBeer(), cleanMugs(), wipeUpSpills(), cutOffUser(), etc. As the user of the service, I don’t care how you get these things done, you just do them, far as I’m concerned.

The Fridge, The Beer, The Mug, etc. These are components within your application’s model. In real computer systems these are objects that have specific responsibilities. For instance, the mug in our system is responsible for being frosty and holding beer. In a real system you might have a BeerGateway that is responsible for listing beers in your database.

I hope that helps clarify things!

Changing the Font Size in Eclipse

A couple weeks ago I was preparing giving a three day training class on Model-Glue and Enterprise ColdFusion Development. (Interested in some onsite training? Send me an email!) Unfortunately, the default font size in Eclipse is way to small to see on a projector. It took me nearly half an hour to figure this out, so I thought I’d post how to do this for posterity’s sake:

Within Eclipse click Window > Preferences. This will open up the Preferences dialog with gives you about a million configuration settings to tweak.

At the top of the list on the left you will see General. Click to open this. Next click Appearances. Finally, select Colors and Fonts from under Appearances.

This is where it gets confusing. Eclipse shows a tree of what appear to be languages or plugins or something. Underneath each one are many options for specific types of text. There are many choices in this dialog with no clearly obvious one.

Well, the one you’re looking for is “Text Font” under the “Basic” node. Select this and click the “Change” button that appears. From here, it’s just a matter of selecting the new font size and applying it.

Oh, and when you’re ready to go back to the old font size just click the Reset button to go back to your old settings.

CF7, CF8, Jrun and the JVM

As I mentioned in this post, I described, briefly how my development environment is set up, and how I installed ColdFusion 8 onto the same JRun server where I have ColdFusion 7 installed. A reader inquired about the JVM and if there are any conflicts. Well, the answer is no, there are not. Why? Well, becasue when you deploy ColdFusion 8 as a .ear file onto a server running ColdFusion 7, JRun will use the JRE specified in the java.home variable in {jRun root}/bin/jvm.config, which in my case was 1.4.2_09.

Now, I have been running this configuration since the public beta and have not run into any issues with performance, or even errors occurring when running ColdFusion 8 code. However, I wanted to set-up my ColdFusion 8 to use the same JRE it would if I had done a different install (stand alone, or multi-server). This was easy enough as you can create custom jvm.config files and use them to run your JRun ‘servers’.

Here’s to do it.

Disclaimer: This is for Windows only. I assume the procedure would be similar in a different environment.

  1. Download the latest Java SDK and install it. (You may be able to use the JRE alone, but I didn’t test this)
  2. Make a copy of jvm.config (located in {JRun root}/bin } and name it jvm_cf8.config. (You can name it whatever you would like, but the rest of the instructions assume you use this name)
  3. Change the java.home variable from “C:/JRun4/jre” (It may be different for you) to {new SDK Install path}/jre and save the file.
  4. If its running, stop the ColdFusion 8 service.
  5. Open a command window and “cd” to {JRun Root}/bin
  6. Test the new config by typing jrun -config jvm_cf8.config -start {the name of your ColdFusion 8 server in Jrun}. If you don’t get any errors, you can now set up your Windows service to use this config file.
  7. Pressing crtl+c should shut down the JRun server you just started.
  8. Type the following to remove the windows service jrunsvc -remove {the name of your ColdFusion 8 server in JRun}
  9. Now you need to reinstall the Windows service and tell it to use the new config jrunsvc -install {the name of your ColdFusion 8 server in JRun} -config jvm_cf8.config.
  10. You should now be able to start ColdFusion 8 from the Services MMC in Windows.

To verify you are using the updated JVM, log into the ColdFusion Administrator for ColdFusion 8 and go to ‘System Information’ (It’s the blue icon on the top right side of the page) and check the JRE and JVM values.

UPDATED: As noted by Andy Allan in a comment below, when you copy jvm.config and update the java.home variable, you also need to update the java.library.path variable as well. This variable should point to you new instance of ColdFusion. He also warns to be careful with pathing to the new instance as there may be some subtle differences between the new instance, and the ‘default’ instance.

Allow myself to.. uh… introduce myself

My name is Critter Gewlas and I have recently joined the Alagad. In my short time here, I have already had the opportunity to work on several projects. Coldspring, Model-Glue, Mach II, Reactor… you name it. If it’s a framework, I get to work with it in enterprise environments. Seriously, how great is that? It’s much more rewarding than just cataloging my CD collection in the various frameworks :).

I have been working with ColdFusion since 1998 and have been loving it ever since. I also dabble with C#, and another favorite of mine, Delphi.

It’s a great feeling to actually enjoy going into walking downstairs to work. I am very excited about the future of ColdFusion. The introduction of Flex and and Adobe’s new AIR is just icing on the cake, in my eyes. I am also very excited about working with Doug and the rest of the brilliant minds at Alagad. I can already tell that it will be a great and learning full experience.

Running CF8 & CF 7 on JRun with Apache

On my development machine, I run ColdFusion 7 in ‘multi-server’ mode. This comes in handy if you need to create a separate instance of ColdFusion because of needs of a project or client. I also run Apache as my web server. While I am not a big fan of the httpd.conf file (mostly out of lack of familiarity), it makes it a lot easier to run multiple web sites on Windows XP. (Yes, I know there are tools that allow you to do this with IIS, but all the ones I have tried have been buggy and made messing with httpd.conf a pleasant experience). I also add sites to my HOSTS file and give them a ‘domain’ of ‘dev’ (boyzoid.dev, for example). This makes it easier for me to keep track of which environment I am in, and in a lot of cases, save some typing as I usually abbreviate the project (mic.dev, for example).

Like most ColdFusion developers, I wanted to play with ColdFusion 8 when it went into public beta. I wanted to be able to use ColdFusion 8 and not have to deviate much from my development practices. I wound up installing ColdFusion 8 as a .ear file and deploying it to the same instance of JRun on which ColdFusion 7 is running. This way I could manage all my ColdFusion instances in one place. I ran into one small problem though, how do I get a site configured in Apache to use the ColdFusion 8 server rather than the ColdFusion 7 server? For those who may not know, when you are using IIS and multiserver install of ColdFusion, when you add news ‘sites’ to IIS, you ccan specify what instance of ColdFusion to use for the site. The answer was surprisingly simple.

First, keep in mind these instructions pick up AFTER ColdFusion 8 has been installed and deployed to your JRun server and the server is running. It also assumes that Apache has already been configured to work with ColdFusion

  1. Go into your JRun Admin and find the ‘server’ you specified when you deployed ColdFusion 8, and click the link. In my case, its named ‘cf8’.
  2. In the resulting screen, click the ‘Services’ link in the navigation bar.
  3. In the next screen, click the ‘Start’button next to the ‘Proxy Service’. Take note of the ‘proxy port’, we will need that in a bit.
  4. Create a directory, with whatever name you woud like) under {Jrun}/lib/wsconfig (In my case, I named it ‘cf8’…original, I know)
  5. Open up httpd.conf and create a <virtualHost> to use, or you can use an existing one.
  6. In httpd.confand look for a block of code that looks like:
    # JRun Settings
    LoadModule jrun_module "C:/JRun4/lib/wsconfig/1/mod_jrun20.so"
    <IfModule mod_jrun20.c>
    JRunConfig Verbose false
    JRunConfig Apialloc false
    JRunConfig Ssl false
    JRunConfig Ignoresuffixmap false
    JRunConfig Serverstore "C:/JRun4/lib/wsconfig/1/jrunserver.store"
    JRunConfig Bootstrap 127.0.0.1:51020
    #JRunConfig Errorurl <optionally redirect to this URL on errors>
    #JRunConfig ProxyRetryInterval 600
    #JRunConfig ConnectTimeout 15
    #JRunConfig RecvTimeout 300
    #JRunConfig SendTimeout 15
    AddHandler jrun-handler .jsp .jws .cfm .cfml .cfc .cfr .cfswf
    </IfModule>
    

    This information is what Apache uses to pass off requests to ColdFusion.

  7. Copy the following lines:
    JRunConfig Apialloc false
    JRunConfig Serverstore &quot;C:/JRun4/lib/wsconfig/1/jrunserver.store&quot;
    JRunConfig Bootstrap 127.0.0.1:51020
    
  8. Paste the above lines inside the <virtualHost> block you created, or chose, in step 6.
  9. In the line: JRunConfig Serverstore “C:/JRun4/lib/wsconfig/1/jrunserver.store”, change the path so it matches the path of the directory you created in step 4. Make sure you keep the ‘/jrunserver.store‘ on the end. Don;t worry about the file not being there, it will get added auto-magiaclly.
  10. In the line JRunConfig Bootstrap 127.0.0.1:51020, replace the port number (the number after the colon) with the ‘proxy port’ number we noted in step 3.
  11. Restart Apache.

The <virtualHost> you created will now use ColdFusion 8 instead of the default server (which in my case was ColdFusion 7).

How do we know its using ColdFusion 8? Easy, just create a test page with <cfdump var=”#server#” />, you’ll see a version number that begins with ‘8’.

You can also use this method for pointing Apache to different instances of the same version of ColdFusion, since, as far as JRun cares, they are all just servers.

Tag Cloud