A server class may need to handle a large number of incoming requests. If it takes more than a few milliseconds to handle each request, clients who make the request may have to wait longer than an acceptable period of time while the server works on other incoming requests. A better solution is to have the server store each incoming request as a search on a queue. Another thread can then take searches from the queue in the order they arrived and process them one at a time. This is known as the active object pattern;[1] it decouples the method request from the actual execution of the method. See Figure 13.1. All relevant search information is translated into a command object for later execution.
Figure 13.1. Active Object
Note: If you're not connected to the Internet, the search test will not execute properly. This is corrected in short timethe section entitled Less Dependent Testing shows how to modify the test to execute against local URLs. |