
1329
DEVELOPING
COLDFUSION 9 APPLICATIONS
Using External Resources
Las
t
upda
te
d 8/5/2010
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.
//log.error(e1);
}
}
// Close and release the serverSocket instance that gets requests from the
// network.
if (serverSocket != null) {
try
{
serverSocket.close();
}
catch (IOException e1)
{
}
//Release the serverSocket.
serverSocket = null;
}
// Shutdown succeeded; set the status variable.
status = STOPPED;
}
The restart method
In most cases, you implement the
restart
method by calling the
stop
method and the
start
method consecutively,
but you could be able to optimize this process for some services. The following code shows the SocketGateway class
restart
method:
public void restart() {
stop();
start();
}
Responding to incoming messages
One or more listener threads respond to incoming messages (events). The threads must include code to dispatch the
messages to ColdFusion event gateway services, as follows:
1
Create a CFEvent instance.
2
Create a Map instance that contains the message and any other event gateway-specific information, and pass it to
the CFEvent
setData
method.