
1328
DEVELOPING
COLDFUSION 9 APPLICATIONS
Using External Resources
Las
t
upda
te
d 8/5/2010
The
start
method should return within a time-out period that you can configure for each event gateway type in the
ColdFusion Administrator. If it does not, the ColdFusion Administrator has a Kill on Startup Timeout option for each
gateway type. If you select the option, and a time-out occurs, the ColdFusion starter thread calls an interrupt on the
gateway thread to try to kill it, and then exits.
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 Administrator for such gateways.
If the gateway uses a configuration file, load the configuration from the file. Doing so lets users change the
configuration file and restart the gateway without restarting ColdFusion. Also load the configuration file in the
constructor; for more information, see “
Class constructor
” on page 1325.
In the SocketGateway class, the
start
method starts an initial thread. (In a single-threaded Gateway, this thread would
be the only one.) When the thread starts, it calls a
socketServer
method, which uses the Java ServerSocket class to
implement a multi-threaded socket listener and message dispatcher. For more information on the listener, see
“
Responding to incoming messages
” on page 1329.
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: