Conduit ArchitectureThere is a basic pattern when dealing with each of the three types of core CFCs that make up Conduit. Invoker, Serialiser and Deserialiser Basic Structure
InvokerThe invoker's job is to find the CFC to be called, and then call the method that has been requested from Flex Remoting. SerialiserThis component is responsible for serialising CF=>AS3 in the remoting communication process DeserialiserThis component is responsible for deserialising AS3 => CF in the remoting communication process. Method Invocation PatternThere is a basic pattern to each of the CFC components that make up the Conduit structure, as they all extend conduit.core.AbstractComponent Initialise(configMap)The initialise method is called when Conduit first starts up with ColdFusion, and it gets passed the Java ConfigMap object, which is essentially a case sensitive struct. This is how you can pass your custom settings into a Conduit CFC. It is important to call 'setFilterType(filtertype);', so Conduit knows what filters to apply to this CFC from the configuration. It is important to call super.initialise(), inside initialise(), so the core functionality of Conduit will also be initialised. A simple example: <cffunction name="initialise" hint="called when the adapter is first created, this is the place to setup any dependencies" access="public" returntype="void" output="false">
<cfargument name="configMap" hint="the flex.messaging.config.ConfigMap from the BlazeDS adapter (case sensitive struct)" type="any" required="Yes">
<cfscript>
setFilterType("deserialiser");
super.initialise(argumentCollection=arguments);
</cfscript>
</cffunction>
validate()The validate method is in place to pickup if configuration for the CFC is invalid. If you wish to report a validation error, use It is important to call super.validate(), inside validate(), if you define it, so the core functionality of Conduit will also be validated. A simple example: <cffunction name="validate" hint="called after 'initialise', throw an exception if something is wrong" access="public" returntype="void" output="false">
<cfif NOT StructKeyExists(variables, "myObject")>
<cfthrow message="myObject should have been initialised. Please check your configuration" />
</cfif>
</cffunction>
execute()This is the method that actually does stuff. The execute method is really just a convention, and depending on what you are implementing, it can have different arguments. That being said, an Invoker's, Serialiser and Deserialiser's execute() methods must have the arguments it currently has in the Conduit core implementation, as it is called from the Java Adapter. You can see this in the bundled ColdDoc documentation that comes with the download. A simple example of this is, in the conduit.core.CFSerialiser: <cffunction name="execute" hint="serialises CF into objects for returning to AS3" access="public" returntype="any" output="false">
<cfargument name="object" hint="the object to serialise" type="any" required="Yes">
<cfscript>
arguments.cache = createObject("java", "java.util.HashMap").init();
return translate(argumentCollection=arguments);
</cfscript>
</cffunction>
|