|By Simon Horwith||
|October 20, 2004 12:00 AM EDT||
Beginning with the release of ColdFusion MX, the ColdFusion Application Server now runs on top of an underlying Java engine. Java, as we all know, is an object-oriented language. However, the question of whether CFML is an object-oriented language has been under debate since the ColdFusion Component (CFC) Framework was introduced in ColdFusion MX.
Too much energy has been spent bantering about whether CFML is object oriented, rather than exploring uses for the object-oriented features that CFCs brought to the language. Among these features were inheritance, support for the creation of Web services, the ability to encapsulate data and business logic in objects and to perform instance-based development, and metadata.
So many new features mean that the rules have changed for ColdFusion developers. We must now relearn and redefine best practices, which not only means changing the way we write code but also the way that we plan our applications. Fortunately, we can take advantage of a wealth of knowledge about what does and doesn't work. We can do this by studying the design patterns and development techniques that have been tried and tested by object-oriented developers, most notably Java developers, for more than a decade. Because of the very nature of Web-application development, J2EE design patterns are particularly applicable when architecting applications with ColdFusion.
Unfortunately, understanding design patterns is only the first step toward building CFML applications the right way. There still remains the challenge of not only selecting the right pattern for the job, but also knowing how to implement a pattern (or not) in your code.
No single article, or book for that matter, could ever hope to provide the magic answer to determining what pattern to use when, or even how to properly implement any one design pattern in CFML. There are some patterns that lend themselves to the language very well and others that do not, and most could be implemented in any one of several manners. It would take several months, or years even, to properly test and document it all. The purpose of this article is to shed some light on a general realm of design patterns. This article will also case study a recent implementation that allowed me to quickly help reduce overhead, boost performance, and add functionality to a client application. It is just one example of how knowledge of design patterns and creativity with CFML can allow you to achieve your goals quickly and efficiently.
Working as a consultant, I am often asked to advise on architectural decisions as well as troubleshoot existing architectures. A client of mine developed an application (a framework) with ColdFusion allowing rather inexperienced developers to quickly and easily create data entry and data display screens on the Web. The idea being that defining the database table with XML and adding a few lines of code to a display file and a CFC (which inherits from a parent "object" code base) is all it takes to create screens that have a uniform look and feel and reproduce the screens in a massive legacy application. The client hopes to move the entire legacy application onto the Web within two years.
My role for the past year has primarily been to assess risks, advise on the best course of action, and to come in and fix problems when all else has failed. As you can imagine, at any given moment I might be researching several issues at once. Just prior to a recent major release of the software, I was asked to look into two major issues. One was the replication of sessions when servers in our J2EE clusters failover and the other was application performance in general.
The first thing I did was tackle the session replication problem. As it turns out, this was right around the time that J-Run Updater 4 and the ColdFusion MX 6.1 Updater were both released to the public. Unfortunately even with both updaters installed, after all of my testing I was unable to consistently make ColdFusion session variables replicate to a server that was added to the cluster. Session replication and failover works pretty consistently - when you turn off a server everything fails over and replicates fine. However, when you add a server back into the cluster, the session doesn't always replicate onto the new server properly. The application server console always reports a J2EESessionScope error when a server rejoins the cluster. Sometimes ignoring this message appears to be okay, and sometimes it does not. It's also worth noting that sending requests while a server was in the process of rejoining the cluster seems to encourage session replication failure. All of my tests with "pure" Java, even simple JSP files, consistently worked. Sessions always replicated just fine. One of my rules of thumb is to never spend too much time on one error, so I put that problem on the back burner and focused on the other problem: performance. We'll revisit the question of session replication later.
There are a lot of things that can kill performance and a lot of things that can be done to speed things up in an application. Every developer has a mental list of the things they do on a page or in an application to make it efficient (use CFSCRIPT, avoid unnecessary looping/conditional logic/HTTP, cache things in memory, optimize and minimize database calls, etc.). The list can be huge but the last two points, taking advantage of the server's memory and minimizing/optimizing calls to the database, are the two most common ways developers speed up their applications. But what can you do to speed up an application that already has all of these things in place? Go line by line through the code looking for small tweaks here and there?
You could do that, but the performance gains would be minimal and it would take a long time in this case. The application I was working with already consisted of about 600 files including not only the framework, but also the screen definitions and accompanying logic as well. The application I was asked to optimize also already had a great deal of caching and code reuse in place, and all of the database access had been gone over with a fine-tooth comb. When faced with a situation like this, I find that it's a good strategy to take a step back and look at the big picture.
Looking at the entire application from a distance must be a lot like looking at Earth from outer space. There are no countries, no borders, and no politics. There's just water, land, and clouds all working together to create that delicate balance needed to sustain life. All of the minute details blur together, allowing you to concentrate on the system as a whole rather than trying to focus on all of the smaller parts, which in the big picture are insignificant. When I thought about how I would model this client's application and how all of the parts of the model interacted, I looked for problems. If I didn't find any, I'd take a step back. Eventually, a potential problem almost always presents itself. In this case, when I finally got to the point of blurring modules into single tiers that interact with one other, something dawned on me: tier communication patterns.
It had been some time since I'd thought about all of the design patterns I've studied in the past. But I remembered that there are a few patterns I'd read about that deal primarily with communication between tiers in an application, whether those tiers were the presentation and business logic tiers or business logic and database. The application I was optimizing had a terribly high number of CFC instances being passed around between the presentation layer and the business components, between Java and ColdFusion, and between business components and other business components. I hadn't thought about this as a problem because the individual CFC instantiations and method calls were taking very little time at all. Most of the CFCs were instantiated and cached in memory once and then reused throughout the application. Still, there is a certain amount of overhead in passing instances of complex objects around in memory as well as in persisting all of the instruction sets for dozens of components. Many of these were even cached in sessions (for justifiable reasons). A few patterns came to mind that might shed light on a possible solution: Data Transfer Objects, Lazy Load Pattern, and the IsDirty Pattern. So I went back to the books and brushed up on the intricacies of these three patterns and some of their related patterns.
After refreshing my memory about these patterns, it became clear that what I was looking for was something along the lines of the Data Transfer Hash Pattern (the other patterns I mentioned have qualities I'm looking for but are more specific to database interaction). The idea behind the Data Transfer Hash Pattern is that passing instances of objects around carries with it a lot of overhead, so hashmap representations are used instead. Think of a hashmap as the Java equivalent of a ColdFusion structure. It's much more lightweight moving a hashmap data structure around rather than a complex object that contains functionality (e.g., a CFC instance). The one downside is that there's no easy way to enforce the values within that hashmap. This is a problem more easily remedied in Java by using Objects, but all too familiar and not-so-easily remedied in ColdFusion, as our only option is to use a CFC with a constructor. The IsDirty Pattern, in a nutshell, is all about setting a Boolean flag in a data container so that database commands to manipulate data are executed only when data has actually changed. The Lazy Load Pattern is similar to IsDirty in that it reduces database connectivity overhead. However, it does so by not retrieving data until it's specifically requested. In implementing the Data Transfer Hash Pattern, I will also borrow from these ideas in that I will keep external object access to a minimum until it is required. But the solution is still in essence more of a Data Transfer Hash Pattern solution.
So how do I put this idea of only transferring simple data collections rather than object instances into practice? Ideally, I'd like a way to represent the data contained within a CFC instance as a structure. Furthermore, I want to do so in a way that's flexible, easy for the end users of the framework to implement, and doesn't break the existing code base. Fortunately, there are some features in CFML that I can take advantage of to make this work.
For one thing, we have inheritance. In my particular scenario I could easily modify component.cfc to offer this functionality within all CFCs. I described this technique in an article titled "component.cfc: The Mother of All Components" in the November 2003 issue of ColdFusion Developer's Journal. The code has to be very portable, which means that I don't want to rely on this technique. Fortunately for me, because my "fix" must be implemented in the context of a framework and all CFCs in that framework inherit from a "master" CFC, I can easily create a component and specify that the "parent" inherits from it (via the <CFCOMPONENT> tag "extends" attribute). It also occurred to me that until an elegant solution to my session replication woes is found, this pattern offers the added bonus of helping to address that problem as well. In ColdFusion MX (6.1 or prior) CFC instances are not serializable. This means that they cannot be replicated across servers in a cluster. I knew this and did advise my client that all CFC instances in the session scope had to be made nonpersistent. This resulted in two code bases. One we wanted to implement but couldn't until serialized CFC instances is supported (a feature rumored to be in Blackstone). The other one works around the issue by not keeping CFC instances in the session scope. If I could present a way to represent CFC instances as structures, not only would it reduce overhead, but it would also offer a means to persist CFCs and have them replicate. This could be accomplished by serializing and deserializing them as structures. Although I was having trouble making serialization work for ColdFusion, structures map to hashmaps (and vice versa) quite well. Plus I'd already proven that Java session information serializes just fine.
My solution took advantage of the metadata created for CFCs: metadata exposed with the getMetaData() function. I created three methods. One simply accepts a CFC instance and returns its metadata in a more "friendly" format. Another accepts a structure and the name (including full package) of a component and returns an instance of that component populated with the structure data. The third method accepts a CFC instance and returns a structure containing all of its properties. How could I guarantee that I retrieved all of the properties?
My requirements were simple, and fortunately the framework coding standards that were already in place assured me that the following conditions already exist. When serializing the data in a CFC within a structure, I look for any property defined with a <CFPROPERTY> tag. If a method exists with the name "get" plus the property name, the code calls that method to get the value. If a property is defined that doesn't have a "getter," I copy it directly from the component's public "this" scope if it exists. When creating a component instance from a structure, I create an instance of the component and look for an init() method. If a nonprivate init() method exists and the structure contains keys with names of any and all required parameters, I pass the parameters to the init() method. After calling the init() method, if it exists, the code then loops over the structure that was passed and calls any method named "set" plus the structure key name (passing it the structure key value). If no "setter" exists but a public property with the same name as the current key name exists, the code sets a variable in the component's "this" scope with the name-value pair from the structure. It's probably not the most robust or flexible solution in the world, but it does serve my purpose.
The rest of the implementation details are just a matter of persisting structures whenever possible if an object isn't likely to receive much activity and serializing that structure as a CFC instance in the event that an actual object is required in a certain scenario. It's worth noting that in a system in which the CFC instances receive frequent method calls that manipulate their data, the overhead serializing and deserializing to and from structures carries more performance hit than simply keeping a component instance in memory. However, often in other scenarios you can free up a significant amount of memory and other resources by not keeping so many objects in memory. This may result in better performance (it did in my scenario).
More and more it is becoming evident that it's necessary to have at least a basic understanding of design patterns. Coupled with the features in ColdFusion MX, this opens up the doors to a whole new realm of development solutions using CFML. Any of you who are interested in seeing the code I used to implement this solution, may download it from www.sys-con.com/coldfusion/sourcec.cfm or from www.horwith.com/downloads/dto.zip.
I encourage you to not just examine my code but (more important) think about alternative approaches to problems and creative methods for implementing the design patterns that already exist and are just waiting to be explored by ColdFusion developers. It's also worth noting that the technique I've outlined is what J2EE application servers already do to serialize sessions in a cluster. The application server itself is a very good place to look for inspiration when trying to determine how best to meet business requirements in your applications.
SYS-CON Events announced today that Windstream, a leading provider of advanced network and cloud communications, has been named “Silver Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9–11, 2015, at the Javits Center in New York, NY. Windstream (Nasdaq: WIN), a FORTUNE 500 and S&P 500 company, is a leading provider of advanced network communications, including cloud computing and managed services, to businesses nationwide. The company also offers broadband, phone and digital TV services to consumers primarily in rural areas.
Nov. 23, 2014 07:30 PM EST Reads: 1,684
"There is a natural synchronization between the business models, the IoT is there to support ,” explained Brendan O'Brien, Co-founder and Chief Architect of Aria Systems, in this SYS-CON.tv interview at the 15th International Cloud Expo®, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
Nov. 23, 2014 12:00 PM EST Reads: 1,624
The major cloud platforms defy a simple, side-by-side analysis. Each of the major IaaS public-cloud platforms offers their own unique strengths and functionality. Options for on-site private cloud are diverse as well, and must be designed and deployed while taking existing legacy architecture and infrastructure into account. Then the reality is that most enterprises are embarking on a hybrid cloud strategy and programs. In this Power Panel at 15th Cloud Expo (http://www.CloudComputingExpo.com), moderated by Ashar Baig, Research Director, Cloud, at Gigaom Research, Nate Gordon, Director of T...
Nov. 23, 2014 07:45 AM EST Reads: 1,467
The definition of IoT is not new, in fact it’s been around for over a decade. What has changed is the public's awareness that the technology we use on a daily basis has caught up on the vision of an always on, always connected world. If you look into the details of what comprises the IoT, you’ll see that it includes everything from cloud computing, Big Data analytics, “Things,” Web communication, applications, network, storage, etc. It is essentially including everything connected online from hardware to software, or as we like to say, it’s an Internet of many different things. The difference ...
Nov. 22, 2014 10:00 PM EST Reads: 1,380
Cloud Expo 2014 TV commercials will feature @ThingsExpo, which was launched in June, 2014 at New York City's Javits Center as the largest 'Internet of Things' event in the world.
Nov. 22, 2014 05:30 PM EST Reads: 1,448
An entirely new security model is needed for the Internet of Things, or is it? Can we save some old and tested controls for this new and different environment? In his session at @ThingsExpo, New York's at the Javits Center, Davi Ottenheimer, EMC Senior Director of Trust, reviewed hands-on lessons with IoT devices and reveal a new risk balance you might not expect. Davi Ottenheimer, EMC Senior Director of Trust, has more than nineteen years' experience managing global security operations and assessments, including a decade of leading incident response and digital forensics. He is co-author of t...
Nov. 22, 2014 05:30 PM EST Reads: 1,301
ARMONK, N.Y., Nov. 20, 2014 /PRNewswire/ -- IBM (NYSE: IBM) today announced that it is bringing a greater level of control, security and flexibility to cloud-based application development and delivery with a single-tenant version of Bluemix, IBM's platform-as-a-service. The new platform enables developers to build ap...
Nov. 22, 2014 05:30 PM EST Reads: 1,460
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In his session at Internet of @ThingsExpo, James Kirkland, Chief Architect for the Internet of Things and Intelligent Systems at Red Hat, described how to revolutioniz...
Nov. 21, 2014 09:15 PM EST Reads: 1,376
The security devil is always in the details of the attack: the ones you've endured, the ones you prepare yourself to fend off, and the ones that, you fear, will catch you completely unaware and defenseless. The Internet of Things (IoT) is nothing if not an endless proliferation of details. It's the vision of a world in which continuous Internet connectivity and addressability is embedded into a growing range of human artifacts, into the natural world, and even into our smartphones, appliances, and physical persons. In the IoT vision, every new "thing" - sensor, actuator, data source, data con...
Nov. 21, 2014 08:00 PM EST Reads: 1,386
Technology is enabling a new approach to collecting and using data. This approach, commonly referred to as the "Internet of Things" (IoT), enables businesses to use real-time data from all sorts of things including machines, devices and sensors to make better decisions, improve customer service, and lower the risk in the creation of new revenue opportunities. In his General Session at Internet of @ThingsExpo, Dave Wagstaff, Vice President and Chief Architect at BSQUARE Corporation, discuss the real benefits to focus on, how to understand the requirements of a successful solution, the flow of ...
Nov. 21, 2014 08:00 PM EST Reads: 1,439
"BSQUARE is in the business of selling software solutions for smart connected devices. It's obvious that IoT has moved from being a technology to being a fundamental part of business, and in the last 18 months people have said let's figure out how to do it and let's put some focus on it, " explained Dave Wagstaff, VP & Chief Architect, at BSQUARE Corporation, in this SYS-CON.tv interview at @ThingsExpo, held Nov 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
Nov. 21, 2014 07:00 PM EST Reads: 1,291
Focused on this fast-growing market’s needs, Vitesse Semiconductor Corporation (Nasdaq: VTSS), a leading provider of IC solutions to advance "Ethernet Everywhere" in Carrier, Enterprise and Internet of Things (IoT) networks, introduced its IStaX™ software (VSC6815SDK), a robust protocol stack to simplify deployment and management of Industrial-IoT network applications such as Industrial Ethernet switching, surveillance, video distribution, LCD signage, intelligent sensors, and metering equipment. Leveraging technologies proven in the Carrier and Enterprise markets, IStaX is designed to work ac...
Nov. 20, 2014 09:15 PM EST Reads: 1,378
C-Labs LLC, a leading provider of remote and mobile access for the Internet of Things (IoT), announced the appointment of John Traynor to the position of chief operating officer. Previously a strategic advisor to the firm, Mr. Traynor will now oversee sales, marketing, finance, and operations. Mr. Traynor is based out of the C-Labs office in Redmond, Washington. He reports to Chris Muench, Chief Executive Officer. Mr. Traynor brings valuable business leadership and technology industry expertise to C-Labs. With over 30 years' experience in the high-tech sector, John Traynor has held numerous...
Nov. 20, 2014 06:00 PM EST Reads: 1,340
Bit6 today issued a challenge to the technology community implementing Web Real Time Communication (WebRTC). To leap beyond WebRTC’s significant limitations and fully leverage its underlying value to accelerate innovation, application developers need to consider the entire communications ecosystem.
Nov. 20, 2014 04:45 PM EST Reads: 1,135
The 3rd International @ThingsExpo, co-located with the 16th International Cloud Expo - to be held June 9-11, 2015, at the Javits Center in New York City, NY - announces that it is now accepting Keynote Proposals. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devices - computers, smartphones, tablets, and sensors - connected to the Internet by 2020. This number will continue to grow at a rapid pace for the next several decades.
Nov. 20, 2014 01:00 PM EST Reads: 1,584
The Internet of Things is not new. Historically, smart businesses have used its basic concept of leveraging data to drive better decision making and have capitalized on those insights to realize additional revenue opportunities. So, what has changed to make the Internet of Things one of the hottest topics in tech? In his session at @ThingsExpo, Chris Gray, Director, Embedded and Internet of Things, discussed the underlying factors that are driving the economics of intelligent systems. Discover how hardware commoditization, the ubiquitous nature of connectivity, and the emergence of Big Data a...
Nov. 20, 2014 12:30 PM EST Reads: 1,793
Almost everyone sees the potential of Internet of Things but how can businesses truly unlock that potential. The key will be in the ability to discover business insight in the midst of an ocean of Big Data generated from billions of embedded devices via Systems of Discover. Businesses will also need to ensure that they can sustain that insight by leveraging the cloud for global reach, scale and elasticity.
Nov. 18, 2014 09:00 PM EST Reads: 2,018
SYS-CON Events announced today that IDenticard will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. IDenticard™ is the security division of Brady Corp (NYSE: BRC), a $1.5 billion manufacturer of identification products. We have small-company values with the strength and stability of a major corporation. IDenticard offers local sales, support and service to our customers across the United States and Canada. Our partner network encompasses some 300 of the world's leading systems integrators and security s...
Nov. 18, 2014 08:15 PM EST Reads: 1,571
IoT is still a vague buzzword for many people. In his session at @ThingsExpo, Mike Kavis, Vice President & Principal Cloud Architect at Cloud Technology Partners, discussed the business value of IoT that goes far beyond the general public's perception that IoT is all about wearables and home consumer services. He also discussed how IoT is perceived by investors and how venture capitalist access this space. Other topics discussed were barriers to success, what is new, what is old, and what the future may hold. Mike Kavis is Vice President & Principal Cloud Architect at Cloud Technology Pa...
Nov. 18, 2014 01:30 PM EST Reads: 2,013
Cloud Expo 2014 TV commercials will feature @ThingsExpo, which was launched in June, 2014 at New York City's Javits Center as the largest 'Internet of Things' event in the world. The next @ThingsExpo will take place November 4-6, 2014, at the Santa Clara Convention Center, in Santa Clara, California. Since its launch in 2008, Cloud Expo TV commercials have been aired and CNBC, Fox News Network, and Bloomberg TV. Please enjoy our 2014 commercial.
Nov. 13, 2014 05:00 AM EST Reads: 3,543