The first, the HsCommunicator service, acts as a network socket based interface. The service starts up within its own thread space and listens to incoming connections on a given port (5776 by default). These connections are passed off to CommunicatorThread objects (in the haystack.service.misc package). The CommunicatorThread objects are themselves threads which allow the HsCommunicator to handle multiple calls simultaenously. The CommunicatorThread objects simply read the input from the socket and submit the text to the HsCommandAPI.
There are a number of utility functions within the HsCommunicator that allow for the cleanup of all CommunicatorThread objects. We would like Haystack to shutdown when the close() operation is invoked on the HsCommunicator it will run through the CommunicatorThreads it knows about and shuts them down. To do this, the HsCommunicator maintains a list of all running CommunicatorThread objects.