While working with async gateways, I discovered some behaviour that I
thought'd I'd pass on to the group.  Some of the more seasoned people may
already be aware of it but it threw me off for a while and I'd thought I
might save some people some headache by sharing.  When calling async
gateways, its imperative that you pass a localized structure if you intend
on modifying the structure while the gateway process is running.  Passing a
structure to the Event only passes a pointer to the structure.  Normally
when processing serially this wouldn't cause a problem because when doing
it in parallel you just should be aware your calling process may overwrite
the data before the responding process (the gateway cfc) gets a chance to
work with it.  I've included 3 files which quickly demonstrate this.  Put
the myProcess.cfc in CF Administrator as on of your gateways and then run
the calling pages.  They produce two text files test1 and test2 and it
should be apparent whats going on looking at the difference between them.
In case you don't get the attachments, I've copied the code below.



myProcess.cfc
<cfcomponent displayname="My Process">
      <cffunction name="OnIncomingMessage" returntype="void">
      <cfargument name="CFEvent" type="struct">
            <cflock name="fileWrite" timeout="100">
            <cffile action="append" file="C:\#CFEvent.data.fileName#"
output="#CFEvent.data.line#">
            </cflock>
      </cffunction>
</cfcomponent>







myProcess1.cfm
<cfset data=structnew()>
<cfset data.fileName="test1.txt">
<cfloop index="data.line" from=1 to=1000>
       <cfset sendGatewayMessage("myProcess",data)>
</cfloop>






myProcess2.cfm
<cffunction name="sendGateway">
      <cfargument name="data" type="struct">
      <cfset var localData = duplicate(arguments.data)>
      <cfset sendGatewayMessage("myProcess",localData)>
</cffunction>

<cfset data.fileName="test2.txt">
<cfloop index="data.line" from=1 to=1000>
      <cfset sendGateway(data)>
</cfloop>


Jason Cronk
[EMAIL PROTECTED]

(See attached file: myProcess2.cfm)(See attached file: myProcess1.cfm)(See
attached file: myProcess.cfc)




----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]

Attachment: myProcess2.cfm
Description: Binary data

Attachment: myProcess1.cfm
Description: Binary data

Attachment: myProcess.cfc
Description: Binary data

Reply via email to