CHAPTER 11 REST-BASED MODEL VIEW CONTROLLER PATTERN (Web site directory)
CHAPTER 11 REST-BASED MODEL VIEW CONTROLLER PATTERN Look at the implementation of the method processRequest. The first call is to call the method super.processRequest, which translates to calling the ParentBase.processRequest method. The base class method implementation will start all the threads. Then, when the base class returns, SynchronousParent retrieves the Iterator instance to the currently executing threads. The method processRequest will use the iterator to iterate each thread ID and call the method thrd.join. Calling thrd.join will call the calling thread to wait until the thread referenced by the variable thrd has finished executing. The idea is to call the join method on each of the executing threads, and if all have been called, then no thread will be executing. Relating this back to the addResult method, what happens is that a caller of SynchronousParent will expect to execute all the Command interface instances. Let s call that the main thread. SynchronousParentthen spawns a number of child threads. The main thread then waits until all child threads have executed. During the execution of the child threads, results will be added by using the method addResult. However, no results will be retrieved because the main thread is waiting for all the child threads to finish. After all the child threads have finished executing, the main thread returns control to the caller of SynchronousParent, who then proceeds to iterate the results. When the results are iterated, there will be only one thread accessing the data. This finishes the basic architecture of the REST-Based Model View Controller pattern. The last remaining piece is to implement the Java servlet. The implementation of the Java servlet will be broken into two pieces; one is used to handle asynchronous requests, and the other to handle synchronous requests. The implementation is broken into two pieces because of the complexity associated with the implementation. Remember from the architecture that the REST-Based Model View Controller pattern needs to implement the Permutations pattern. Combining the Permutations pattern with the asynchronous and synchronous implementations would be too much complexity in one explanation. Handling an Asynchronous Search The asynchronous Java servlet search will be discussed first because it will not implement the Permutations pattern. The focus of the asynchronous Java servlet is to configure the REST-Based Model View Controller pattern implementation, illustrate how to make a call, and then process the results. Posting a Query Consider the following source code that defines the Java Servlet class AsynchronousServlet and configures the SearchBuilder class: public class AsynchronousServlet extends HttpServlet { public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException { SearchBuilder.assignConfiguration( config.getInitParameter( “amazon-endpoint”), config.getInitParameter( “amazon-access-key”), config.getInitParameter( “amazon-secret-key”), config.getInitParameter( “google-endpoint”), config.getInitParameter( “google-access-key”)); }
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.