CFLib.org – Common Function Library Project

createEndpoint(channelId)

Last updated March 20, 2010

Version: 1 | Requires: ColdFusion 9 | Library: UtilityLib

 
Rated 2 time(s). Average Rating: 4.0

Description:
Create channel which communicate with corresponding endpoints on the BlazeDS server. This is part we miss to complete "BlazeDS dynamic configuration" story we started with createDestination function. It takes single parameter: - channelId - Channel ID. Uniquely identify you channel definition. Usually channel is defined in services-config.xml. In this specific case (see warning below) we would do that like this: <channel-definition id="collyba-longpolling-amf" class="mx.messaging.channels.AMFChannel"> <endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/cfamflongpolling" class="flex.messaging.endpoints.AMFEndpoint"/> <properties> <enable-small-messages>false</enable-small-messages> <add-no-cache-headers>false</add-no-cache-headers> <polling-enabled>true</polling-enabled> <polling-interval-seconds>0</polling-interval-millis> <client-wait-interval-millis>1</client-wait-interval-millis> <wait-interval-millis>60000</wait-interval-millis> <max-waiting-poll-requests>200</max-waiting-poll-requests> <serialization> <enable-small-messages>false</enable-small-messages> </serialization> </properties> </channel-definition> IMPORTANT! This method create a channel and endpoint according to my specific needs. Anyhow, to adjust it to your needs is quite easy. That will be the subject of next upgrade of this function ;) For more information see my blog http://itreminder.blogspot.com/2010/03/blazeds-creating-endpoint-at-runtime.html I'll be glad to help.

Return Values:
Returns nothing.

Example:

view plain print about
createEndpoint("collyba-longpolling-amf");

Parameters:

Name Description Required
channelId Channel ID. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Create channel and endpoint at runtime
 * 
 * @param channelId      Channel ID. (Required)
 * @return Returns nothing. 
 * @author Marko Simic (marko.simic@gmail.com) 
 * @version 1, March 20, 2010 
 */

function createEndpoint(channelId){
        var local = structNew();
    
        local.brokerClass = createObject('java','flex.messaging.MessageBroker');
        local.broker = local.brokerClass.getMessageBroker( javacast('null','') );
        local.channelSets = local.broker.getAllChannelSettings();
        local.chennIds = local.broker.getChannelIds();
    
        //check if channel/endpoint is already created
        if (arrayContains(local.chennIds,arguments.channelId)){
            return;
        }
    
        //Channel definiton properties
        local.channelSettings = createObject('java','flex.messaging.config.ChannelSettings').init(arguments.channelId);
        local.channelProperties = createObject('java','flex.messaging.config.ConfigMap').init();
        local.chPropSerialize = createObject('java','flex.messaging.config.ConfigMap').init();  
    
        local.channelSettings.setClientType("mx.messaging.channels.AMFChannel");
        local.channelSettings.setEndpointType("coldfusion.flash.messaging.CFAMFEndPoint");
        local.channelSettings.setUri("http://{server.name}:{server.port}{context.root}/flex2gateway/cfamflongpolling");
    
        local.channelProperties.addProperty("
add-no-cache-headers","false"); 
        local.channelProperties.addProperty("
polling-enabled","true");
        local.channelProperties.addProperty("
polling-interval-seconds","0");
        local.channelProperties.addProperty("
client-wait-interval-millis","1");
        local.channelProperties.addProperty("
wait-interval-millis","60000");
        local.channelProperties.addProperty("
max-waiting-poll-requests","200");
    
        local.chPropSerialize.addProperty("
enable-small-messages","false");
        local.channelProperties.addProperty("
serialization",local.chPropSerialize); 
    
        local.channelSettings.addProperties(local.channelProperties);
    
        //Creates an Endpoint instance, sets its id and url
        local.endpoint = local.broker.createEndpoint(
                        arguments.channelId, 
                        "
http://{server.name}:{server.port}{context.root}/flex2gateway/cfamflongpolling",
                        local.channelSettings.getEndpointType());
        // Initialize the endpoint with id and properties
        local.endpoint.initialize(arguments.channelId, local.channelSettings.getProperties());
        //Start the endpoint
        local.endpoint.start();
    
        local.channelSets[arguments.channelId] = local.channelSettings;
        local.broker.setChannelSettings(local.channelSets);
    }
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
11 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
30 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson