Jetty

1. Jetty?

 - HTTP server, HTTP client, and javax.servlet container

2.  Features

 - open source
 - Small footprint
 - Asynchronous ( http://wiki.eclipse.org/Jetty/Feature/Continuations )
 - Enterprise scalable
 - Embeddable ( http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty ) 

3. License

 - Apache License 2.0
 - Eclipse Public License 1.0


4. Owner

 - <=6 codehaus 
 - 7 <= eclipse ( http://wiki.eclipse.org/Jetty/ )

5. Architecture ( http://wiki.eclipse.org/Jetty/Reference/Jetty_Architecture )

 - Conenctor
  • SocketConnector - for few busy connections or when NIO is not available
  • BlockingChannelConnector - for few busy connections when NIO is available(This connector uses efficient NIO buffers with a traditional blocking thread mode)
  • SelectChannelConnector - for many mostly idle connections or asynchronous handling of Ajax requests(This connector uses efficient NIO buffers with a non blocking threading mode)
  • SslSocketConnector - SSL without NIO
  • SslSelectChannelConnector - SSL with non blocking NIO support
  • AJPConnector AJP protocol support for connections from apache mod_jk or mod_proxy_ajp

 - Server
   plumbing between a collection of Connectors that accept HTTP connections, and a collection of Handlers that servicerequests from the connections and produce responses, with the work being done by threads taken from a thread pool.

 - ThreadPool
  • ExecutorThreadPool
  • QueuedThreadPool
      
 - Handler

  Understanding Handler Collections, Wrappers and Scopes

  • Handler Collection holds a collection of other handlers and calls each handler in order. This is useful for combining statistics and logging handlers with the handler that generates the response.
  • Handler List is a Handler Collection that calls each handler in turn until either an exception is thrown, the response is committed or the request.isHandled() returns true. It can be used to combine handlers that conditionally handle a request.
  • Handler Wrapper is a handler base class that can be used to daisy chain handlers together in the style of aspect-oriented programming. For example, a standard web application is implemented by a chain of a context, session, security and servlet handlers.
  • Context Handler Collection uses the longest prefix of the request URI (the contextPath) to select a specific ContextHandler to handle the request.


  Type
   1. Coordinating Handlers - Handlers that route requests to other handlers (eg HandlerCollection, ContextHandlerCollection)
   2. Filtering Handlers - Handlers that augment a request and pass it on to other handlers (eg. HandlerWrapper, ContextHandler,SessionHandler)
   3. Generating Handlers - Handlers that produce content (eg ResourceHandler and ServletHandler)

6. Continuations

 -  for Asynchronous Request handling

1) Obtaining a Continuation

The ContinuationSupport factory class can be used to obtain a continuation instance associated with a request:
Continuation continuation = ContinuationSupport.getContinuation(request);

2) Suspending a Request

To suspend a request, the suspend method is called on the continuation:
void doGet(HttpServletRequest request, HttpServletResponse response)
{
    ...
    // optionally:
    // continuation.setTimeout(long);
    continuation.suspend();
    ...
}

3) Suspend Resume Pattern

The suspend/resume style is used when a servlet and/or filter is used to generate the response after an asynchronous wait that is terminated by an asynchronous handler. Typically a request attribute is used to pass results and to indicate if the request has already been suspended.
void doGet(HttpServletRequest request, HttpServletResponse response)
{
     // if we need to get asynchronous results
     Object results = request.getAttribute("results");
     if (results==null)
     {
       final Continuation continuation = ContinuationSupport.getContinuation(request);
 
       // if this is not a timeout
       if (continuation.isExpired())
       {
         sendMyTimeoutResponse(response);
         return;
       }
 
       // suspend the request
       continuation.suspend(); // always suspend before registration
 
       // register with async service.  The code here will depend on the
       // the service used (see Jetty HttpClient for example)
       myAsyncHandler.register(new MyHandler()
       {
          public void onMyEvent(Object result)
          {
            continuation.setAttribute("results",results);
            continuation.resume();
          }
       });
       return; // or continuation.undispatch();
     }
 
     // Send the results
     sendMyResultResponse(response,results);
}



4) Suspend Continue Pattern

The suspend/complete style is used when an asynchronous handler is used to generate the response:
void doGet(HttpServletRequest request, HttpServletResponse response)
{
     final Continuation continuation = ContinuationSupport.getContinuation(request);
 
     // if this is not a timeout
     if (continuation.isExpired())
     {
       sendMyTimeoutResponse(request,response);
       return;
     }
 
     // suspend the request
     continuation.suspend(response); // response may be wrapped.
 
     // register with async service.  The code here will depend on the
     // the service used (see Jetty HttpClient for example)
     myAsyncHandler.register(new MyHandler()
     {
       public void onMyEvent(Object result)
       {
         sendMyResultResponse(continuation.getServletResponse(),results);
         continuation.complete();
       }
     });
}

7. Caution

WebSockets is not a silver bullet, and on its own will never be simple to use for nontrivial applications (see Is WebSocket Chat Simpler?).

8. Other
 - Cometd ( http://cometd.org/ )
  : implement responsive user interactions for web clients using AJAX and WebSocket by means of WebSocket and server-push techniques called Comet.

댓글

이 블로그의 인기 게시물

JTDS&Mabatis 에서 MSSQL NVARCHAR 처리

"구글이 목표를 달성하는 방식 OKR" - 독서 후기

Lecture 2 "Supervised Learning Setup Continued" -Cornell CS4780 SP17