358 CHAPTER 11 REST-BASED MODEL VIEW CONTROLLER (Web server on xp)
Friday, December 21st, 2007358 CHAPTER 11 REST-BASED MODEL VIEW CONTROLLER PATTERN greater cost is the waiting time of the network communications. Therefore, to be robust, it is best if each local client waits individually and indicates to the controller when they have completed. While an individual thread is waiting, it is not consuming resources, and therefore having multiple waiting threads is not a problem for the server. Following is the implementation of the command execution: protected List _runningThreads = new LinkedList(); public abstract void addResult(Result result); public void processRequest( Request request) { Iterator iter = _commands.iterator(); _runningThreads.clear(); while( iter.hasNext()) { Command cmd = (Command)iter.next(); cmd.setRequest( request); cmd.assignParent( this); Thread thrd = new Thread((Runnable)cmd); _runningThreads.add( thrd); thrd.start(); } } public void processRequest( String impl, Request request) { Iterator iter = _commands.iterator(); _runningThreads.clear(); while( iter.hasNext()) { Command cmd = (Command)iter.next(); if( cmd.getIdentifier().compareTo( impl) == 0) { cmd.setRequest( request); cmd.assignParent( this); Thread thrd = new Thread( (Runnable)cmd); _runningThreads.add( thrd); thrd.start(); break; } } } The data member _runningThreads is a list of threads that are executing. The list is required by the synchronous or asynchronous controller implementations to know when a thread has completed. The method addResult, which is used to add a result to the controller, is defined as abstract because the synchronous or asynchronous implementations define their own way of managing the results. You will see this difference shortly. The processRequest methods are used to execute the Commandinterface instances. There are two versions of the processRequest method. The version with a single parameter executes all local clients. The version with two parameters executes a specific local client. Regardless of whether a single local client or all local clients are executed, they are executed on their own threads. This keeps the architecture simple so you don t have to deal with too many architectural variations.
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.