User Guide

Table Of Contents
1090 Chapter 45: Creating Custom Event Gateways
The following code defines the SocketHelper class, the gateway helper for the SocketGateway
class. It has an empty constructor and two public methods: one returns the socket IDs; the other
closes a specified socket. These classes let an application monitor and end session connections.
public class SocketHelper implements GatewayHelper {
public SocketHelper() {
}
public coldfusion.runtime.Array getSocketIDs () {
coldfusion.runtime.Array a = new coldfusion.runtime.Array();
Enumeration e = socketRegistry.elements();
while (e.hasMoreElements()) {
a.add(((SocketServerThread)e.nextElement()).getName());
}
return a;
}
public boolean killSocket (String socketid) {
try
{
((SocketServerThread)socketRegistry.get(socketid)).socket.close();
((SocketServerThread)socketRegistry.get(socketid)).socket = null;
socketRegistry.remove(socketid);
return true;
}
catch (IOException e) {
return false;
}
}
}
Gateway configuration file
Gateways can use a configuration file to specify information that does not change frequently. For
example, the ColdFusion SMS event gateway configuration file contains values that include an IP
address, port number, system ID, password, and so on.
You can specify a configuration file path for each event gateway instance in the ColdFusion MX
Administrator. ColdFusion passes the file path in the gateway constructor when it instantiates the
event gateway. The configuration file format and content handling is up to you. It is the
responsibility of the gateway class to parse the file contents and use it meaningfully.
One good way to access and get configuration data is to use the java.util.Properties class. This
class takes an ISO8859-1 formatted input stream with one property setting per line. Each
property name must be separated from the value by an equal sign (=) or a colon (:), as the
following example shows:
ip-address=127.0.0.1
port=4445
The example SocketGateway event gateway uses this technique to get an optional port number
from a configuration file. For an example of reading a properties file and using its data, see the
code in “Class constructor” on page 1092.