com.faunos.util.net.http
Class AbstractResponseFactory

java.lang.Object
  extended by com.faunos.util.net.http.AbstractResponseFactory
All Implemented Interfaces:
ResponseFactory
Direct Known Subclasses:
FileResponseFactory, SkwishResponseFactory

public abstract class AbstractResponseFactory
extends Object
implements ResponseFactory

A skeletal implementation of a ResponseFactory that honors the server's asynchHint. Instead of implementing ResponseFactory.getResponse(RequestHeader, StageletStack, boolean), a subclass implements prepareResponseImpl(RequestHeader, StageletStack): asynchronous processing hints (i.e. when the asynchHint parameter in a getResponse invocation is true) are automatically handled by returning a AsynchStagelet that asynchronously calls prepareResponseImpl on init.

Author:
Babak Farhang
See Also:
prepareResponseImpl(RequestHeader, StageletStack)

Constructor Summary
AbstractResponseFactory()
           
 
Method Summary
protected  Stagelet badRequest(RequestHeader request, StageletStack stack)
           
 Stagelet getResponse(RequestHeader request, StageletStack stack, boolean asynchHint)
          Returns the implementation-specific stagelet.
protected  Stagelet notFound(RequestHeader request, StageletStack stack)
           
protected abstract  Stagelet prepareResponseImpl(RequestHeader request, StageletStack stack)
          Returns the factory-specific (i.e.
protected  String urlDecode(String value)
          URL-decodes and returns the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractResponseFactory

public AbstractResponseFactory()
Method Detail

getResponse

public Stagelet getResponse(RequestHeader request,
                            StageletStack stack,
                            boolean asynchHint)
Returns the implementation-specific stagelet. If asynch is false, then prepareResponseImpl(RequestHeader, StageletStack) is returned immediately; o.w., an AsynchStagelet that'll later invoke prepareResponseImpl(RequestHeader, StageletStack) is returned.

Specified by:
getResponse in interface ResponseFactory
stack - if the returned stagelet is itself stack-aware, then it will push additional stagelets (e.g. the header response stage) onto the given stack. The rules for when and how stagelets can be pushed on the stack are described in the Stagelet interface.
asynchHint - if true, then the response stagelet should try to process non-network I/O based tasks asynchronously.
See Also:
Stagelet, HandletContext.processAsynch()

prepareResponseImpl

protected abstract Stagelet prepareResponseImpl(RequestHeader request,
                                                StageletStack stack)
Returns the factory-specific (i.e. app-specific) stagelet. The returned instance will not be in the PROCESSING state.


notFound

protected Stagelet notFound(RequestHeader request,
                            StageletStack stack)

badRequest

protected Stagelet badRequest(RequestHeader request,
                              StageletStack stack)

urlDecode

protected final String urlDecode(String value)
URL-decodes and returns the given value. If value is null, then null is returned.



SourceForge.net Logo