248 CHAPTER 8 PERSISTENT COMMUNICATIONS PATTERN (Web server address) In
Wednesday, October 31st, 2007248 CHAPTER 8 PERSISTENT COMMUNICATIONS PATTERN In Figure 8-8, the HTTP server is hosted on the main server and accessed by multiple clients. Two of the clients are humans using web browsers. The other client is another computer. The client that is a computer is running an application that listens for changing information. If the information changes, it writes data to the writing stream, resulting in an HTTP PUT or POST causing a change in the other two listening clients. Separating the processes makes it possible to change how the service listens and updates the data on the HTTP server. Example: Presence Detection Presence detection in code terms is an incremental update of the global status application. The incremental update is the requirement of the global status resource to know who is accessing the resource. The identity of the user is used to enhance the content of the global status resource. Authenticating the User The basis code of Presence Detection is the global status code just presented. The client code remains as is, because it already has the facilities to retrieve a username and password. The ServerCommunicator needs to be updated to include functionality used to identify the user. The mechanism used to identify the user could be HTTP authentication or a cookie, but HTTP authentication is used in this example. Because a user might want to implement different forms of authentication, an interface is defined. Following are the interface definitions: public interface UserIdentification { public String getIdentifier(); public Boolean isIdentified(); } public interface UserIdentificationResolver { UserIdentification identifyUser(HttpServletRequest request); } The interface UserIdentificationResolver identifies a user based on the servlet request interface HttpServletRequest. The interface UserIdentification represents an identified user if the property isIdentified returns true. Looking at the interface definitions, you will probably get a sense of d j vu, and that would be correct. In the Permutations pattern, identifying the user used the same interface declarations, but the interfaces were declared as IUserIdentificationResolver and IUserIdentification because the code was written in .NET. If you want to know more about the implementation of user identification interfaces, be sure to read the section An Example Shopping Cart Application in Chapter 5. Updating the ServerCommunicator The ServerCommunicator functionality for the presence detection will be implemented by using the class WhoisOnline. In implementation terms, WhoisOnline is an increment to the previously defined GlobalStatus. Following is the partial implementation of WhoisOnline:
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.