com.faunos.util.net.http
Class ResponseFactorySwitch

java.lang.Object
  extended by com.faunos.util.net.http.ResponseFactorySwitch
All Implemented Interfaces:
ResponseFactory, ResponseFactoryConfig

public class ResponseFactorySwitch
extends Object
implements ResponseFactory, ResponseFactoryConfig

A thread-safe, ResponseFactory configuration utility.

Concurrency Characteristics

The implementation has well defined behavior under multiple readers concurrent with a single updating thread. If updating threads number more than one, however, while the internal data model itself is [designed to be] never violated, some updates (i.e. mappings) may be missed. So the rule of thumb here is update mappings only from a single thread.

Author:
Babak Farhang
See Also:
ResponseFactoryConfig

Constructor Summary
ResponseFactorySwitch()
           
 
Method Summary
 ResponseFactory addMapping(String path, ResponseFactory factory)
          Adds the given URI path-to-factory mapping to the current mappings and returns the previous mapped factory, if any.
 void addMappings(Map<String,ResponseFactory> mappings)
          Adds the given URI path-to-factory mappings to the current mappings.
 ResponseFactory getMapping(String path)
          Returns the ResponseFactory mapped to the specified path, or null, if nothing is mapped to that path.
 SortedMap<String,ResponseFactory> getMappings()
          Returns a read-only snapshot of the current path-to-factory mappings.
 Stagelet getResponse(RequestHeader request, StageletStack stack, boolean asynchHint)
          Returns a response stagelet for the given request.
 ResponseFactory removeMapping(String path)
          Removes the mapping for specified path and returns the old mapped ResponseFactory, if any; null otherwise.
 void setMappings(Map<String,ResponseFactory> mappings)
          Sets the URI path-to-factory mappings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResponseFactorySwitch

public ResponseFactorySwitch()
Method Detail

getResponse

public Stagelet getResponse(RequestHeader request,
                            StageletStack stack,
                            boolean asynchHint)
Description copied from interface: ResponseFactory
Returns a response stagelet for the given request. At minimum, the implementation returns a header stage that writes out the HTTP response headers. More typically, the returned stagelet will itself be only responsible for writing the response content; for the HTTP response headers, it will first push a ResponseHeaderStage on the given stack. (Per the stagelet contract, it must wait to push this header stage after its init method is invoked.

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()

setMappings

public void setMappings(Map<String,ResponseFactory> mappings)
Description copied from interface: ResponseFactoryConfig
Sets the URI path-to-factory mappings.

Specified by:
setMappings in interface ResponseFactoryConfig

addMappings

public void addMappings(Map<String,ResponseFactory> mappings)
Description copied from interface: ResponseFactoryConfig
Adds the given URI path-to-factory mappings to the current mappings.

Specified by:
addMappings in interface ResponseFactoryConfig

addMapping

public ResponseFactory addMapping(String path,
                                  ResponseFactory factory)
Description copied from interface: ResponseFactoryConfig
Adds the given URI path-to-factory mapping to the current mappings and returns the previous mapped factory, if any.

Specified by:
addMapping in interface ResponseFactoryConfig

removeMapping

public ResponseFactory removeMapping(String path)
Description copied from interface: ResponseFactoryConfig
Removes the mapping for specified path and returns the old mapped ResponseFactory, if any; null otherwise. To atomically remove multiple mappings, use ResponseFactoryConfig.getMappings() in combination with ResponseFactoryConfig.setMappings(Map).

Specified by:
removeMapping in interface ResponseFactoryConfig

getMapping

public ResponseFactory getMapping(String path)
Description copied from interface: ResponseFactoryConfig
Returns the ResponseFactory mapped to the specified path, or null, if nothing is mapped to that path.

Specified by:
getMapping in interface ResponseFactoryConfig

getMappings

public SortedMap<String,ResponseFactory> getMappings()
Description copied from interface: ResponseFactoryConfig
Returns a read-only snapshot of the current path-to-factory mappings.

Specified by:
getMappings in interface ResponseFactoryConfig


SourceForge.net Logo