Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion

ColdFusion: Article

Using Gateways PART 2

The basics

Part 1 in this series (CFDJ, Vol. 7, issue 5) discussed the options in the ColdFusion Administrator for configuring the event gateway facility in ColdFusion MX 7 and how to register new event gateway types.

There was little in the way of explaining how to use event gateways, so in this article we'll explore the basics of using event gateways through two examples: the code from the previous article and another of the out-of-the-box event gateway types, the CFML asynchronous event gateway type. These two gateway types represent the two fundamental varieties: the types that respond to events external to a ColdFusion application and the types that respond to events generated within a ColdFusion application.

Event gateways represent a new kind of service architecture for ColdFusion that is composed of a number of logical groups, each with its own intricacies. This article glosses over much of the deeper details with the intent of getting you up and running without bogging you down. Not to worry though, the finer details ignored now will be covered in greater detail in a later article.

A rough overview of the choreography of gateways can be seen in the ColdFusion MX 7 product documentation (Developing ColdFusion MX Applications, Using Event Gateways, About event gateways, How event gateway applications work). Many of the framed pieces in this diagram are identified with common event gateway jargon discussed in Part 1. [http://livedocs.macromedia.com/coldfusion/7/ htmldocs/images/gatewayb.jpg]

The two discrete pieces we're going to discuss in this article are the listener CFCs and CFM Pages (the calling logic being either a CFML template or a ColdFusion Component).

CFML Code for Gateways
To create a gateway instance you need a gateway type, a configuration file (which is optional in some cases) and a listener CFC. ColdFusion MX 7 comes with seven gateway types to start you off, one of which, the DirectoryWatcher type, was used in the previous article to verify the instructions for creating a gateway instance. Since the sample code was for an event gateway that responded to external OS level events, it had only a listener CFC written for it, which is a good place to begin.

Listener CFCs
Developers familiar with frameworks in other languages will recognize the role that the methods in a listener CFC fulfill - the event handler. Similar to a class implementing a component or control delegate in the .NET Framework or a Java bean event listener in Java, the listener CFC is the chunk of code that is the implementation-specific part of the more generic problem domain as defined by the gateway type.

While the gateway type defines the method names, the signature always remains the same (with the obvious exception of the method name itself): a public method with one argument, a structure, which may return a string. (Note: Signature is a term used to indicate a function's or a method's definition, its name, the names and data types of its arguments, and data type of the returned value [http://en.wikipedia.org/wiki/Signature_%28Computer_Science%29].)

Event Handling Methods
The one method argument is called the CFEvent and contains information about the gateway instance, the default listener CFC that the gateway instance will use, and a structure containing any data elements sent by the method's calling logic. These data elements can be populated by the Java code of the gateway type as well as the CFML code invoking the gateway instance.

The Members of CFEvent
Each event handler method receives a single structure, the CFEvent argument. This structure contains seven members by default that are almost solely for informational purposes. They are listed in Table 1 and in the ColdFusion product documentation (CFML Reference, ColdFusion MX Event Gateway Reference, CFML CFEvent structure).

Reviewing the Previous Sample
Looking at the code from Part 1 (available at: [http://gemsres.com/story/may05/86134/source.html]), we find two files, CCOJASDirectoryWatcher.cfg (the configuration file) and CCOJASDirectoryWatcher.cfc (the listener CFC), which were used to create the gateway instance, CCOJASDirectoryWatcher.

Within this component we see three methods: onAdd, onDelete, and onChange. These methods are defined by the DirectoryWatcher gateway type (Developing ColdFusion MX Applications, Using Event Gateways, Using the example event gateways and gateway applications). These methods are the event handlers for the DirectoryWatcher gateway instance and none of them are required. If a listener CFC does not implement one of these event handling methods, the gateway instance does not attempt to make a call to the method. This means that the listener CFC needs to implement only what is germane to the problem domain and nothing more.

The CFEvent's data Member
In the case of this example, all three event handling methods were implemented and, as was demonstrated in Part 1 ("Cold Cup o' Joe - Another Shot: Gateways to Fun, Putting It All Together"), a log file was updated each time a file was added to, changed, and deleted from the watched directory. What is more interesting now is not just the execution of the gateway instance but the variables that get passed to the event handling methods.

Referring to CCOJASDirectoryWatcher.cfc from Part 1, you'll see that the first functional line of each method (lines 5, 12, and 19) pull out a structure called data from each method's CFEvent argument. This contains data about each OS level event that the DirectoryWatcher was monitoring for. This structure contains three members, identified in the ColdFusion product documentation (Developing ColdFusion MX Applications, Using Event Gateways, Using the example event gateways and gateway applications, Example event gateway, CFC methods) and shown in Table 2.

More Stories By Guy Rish

Guy Rish is a ColdFusion and .NET developer at Vente as well as President at Gestaltech. He is an active developer and writer for various languages and technologies, and has contributed work in books on ColdFusion MX, Flash MX, and Dreamweaver MX. He blogs at ccoj.coldfusionjournal.com.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
Real IoT production deployments running at scale are collecting sensor data from hundreds / thousands / millions of devices. The goal is to take business-critical actions on the real-time data and find insights from stored datasets. In his session at @ThingsExpo, John Walicki, Watson IoT Developer Advocate at IBM Cloud, will provide a fast-paced developer journey that follows the IoT sensor data from generation, to edge gateway, to edge analytics, to encryption, to the IBM Bluemix cloud, to Wa...
What is the best strategy for selecting the right offshore company for your business? In his session at 21st Cloud Expo, Alan Winters, U.S. Head of Business Development at MobiDev, will discuss the things to look for - positive and negative - in evaluating your options. He will also discuss how to maximize productivity with your offshore developers. Before you start your search, clearly understand your business needs and how that impacts software choices.
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that Fusic will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Fusic Co. provides mocks as virtual IoT devices. You can customize mocks, and get any amount of data at any time in your test. For more information, visit https://fusic.co.jp/english/.
SYS-CON Events announced today that MIRAI Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MIRAI Inc. are IT consultants from the public sector whose mission is to solve social issues by technology and innovation and to create a meaningful future for people.
SYS-CON Events announced today that Enroute Lab will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enroute Lab is an industrial design, research and development company of unmanned robotic vehicle system. For more information, please visit http://elab.co.jp/.
SYS-CON Events announced today that Mobile Create USA will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Mobile Create USA Inc. is an MVNO-based business model that uses portable communication devices and cellular-based infrastructure in the development, sales, operation and mobile communications systems incorporating GPS capabi...
There is huge complexity in implementing a successful digital business that requires efficient on-premise and cloud back-end infrastructure, IT and Internet of Things (IoT) data, analytics, Machine Learning, Artificial Intelligence (AI) and Digital Applications. In the data center alone, there are physical and virtual infrastructures, multiple operating systems, multiple applications and new and emerging business and technological paradigms such as cloud computing and XaaS. And then there are pe...
SYS-CON Events announced today that Interface Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Interface Corporation is a company developing, manufacturing and marketing high quality and wide variety of industrial computers and interface modules such as PCIs and PCI express. For more information, visit http://www.i...
SYS-CON Events announced today that Keisoku Research Consultant Co. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Keisoku Research Consultant, Co. offers research and consulting in a wide range of civil engineering-related fields from information construction to preservation of cultural properties. For more information, vi...
SYS-CON Events announced today that SIGMA Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. uLaser flow inspection device from the Japanese top share to Global Standard! Then, make the best use of data to flip to next page. For more information, visit http://www.sigma-k.co.jp/en/.
SYS-CON Events announced today that B2Cloud will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. B2Cloud specializes in IoT devices for preventive and predictive maintenance in any kind of equipment retrieving data like Energy consumption, working time, temperature, humidity, pressure, etc.
Agile has finally jumped the technology shark, expanding outside the software world. Enterprises are now increasingly adopting Agile practices across their organizations in order to successfully navigate the disruptive waters that threaten to drown them. In our quest for establishing change as a core competency in our organizations, this business-centric notion of Agile is an essential component of Agile Digital Transformation. In the years since the publication of the Agile Manifesto, the conn...
While some developers care passionately about how data centers and clouds are architected, for most, it is only the end result that matters. To the majority of companies, technology exists to solve a business problem, and only delivers value when it is solving that problem. 2017 brings the mainstream adoption of containers for production workloads. In his session at 21st Cloud Expo, Ben McCormack, VP of Operations at Evernote, will discuss how data centers of the future will be managed, how th...
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp em...
SYS-CON Events announced today that Nihon Micron will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nihon Micron Co., Ltd. strives for technological innovation to establish high-density, high-precision processing technology for providing printed circuit board and metal mount RFID tags used for communication devices. For more inf...
SYS-CON Events announced today that Suzuki Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Suzuki Inc. is a semiconductor-related business, including sales of consuming parts, parts repair, and maintenance for semiconductor manufacturing machines, etc. It is also a health care business providing experimental research for...
SYS-CON Events announced today that Ryobi Systems will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Ryobi Systems Co., Ltd., as an information service company, specialized in business support for local governments and medical industry. We are challenging to achive the precision farming with AI. For more information, visit http:...
SYS-CON Events announced today that Daiya Industry will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Daiya Industry specializes in orthotic support systems and assistive devices with pneumatic artificial muscles in order to contribute to an extended healthy life expectancy. For more information, please visit https://www.daiyak...
In his session at @ThingsExpo, Greg Gorman is the Director, IoT Developer Ecosystem, Watson IoT, will provide a short tutorial on Node-RED, a Node.js-based programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using a wide range of nodes in the palette that can be deployed to its runtime in a single-click. There is a large library of contributed nodes that help so...