CFLib.org – Common Function Library Project

createEndpoint(channelId)

Last updated March 20, 2010

author

Marko Simic

Version: 1 | Requires: CF9 | Library: UtilityLib

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:

createEndpoint("collyba-longpolling-amf");

Parameters:

Name Description Required
channelId Channel ID. Yes

Full UDF Source:

/**
 * 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);
    }

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson