com.sun.grizzly.tcp.http11
Class GrizzlyAdapterChain
java.lang.Object
com.sun.grizzly.tcp.StaticResourcesAdapter
com.sun.grizzly.tcp.http11.GrizzlyAdapter
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
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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
GrizzlyAdapterChain
public GrizzlyAdapterChain()
service
public void service(GrizzlyRequest request,
GrizzlyResponse response)
- Map the
GrizzlyRequest to the proper GrizzlyAdapter
- Specified by:
service in class GrizzlyAdapter
- Parameters:
request - The GrizzlyRequestresponse - The GrizzlyResponse
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 instancemappings - 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 © 2008 SUN Microsystems. All Rights Reserved.