User Guide

1012 Chapter 6: ColdFusion MX Event Gateway Reference
Example
The following example keeps an Application scope structure up-to-date with a buddys status. It
also uses the gatewayhelper object
getBuddyStatus method to get the buddys custom away
message, if any.
<cffunction name="onBuddyStatus">
<cfargument name="CFEvent" type="struct" required="YES">
<!--- Get the gatewayhelper object and to get the info for this buddy. --->
<!--- This is used to get the buddy's custom away message. --->
<cfset helper = getGatewayHelper("MYIM")>
<cfset mybuddyinfo=helper.getBuddyInfo(CFEvent.Data.BUDDYNAME)>
<cflog file="#CFEvent.GatewayID#Status" type="Information"
text="in OnbuddyStatus, sender is #CFEvent.OriginatorID#">
<cflock scope="APPLICATION" timeout="10" type="EXCLUSIVE">
<cfscript>
// Create the status structures if they don’t exist.
if (NOT StructKeyExists(Application, "buddyStatus")) {
Application.buddyStatus=StructNew();
}
if (NOT StructKeyExists(Application.buddyStatus,
CFEvent.Data.BUDDYNAME)) {
Application.buddyStatus[#CFEvent.Data.BUDDYNAME#]=StructNew();
}
// Save the buddy status, timestamp, and custom away message
Application.buddyStatus[#CFEvent.Data.BUDDYNAME#].status=
CFEvent.Data.BUDDYSTATUS;
Application.buddyStatus[#CFEvent.Data.BUDDYNAME#].timeStamp=
CFEvent.Data.TIMESTAMP;
// The following assumes that the buddy is in only one group.
Application.buddyStatus[#CFEvent.Data.BUDDYNAME#].customAway=
mybuddyinfo[1].BUDDYCUSTOMAWAYMESSAGE;
</cfscript>
</cflock>
<!--- log the info, for debugging purposes only --->
<cfset temp=Application.buddyStatus[#CFEvent.Data.BUDDYNAME#].status>
<cflog file="#CFEvent.GatewayID#Status" type="Information" text=
"Application.buddyStatus[#CFEvent.Data.BUDDYNAME#].status is #temp#">
<cfset temp=Application.buddyStatus[#CFEvent.Data.BUDDYNAME#].timeStamp>
<cflog file="#CFEvent.GatewayID#Status" type="Information" text=
"Application.buddyStatus[#CFEvent.Data.BUDDYNAME#].timestamp is #temp#">
<cflog file="#CFEvent.GatewayID#Status" type="Information" text=
"Buddy Custom Away Message is mybuddyinfo[1].BUDDYCUSTOMAWAYMESSAGE#">
</cffunchtion>