User Guide

Table Of Contents
Building an event gateway 1097
If your application sends any messages to multiple listener CFCs, the gateway must create and
configure a CFEvent instance and call the
gatewayService.addEvent method to send the
message to each separate listener CFC. The gateways
setCFCListeners method must make the
CFC paths available to the gateway for configuring the CFEvent instances.
If your ColdFusion server carries a heavy event gateway message load, the ColdFusion event
gateway services event queue might reach the maximum value set in the ColdFusion MX
Administrator. When this happens, the
gatewayService.addEvent method returns False and
fails. Your code can do any of the following:
Return a message to the sender to indicate that their message was not received.
Wait until the queue is available by periodically comparing the values returned by the
GatewayService
getQueueSize and getMaxQueueSize methods, and retry the addEvent
method when the queue size is less than the maximum.
Log the occurrence using the logger returned by the GatewayService getLogger method. (For
more information, see “Logging events and using log files” on page 1099.)
The SocketGateway class implements the listener using a java.net.ServerSocket class object and
SocketServerThread listener threads. (See the SocketGateway source for the SocketServerThread
code.) When the listener thread gets a message from the TCP/IP socket, it calls the following
processInput method to dispatch the message to ColdFusion. This method explicitly sets all
required and optional CFEvent fields and sends the event to ColdFusion. If the
addEvent call
fails, it logs the error.
Note: Much of the processInput method code supports multiple listener CFCs. A gateway that uses
only a single listener cfc, would require only the code in the latter part of this method.
private void processInput(String theInput, String theKey)
{
// Convert listeners list to a local array
// Protect ourselves if the list changes while we are running
String[] listeners;
int size = cfcListeners.size();
if (size > 0)
{
// Capture the listeners list
synchronized (cfcListeners)
{
listeners = new String[size];
cfcListeners.toArray(listeners);
}
}
else
{
// Create a dummy list
listeners = new String[1];
listeners[0] = null;
}
// Broadcast to all the CFC listeners
// Send one message at a time with different CFC address on them
for (int i = 0; i < listeners.length; i++)
{