CHAPTER 8 PERSISTENT COMMUNICATIONS PATTERN using Jetty

CHAPTER 8 PERSISTENT COMMUNICATIONS PATTERN using Jetty 6.x, the code will be slightly different and more resource efficient. For more details of the Jetty code, please see the Jetty documentation. However, to satisfy those readers who would like to see a correct implementation, the following abbreviated source code is provided. Note that before reading this source code, it is important to fully understand the Permutations pattern because the code has specific references to the implementation of the pattern: class ServerCommunicator extends HttpServlet { Class _rewriter; Class _router; public void init(ServletConfig config) throws ServletException { try { _rewriter = (IRewriter)ServerCommunicator.class.getClassLoader( ).loadClass( config.getInitParameter(”rewriter”)).newInstance(); _router = (IRewriter)ServerCommunicator.class.getClassLoader( ).loadClass( config.getInitParameter(”router”)).newInstance(); } catch (Exception e) { throw new ServletException( “Could not instantiate types”, e); } } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException { IRewriter rewriter = _rewriter.newInstance(); IRouter router = _router.newInstance(); if (router.IsResource(request)) { router.ProcessPost(response); } } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { IRewriter rewriter = _rewriter.newInstance(); IRouter router = _router.newInstance(); if (router.IsResource(request)) { router.ProcessGet(response); } } } In the implementation of ServerCommunicator, the application logic is missing, as illustrated by the GlobalStatus class. It is not that the application logic completely disappeared, but that the application logic is delegated logic called by ServerCommunicator. As per the Permutations pattern, there are two interface instances: IRewriter and IRouter. The purpose of the IRewriter
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Leave a Reply