org.glassfish.grizzly.web.container.http11
Class GrizzlyAdapterChain

java.lang.Object
  extended by org.glassfish.grizzly.web.container.StaticResourcesAdapter
      extended by org.glassfish.grizzly.web.container.http11.GrizzlyAdapter
          extended by org.glassfish.grizzly.web.container.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 (org.glassfish.grizzly.web.container.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 MAPPED_ADAPTER
           
protected static int MAPPING_DATA
           
 
Fields inherited from class org.glassfish.grizzly.web.container.http11.GrizzlyAdapter
ADAPTER_NOTES, ALLOW_BACKSLASH, chunkingDisabled
 
Fields inherited from class org.glassfish.grizzly.web.container.StaticResourcesAdapter
cache, commitErrorResponse, logger, resourcesContextPath, rootFolder, webDir
 
Constructor Summary
GrizzlyAdapterChain()
           
 
Method Summary
 void addGrizzlyAdapter(GrizzlyAdapter adapter)
          Deprecated. - uses addGrizzlyAdapter(org.glassfish.grizzly.web.container.http11.GrizzlyAdapter, java.lang.String[])
 void addGrizzlyAdapter(GrizzlyAdapter adapter, String[] mappings)
          Add a GrizzlyAdapter and its assciated array of mapping.
 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 org.glassfish.grizzly.web.container.http11.GrizzlyAdapter
afterService, afterService, isAllowEncodedSlash, isHandleStaticResources, service, setAllowEncodedSlash, setDecodeUrl, setHandleStaticResources
 
Methods inherited from class org.glassfish.grizzly.web.container.StaticResourcesAdapter
customizedErrorPage, getResourcesContextPath, getRootFolder, initWebDir, isUseSendFile, service, 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
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)
Map the GrizzlyRequest to the proper GrizzlyAdapter

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

addGrizzlyAdapter

public void addGrizzlyAdapter(GrizzlyAdapter adapter)
Deprecated. - uses addGrizzlyAdapter(org.glassfish.grizzly.web.container.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 © 2009 SUN Microsystems. All Rights Reserved.