com.appenginefan.toolkit.common
Class WebConnectionServer

java.lang.Object
  extended by com.appenginefan.toolkit.common.WebConnectionServer

public class WebConnectionServer
extends Object

Manages the peristence of server-side endpoints for a WebConnectionClient, and the execution of incoming requests.

Author:
Jens Scheffler

Nested Class Summary
static interface WebConnectionServer.Receiver
          Represents the receiving end of a communication
static interface WebConnectionServer.ServerGuts
          Represents the inner works of a server.
 
Constructor Summary
WebConnectionServer(WebConnectionServer.ServerGuts server)
          Constructor
 
Method Summary
 boolean dispatch(WebConnectionServer.Receiver receiver, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Dispatches an incoming request.
 ServerEndpoint fromHandle(javax.servlet.http.HttpServletRequest request, String handle)
          Loads a ServerEndpoint object from a given handle.
static WebConnectionServer fromPeristence(Persistence<byte[]> persistence)
          Factory-method; creates a server based on a binary store
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebConnectionServer

public WebConnectionServer(WebConnectionServer.ServerGuts server)
Constructor

Parameters:
server - the server guts being wrapped. Must not be null.
Method Detail

fromPeristence

public static WebConnectionServer fromPeristence(Persistence<byte[]> persistence)
Factory-method; creates a server based on a binary store

Parameters:
persistence - the storage algorithm for binary data
Returns:
a fully configured server

dispatch

public final boolean dispatch(WebConnectionServer.Receiver receiver,
                              javax.servlet.http.HttpServletRequest req,
                              javax.servlet.http.HttpServletResponse resp)
                       throws IOException
Dispatches an incoming request. This method can be called from a servlet that wraps this object.

Returns:
true if the incoming body was valid and the message has been processed
Throws:
IOException

fromHandle

public ServerEndpoint fromHandle(javax.servlet.http.HttpServletRequest request,
                                 String handle)
Loads a ServerEndpoint object from a given handle. The ServerEndpoint object is usually less "complete" than an object constructed from a request, since it does not contain the state stored in the http client, but it is sufficient to perform certain manipulations, like enqueuing outgoing messages.

Parameters:
handle - the handle that should be used for constructing the object
Returns:
a ServerEndpoint object, or null if the handle is invalid