CFLib.org – Common Function Library Project

createDestination(destname, channelId)

Last updated March 20, 2010

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

 
Rated 0 time(s). Average Rating: 0

Description:
In case you want to physically separate communication between certain groups of users, best way to do that is to create new destination and to direct messages on it. One way to do that is to define destination in messaging-config.xml or dynamically at runtime using this function. It takes 2 arguments: - destname - Destination name - channelId - Channel ID. Channel is either defined in services-config.xml or you may use createChannel method to do it at runtime

Return Values:
Returns a destination object.

Example:

view plain print about
local.newdestination = createDestination('classRoom_1','collyba-longpolling-amf');

Parameters:

Name Description Required
destname Destination name. Yes
channelId Channel ID. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Creates BlazeDS destination at runtime
 * 
 * @param destname      Destination name. (Required)
 * @param channelId      Channel ID. (Required)
 * @return Returns a destination object. 
 * @author Marko Simic (marko.simic@gmail.com) 
 * @version 1, March 20, 2010 
 */

function createDestination(destname, channelId){
    var local = structNew();
    
    local.brokerClass = createObject('java','flex.messaging.MessageBroker');
    local.broker = local.brokerClass.getMessageBroker( javacast('null','') );
    local.service = local.broker.getService('message-service');
    local.destinations = local.service.getDestinations();
    
    //check if destination already exists. If it does just return it
    if (structKeyExists(local.destinations,arguments.destname)){ //check if destination already exist
        return local.destinations[arguments.destname];    
    }
    
    // Creates a ServiceAdapter instance and sets its id, sets if destination  is manageable
    local.destination = local.service.createDestination(arguments.destname);
    local.destination.createAdapter('cfgateway');
    
    local.configMap = createObject('java','flex.messaging.config.ConfigMap').init();
    local.configMap.addProperty('gatewayid',application.CFEventGatewayId);
    
    local.ss = createObject("java","flex.messaging.config.ServerSettings");
    local.ss.setAllowSubtopics(true); 
    local.ss.setSubtopicSeparator('.');
    local.ss.setDurable(false);
    
    local.destination.setServerSettings(ss);
    
    local.adapter = local.destination.getAdapter();
    
    //Initializes the adapter with the properties.
    local.adapter.initialize('cfgateway',configMap);
            
    local.destination.addChannel(arguments.channelId);
    
    //Starts the destination if its associated Service is started and if the destination is not already running. 
    local.destination.start();
    
    return local.destination;
}
</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