The amazing adventures of Doug Hughes

Archive for September, 2007

Welcome to Alagad, Jared!

As many people may have already noticed, Alagad has hired Jared Rypka-Hauer to join our team. As with the rest of our team, Jared is an exceptional talent and were lucky to have him on board.

For those who don’t already know Jared, he’s the brains and brawn behind the CF.Objective conference and a rabid contributor to the ColdFusion and Adobe Toolset community.

In particular, Jared will help strengthen our (already significant) ability to deliver advanced Flex and Air applications. Jared is also a fantastic resource as far as ColdFusion, frameworks and application architecture are concerned.

As with Alagads other employees, Jared will continue to have a very active role in the ColdFusion community. Expect frequent blogging, talking, training, running of CF.Objective, and more. Before long, I expect Jared to post his first blog entry here as we quickly get him up to speed.

Welcome to the team, Jared!

Doing 'screenshots' in Flex and sending them to ColdFusion

This weekend I was doing some research about capturing ‘screen shots’ of a Flex application, or even specific UI components, and passing the ‘image’ back to the server for processing.

While there are a few ways to do this, I am going to discuss the ‘easiest’. Using the JPGEncoder class packaged as part of the AS3 CoreLib on Google Code. Using this class to encode the data on the client side means that very little needs to be done server side to save the data as an image.

Its fairly easy to use this encoder to create binary data and pass it to CF. I have set up an example here. If you enter some text into the text area inside the panel and click ‘Send Image’, Flex will create a JPG of the panel and send it off to CF.

Here is a look at some of the code, you can also view the source from the Flex application.

First, I import the JPGEncoder class. I store a lot of AS libraries and components in one location and add them to the ‘source path’ of my application.

import com.adobe.images.JPGEncoder;

Next, I create a method that converts a UI component into BitmapData.

private
function getBitmapData(target: UIComponent): BitmapData {
    var bitmapData: BitmapData = new BitmapData(target.width, target.height);
    var matrix: Matrix = new Matrix();
    bitmapData.draw(target, matrix);
    return bitmapData;
}

As you can see, this method can take any UI element as an argument. This method returns the bitmap data of the UI element that was passed in.

Next, I create a method that handles calling the above method, and then sends the result to ColdFusion:

private
function sendImage(target: UIComponent): void {
    var bitmapData: BitmapData = getBitmapData(target);
    var jpgEncoder: JPGEncoder = new JPGEncoder(90);
    var imgData: ByteArray = jpgEncoder.encode(bitmapData);
    imageService.saveImage(imgData);
}

This method also takes any UI element and uses it when calling getBitmapData(). It also creates an instance of the JPGEncoder class. The ‘90‘ that is passed into the constructor of JPGEncoder is the ‘quality’ of the resulting JPG.

Next we need to create a<mx:remoteObject> to talk to ColdFusion.

<mx:RemoteObject destination="ColdFusion" id="imageService" showBusyCursor="true" source="path.to.cfc">
    <mx:method name="saveImage" result="onResult(event)"/>
</mx:RemoteObject>

The CFC itself is very simple, it contains 1 method whose only argument is the binary data that is our image.

<cfcomponent displayname="Image Service" name="Image Service" output="false">
    <cffunction access="remote" name="saveImage" output="false" returntype="any">
        <cfargument name="data" required="true" type="binary"/>
        <cffile action="write" file="c:Tempflex_image.jpg" output="#arguments.data#"/>
    </cffunction>
</cfcomponent>

You will see that inside the method all we do is a <cffile> to write the data to a file.

Lastly, we need some code that will fire off this entire event inside our Flex application.

<mx:Panel height="400" id="panel" layout="absolute" title="My Title" width="400">
    <mx:TextArea bottom="5" left="5" right="5" top="5"/>
</mx:Panel>
<mx:Text text="Enter some text in the text area above and click 'Send Image'"/>
<mx:Button click="sendImage(panel)" label="Send Image"/>

In my online example I have other code that will open a new browser window and show you the image you just captured. You can view the source by right-clicking the application and selecting ‘View Source’.

Using this technique, you can do a screen shot of your entire application, or just individual UI components.

Speaking at Columbus ColdFusion User Group

On September 27th, I will be giving a presentation to the Columbus ColdFusion User Group. The meeting is scheduled for 6:00PM. I am unsure if it will be available via Connect, but will check and post back here.

The presentation will be an introduction to Flex with focus on using Flex with ColdFusion.

On a side note, I will be in the Columbus area from the 27th – 30th for The Gathering of P-51 Mustangs and Legends Air Show. If any CF-ers in the area would like to get together for drinks, dinner or possibly a round of golf (I plan on trying to play on Friday), let me know.

What were they thinking?

Below is an editorial I wrote for CFDJ about ColdFusion 8. Given the publication’s untimely demise, I thought it might be worthwhile to publish my article here.

