Adobe COLDFUSION 9 Manual page 1331

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using External Resources
Because each event gateway instance must have a unique ID, ColdFusion provides redundant support for providing
the ID. If the event gateway implements only the default constructor, ColdFusion provides the ID by calling the
method of the event gateway.
setGatewayID
If the event gateway does not implement the two-parameter constructor, it does not get configuration file information
from ColdFusion.
The constructor normally calls the static GatewayServices.getGatewayServices method to access ColdFusion event
gateway services. Although you need not make this call, it is a good coding practice.
A minimal constructor that takes only a gateway ID could look like the following:
public MyGateway(String gatewayID) {
this.gatewayID = gatewayID;
this.gatewayService = GatewayServices.getGatewayServices();
}
The gateway constructor must throw a coldfusion.server.ServiceRuntimeException exception if an error occurs that
otherwise cannot be handled. For example, throw this exception if the event gateway requires a configuration file and
cannot read the file contents.
If your gateway uses a configuration file, have the constructor load the file, even if the
Load the file because the constructor does not run in an independent thread, and ColdFusion can display an error in
the ColdFusion Administrator of the file fails to load. If the
to load the file, ColdFusion logs the error, but it cannot provide immediate feedback in the administrator.
The sample Socket event gateway has a single constructor that takes two parameters. It tries to load a configuration
file. If you specify a configuration file in the ColdFusion Administrator, or the file path is invalid, it gets an IO
exception. It then uses the default port and logs a message indicating what it did. The following example shows the
Gateway constructor code and the
public SocketGateway(String id, String configpath)
{
gatewayID = id;
gatewayService = GatewayServices.getGatewayServices();
// log things to socket-gateway.log in the CF log directory
log = gatewayService.getLogger("socket-gateway");
propsFilePath=configpath;
try
{
FileInputStream propsFile = new FileInputStream(propsFilePath);
properties.load(propsFile);
propsFile.close();
this.loadProperties();
}
catch (IOException e)
{
// Use default value for port and log the status.
log.warn("SocketGateway(" + gatewayID + ") Unable to read configuration
file '" + propsFilePath + "': " + e.toString() + ".Using default port
" + port + ".", e);
}
}
private void loadProperties() {
String tmp = properties.getProperty("port");
port = Integer.parseInt(tmp);
}
Start
method it uses:
loadProperties
Last updated 8/5/2010
method also loads the file.
Start
method, which does run in a separate thread, fails
1326

Advertisement

Table of Contents
loading

Table of Contents