The best way to learn about event gateway applications is to dive into the examples that ship with ColdFusion MX 7. Look for these examples under the "gateway" subdirectory in your install directory.
The DirectoryWatcherGateway event gateway comes preconfigured on ColdFusion MX 7 as an example to help you build your first CFML gateway application. The Java source code is also available for you to learn how to write your own Java gateway.
This event gateway watches a directory for changes. Based on your configuration file, which specifies the directory you want to watch and file system events you want to watch for (such as file creation, deletion, and changes), you can also send event objects to your CFC with the information when any event occurs.
In the following example, a CFC processes events using the DirectoryWatcherGateway event gateway:
<cffunction name="onAdd" output="no">
<cfargument name="CFEvent" type="struct">
<!--- get event data --->
<cfset data=CFEvent.data>
<!--- log a message --->
<cflog file="watch"
text="a file was #data.type# and " &
"the name was #data.filename#">
<!--- watcher will ignore outgoing messages --->
</cffunction>
The code is pretty simple—the function takes the event object as an argument and treats it like a simple CFML struct datatype. The data key of the struct contains a message that describes the file system event. The two entries in this struct are as follows:
filename of the file that changed type of change that happened: add, delete, or changeThe event gateway also contains an entry, lastModified, which specifies the time an added or changed file was last modified.