Several weeks ago in the #coldfusion channel on the Dalnet IRC network we had a rather spirited discussion about some of the new features of ColdFusion 8.The discussion in particular focused on <cfimage>, and its related tags, and if ColdFusion developers actually needed such functionality as part of the product we have all come to know and love.In recent weeks, as I have heard public discussions by Adobe about some of the new features of ColdFusion 8, and as I played with some of these features as part of the public beta, I realized that discussion could have been about any number of features that are a part of ColdFusion 8.

I cannot remember where I heard or maybe read, it, but sometime ago there was some buzz in the community because a respected member of the community made a claim that most ColdFusion developers only use about 10 tags. I will admit, I may have the number wrong, but I think you can understand the point.There are 2 new tags, and related tags, that I think will bump up that number, <cfimage> and <cfzip>.I know that currently there are several products we can use for image manipulation, as well as for creating and using .zip files.I also fully understand that most of these products are nothing more than a wrapper for Java functionality available to any ColdFusion developer using ColdFusion MX or higher.

For a lot of ColdFusion developers, using any of these products, or Java itself, are not options.There are a wide variety of reasons, but one that stands out in my mind is ease of use.Some of the products that exist which perform tasks we will have in ColdFusion 8 are not easy to use.Learning how to interact with Java, or for some people, learning to use CFCs, might be enough of a hurdle to dissuade their use.It might even come done to the cost of learning these tools that limits their usefulness.Keep in mind the easy is a relative term.If you asked the developers of an of these tools, or any of the OO or Java gurus who are part of the ColdFusion community, they will tell you these tools are easy to use, and may even think they are not needed.However, for a lot of developers, they are not ease to understand, much less use.

I was drawn to ColdFusion because it was easy for me to create applications my employer, at the time, wanted.I spent about a year programming an intranet application in PHP before discovering ColdFusion.In about a week, I was able to recreate enough of the intranet application in ColdFusion to persuade my employer that cost of the server licenses would be more than made up for in the increase in my productivity.It took me about 6 weeks to completely rewrite the intranet application into a ColdFusion application. How was it possible to take an application which took a year in one language, and rewrite it in 6 weeks using ColdFusion?The answer is obvious, ColdFusion is easy.

So, to answer my question, do we really need <cfimage> or <cfzip>? Yes, we do.We need them so that ColdFusion will continue to be easy. We need them so that developers who may not, or cannot, use third party tools for image manipulation can create more powerful and compelling applications in a fraction of the time.We need them so that developers who only have access to shared hosting and cannot invoke native Java objects can create applications they desire, and deserve.

This discussion can go beyond the coding features of ColdFusion 8.Do we really need server monitoring?A lot of ColdFusion developers probably do not work on applications so large, or heavily visited, that server metrics would even be on their radar.I must admit, the server monitoring tools in ColdFusion 8 are awesome.The amount of information you can collect about your server is astounding.To be able to view live data about memory usage, database statistics pertaining to slow running queries and stats about individual page requests is quite impressive, but is it necessary?I think so, because ColdFusion is not only easy, its powerful.

<cfimage> and <cfzip> make it easier to accomplish fairly common tasks, Server Monitoring gives us a tool we can use to streamline our applications.I think that looking at the Server Monitoring tools, even on the smallest applications, offers us something no other language, or application server, can claim, the server itself can help us learn to be better developers. By studying the database statistics we can see which queries are taking longer to run.This may lead us to look a little closer at our SQL statements to see if we can make them more efficient. By watching the data about page requests, we may be inclined to look at our ColdFusion code itself and see how we can code more efficiently, or even to begin caching practices we have otherwise overlooked.At the very least, it will give us an idea of where to start looking when we eventually have the chance to work on the enterprise level application that is having performance issues.The bets part is, we dont need to install anything else, we dont need to fuddle with third party libraries or products.All we need is access to the ColdFusion Administrator.

There are two other groups of tags that I think make ColdFusion both easier and more powerful.<cfexchange> and <cfpresentation> give ColdFusion developers functionality I am not sure exists in any third party tools, or can be easily recreated by the average developer using Java.I will admit, when we got our first glimpse of <cfpresentation> at CFUnited last year my response was lukewarm at best.Yes, I thought it was cool, but what purpose could it possibly serve?As I started playing with ColdFusion 8 and tried out <cfpresentation> I realized that it has a myriad of uses.With very little code, developers could create presentations covering a vast array of uses including new employee orientation, annual reports, online training and in-services for new products or procedures. <cfpresentation> makes it not only easy to create, but update, these presentations.

I know of quite a few developers who would love to easily include some basic e-mail functionality, via Microsoft Exchange, into their applications.I know that a lot of information can be gleaned from later versions of Exchange using <cfldap>.However, I think some might be more inclined to try and learn Java than muddle their way through LDAP and the directory hierarchy that exists in Exchange.<cfexchange> offers not only the ability to retrieve mail, contacts, appointments, etc from an Exchange server, but to create new contacts, tasks and appointments as well.I know of a handful of developers already working on applications that will mimic Outlook Web Access (OWA) functionality using ColdFusion 8. So now their intranet mail application is written in a language they feel more comfortable with, as well as having the mail application fit within the standard web template for their respective companies (I know this can probably be done now with OWA, but its ASP, or whatever flavor Microsoft is using these days, and what ColdFusion developer wants to punish themselves like that?).

