User Guide

Table Of Contents
Building an event gateway 1095
Note: If the start method is the listener (for example, in a single-threaded gateway), the method
does not return until the gateway stops. Do not set the Kill on Startup Timeout option in the
ColdFusion MX Administrator for such gateways.
If the gateway uses a configuration file, the start method should load the configuration from the
file. Doing so lets users change the configuration file and restart the gateway without restarting
ColdFusion. Applications should also load the configuration file in the constructor; for more
information, see “Class constructor” on page 1092.
In the SocketGateway class, the
start method starts an initial thread. (In a single-threaded
Gateway, this would be the only thread.) When the thread starts, it calls a
socketServer
method, which uses the Java ServerSocket class to implement a multithreaded socket listener and
message dispatcher. For more information on the listener, see “Responding to incoming messages
on page 1096.
public void start()
{
status = STARTING;
listening=true;
// Start up event generator thread
Runnable r = new Runnable()
{
public void run()
{
socketServer();
}
};
Thread t = new Thread(r);
t.start();
status = RUNNING;
}
The stop method
The
stop method performs the event gateway shutdown tasks, including shutting down the
listener thread or threads and releasing any resources. The following example shows the
SocketGateway
stop method:
public void stop()
{
// Set the status variable to indicate that the server is stopping.
status = STOPPING;
// The listening variable is used as a switch to stop listener activity.
listening=false;
// Close the listener thread sockets.
Enumeration e = socketRegistry.elements();
while (e.hasMoreElements()) {
try
{
((SocketServerThread)e.nextElement()).socket.close();
}
catch (IOException e1)
{
// We don't care if a close failed.