com.sun.grizzly.tcp.http11
Class GrizzlyAdapterChain

java.lang.Object
  extended by com.sun.grizzly.tcp.StaticResourcesAdapter
      extended by com.sun.grizzly.tcp.http11.GrizzlyAdapter
          extended by com.sun.grizzly.tcp.http11.GrizzlyAdapterChain
All Implemented Interfaces:
Adapter

public class GrizzlyAdapterChain
extends GrizzlyAdapter

The GrizzlyAdapterChain class allow the invokation of multiple GrizzlyAdapter every time a new HTTP requests is ready to be handled. Requests are mapped to their associated GrizzlyAdapter at runtime using the mapping information configured when invoking the GrizzlyAdapterChain#addGrizzlyAdapter (com.sun.grizzly.tcp.http11.GrizzlyAdapter, java.lang.String[]) Below is a simple example using two {@link Servlet}



GrizzlyWebServer ws = new GrizzlyWebServer(path);
ServletAdapter sa = new ServletAdapter();
sa.setRootFolder(".");
sa.setServletInstance(new ServletTest("Adapter-1"));
ws.addGrizzlyAdapter(sa, new String[]{"/Adapter-1"});
ServletAdapter sa2 = new ServletAdapter();
sa2.setRootFolder("/tmp");
sa2.setServletInstance(new ServletTest("Adapter-2"));
ws.addGrizzlyAdapter(sa2, new String[]{"/Adapter-2"});
System.out.println("Grizzly WebServer listening on port 8080");
ws.start();
 
 
Note: This class is NOT thread-safe, so make sure you synchronize when dynamically adding and removing {@link GrizzlyAdapter}

Author:
Jeanfrancois Arcand

Field Summary
protected static int INVOKED_ADAPTER
           
protected static int MAPPED_ADAPTER
           
protected static int MAPPING_DATA
           
 
Fields inherited from class com.sun.grizzly.tcp.http11.GrizzlyAdapter
ADAPTER_NOTES, ALLOW_BACKSLASH, chunkingDisabled
 
Fields inherited from class com.sun.grizzly.tcp.StaticResourcesAdapter
cache, commitErrorResponse, fileFolders, logger, resourcesContextPath
 
Constructor Summary
GrizzlyAdapterChain()
           
 
Method Summary
 void addGrizzlyAdapter(GrizzlyAdapter adapter)
          Deprecated. - uses addGrizzlyAdapter(com.sun.grizzly.tcp.http11.GrizzlyAdapter, java.lang.String[])
 void addGrizzlyAdapter(GrizzlyAdapter adapter, String[] mappings)
          Add a GrizzlyAdapter and its assciated array of mapping.
 void afterService(GrizzlyRequest request, GrizzlyResponse response)
          Once the GrizzlyAdapter.service(com.sun.grizzly.tcp.Request, com.sun.grizzly.tcp.Response) method has been execyuted, the container will call this method to allow any extension to clean up there associated GrizzlyRequest and GrizzlyResponse.
 void destroy()
          Invoked when the GrizzlyWebServer or SelectorThread is stopped or removed.
 boolean removeAdapter(GrizzlyAdapter adapter)
          Remove a GrizzlyAdapter
 void service(GrizzlyRequest request, GrizzlyResponse response)
          Map the GrizzlyRequest to the proper GrizzlyAdapter
 void start()
          Called when the GrizzlyAdapter's container is started by invoking GrizzlyWebServer#start or when .
 
Methods inherited from class com.sun.grizzly.tcp.http11.GrizzlyAdapter
afterService, getName, isAllowEncodedSlash, isDecodeURL, isHandleStaticResources, service, setAllowEncodedSlash, setDecodeUrl, setDispatcherHelper, setHandleStaticResources
 
Methods inherited from class com.sun.grizzly.tcp.StaticResourcesAdapter
addRootFolder, customizedErrorPage, getDefaultContentType, getResourcesContextPath, getRootFolder, getRootFolders, initWebDir, isUseSendFile, service, setDefaultContentType, setLogger, setResourcesContextPath, setRootFolder, setUseSendFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAPPING_DATA

protected static final int MAPPING_DATA
See Also:
Constant Field Values

MAPPED_ADAPTER

protected static final int MAPPED_ADAPTER
See Also:
Constant Field Values

INVOKED_ADAPTER

protected static final int INVOKED_ADAPTER
See Also:
Constant Field Values
Constructor Detail

GrizzlyAdapterChain

public GrizzlyAdapterChain()
Method Detail

start

public void start()
Description copied from class: GrizzlyAdapter
Called when the GrizzlyAdapter's container is started by invoking GrizzlyWebServer#start or when . By default, it does nothing.

Overrides:
start in class GrizzlyAdapter

service

public void service(GrizzlyRequest request,
                    GrizzlyResponse response)
             throws Exception
Map the GrizzlyRequest to the proper GrizzlyAdapter

Specified by:
service in class GrizzlyAdapter
Parameters:
request - The GrizzlyRequest
response - The GrizzlyResponse
Throws:
Exception

afterService

public void afterService(GrizzlyRequest request,
                         GrizzlyResponse response)
                  throws Exception
Description copied from class: GrizzlyAdapter
Once the GrizzlyAdapter.service(com.sun.grizzly.tcp.Request, com.sun.grizzly.tcp.Response) method has been execyuted, the container will call this method to allow any extension to clean up there associated GrizzlyRequest and GrizzlyResponse.

Overrides:
afterService in class GrizzlyAdapter
Parameters:
request - The GrizzlyRequest
response - The GrizzlyResponse
Throws:
Exception

addGrizzlyAdapter

public void addGrizzlyAdapter(GrizzlyAdapter adapter)
Deprecated. - uses addGrizzlyAdapter(com.sun.grizzly.tcp.http11.GrizzlyAdapter, java.lang.String[])

Add a GrizzlyAdapter to the chain.

Parameters:
{@link - GrizzlyAdapter} to the chain.

addGrizzlyAdapter

public void addGrizzlyAdapter(GrizzlyAdapter adapter,
                              String[] mappings)
Add a GrizzlyAdapter and its assciated array of mapping. The mapping data will be used to map incoming request to its associated GrizzlyAdapter.

Parameters:
adapter - GrizzlyAdapter instance
mappings - an array of mapping.

destroy

public void destroy()
Description copied from class: GrizzlyAdapter
Invoked when the GrizzlyWebServer or SelectorThread is stopped or removed. By default, this method does nothing. Just override the method if you need to clean some resource.

Overrides:
destroy in class GrizzlyAdapter

removeAdapter

public boolean removeAdapter(GrizzlyAdapter adapter)
Remove a GrizzlyAdapter

Returns:
true if removed


Copyright © 2013 Oracle Corporation. All Rights Reserved.