I have not had the time to play with every new feature of ColdFusion 8. But I have made a point to try out all the features I thought were excellent additions to ColdFusion, as well as the ones that initially made me wonder, What were they thinking?I can say without hesitation I do not think there is any new feature that does not add value to ColdFusion and to ColdFusion developers.Each new feature makes ColdFusion easier, more powerful or both.Whether you will use any of these new features immediately, or six months down the road, ColdFusion 8 gives us new tools to make it easier to create powerful applications even faster than before. Dont get me wrong, there are some things I would have preferred over some of these new features, but each of the new features adds something to the language we have all come to love.

So, do we really need all these new features? If you want ColdFusion to become more powerful, yet easier to use, and if you want to become even more efficient at creating applications and making your application code more efficient, the answer is a resounding, Yes!

Implementing High Availability

High Availability (HA) should be the goal for any web application environment, which is business-mission critical. The big question though is what constitutes acceptable HA? In this article we discuss the various levels in a total environment and what can and should be done in each level to ensure adequate redundancy at an affordable cost, in relation to the overall costs and business-mission critical nature of the web applications. This article assumes the use of a hosting company and that the equipment is co-located. Co-location typically means you own the servers-software and rent rack-space from a hosting company who typically supply firewall-routers-switches etc.

Let’s consider a typical dedicated or co-located web application infrastructure, here is a diagram showing an entry level infrastructure and we will expand on this as we go through this article.

1/ Basic Infrastructure (Little or no Redundancy)

Non Redundant

I have encountered many infrastructures which look like this. This is no doubt a start point if moving from a shared hosting environment. The weaknesses are fairly obvious, with only one of each key component, if one fails we have no service. There are some things that can be done to introduce some coverage-redundancy in this set-up.

Firstly, find out from the hosting provider what their Service Level Agreement (SLA) is for repairing-replacing their equipment should it fail (firewalls, switches, servers note you will own the servers if this is a co-located arrangement). Make sure within the SLA there are provisions for maintaining back-ups of all data, configuration files etc. Once you know what the SLA says you will know how long you could be without service in the case of a failure.

Secondly, consider what components in each server could be covered in case of failure. Multiple Hard-drives, for instance, can be configured so that if a single drive fails there is no loss of service. To do this we create RAID arrays. RAID is an acronym for Redundant Array of Inexpensive Disks. There are two main types of RAID arrays, one where two hard drives are in the array and are mirrored (RAID levels 1 and 10) and another where there are 3 or more disks in an array (RAID levels 5 and 6) this last type of array is typically used where there is a lot of data to be stored. Also multiple network cards are a good idea as that is a critical component which is easy to add to a server. Power is also critical so redundant power supplies per server are also good. The items that are difficult to be made redundant are things such as RAM, Motherboard etc.

2/ Basic Redundancy

Redundant

Adding a second web-CF server is an important step; in fact adding a second anything takes us into a different realm, adding a level of true redundancy. The important point to bear in mind here is to make sure there is replication between the two servers so that web site content is kept synchronized allowing site visitors to be handled by ether server, seamlessly. We have also added a clustering device to handle all incoming traffic and to control which web-CF server site visitors go to. We shall be covering clustering-load balancing in greater detail in a future article.

The comments regarding SLAs, RAID arrays, back-ups etc still apply.

3/ Ideal Basic Redundancy

Ideal 1

In this configuration we have full redundancy at all levels of the infrastructure (please note, we are not explicitly showing network switches here but they would be redundant also). In this configuration the second device(s) Firewall, Router, Clustering Device, Database Server are in a hot-standby mode, denoted by a red-outline. This means they are in a fully operational state, fully replicated etc and ready to take over from the primary device should it fail. Two other states could be cold-standby meaning some configuration is still necessary before the device can take over and fully operational meaning they are taking traffic in a parallel state with their redundant partner.

The comments regarding SLAs, RAID arrays, back-ups etc still apply.

4/ Enterprise Level Redundancy

Ideal 2

In this case not only is each piece of equipment redundant but the whole grouping of all pieces of equipment also. So not only are we covered in the event of a single piece of equipment failing but also a catastrophic failure of some kind.

If we located these installations in different geographical locations we have coverage in the event of major natural disasters. Critical items in this last kind of installation are keeping data-settings synchronized and also handling domain name resolution if the two installations are in different geographical locations. There are specialist companies who can help with those sorts of issues.

The comments regarding SLAs, RAID arrays, back-ups etc still apply.

In this article we have attempted to lay out some scenarios for ensuring redundancy-HA. There are other ways we could have recommended but we based the article on real-world situations we have worked with on behalf of clients. In future articles we will cover parts of this in greater depth focusing on clustering, database issues etc.

Tag Cloud