Search Server


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.

[1] [Lavender1996].

Figure 13.1. Active Object


You will build a simple web search server. The server will take a search object consisting of a URL and a search string as a request. As it searches the URL, the server will populate the search object with the number of times the string was found in the document at the URL.


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.



Agile Java. Crafting Code with Test-Driven Development
Agile Javaв„ў: Crafting Code with Test-Driven Development
ISBN: 0131482394
EAN: 2147483647
Year: 2003
Pages: 391
Authors: Jeff Langr

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net