package com.googlecode.objectify.cache;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * <p>This Filter is a companion to the CachingAsyncDatastoreService, and must be
 * installed any time the CachingAsyncDatastoreService is used.</p>
 * 
 * <p>This Filter is a temporary measure until Google provides a hook that lets
 * us intercept the raw Future<?> calls at the end of a request.  At that point
 * this filter can be eliminated in favor of the hook.</p>
 * 
 * @author Jeff Schnitzer <jeff@infohazard.org>
 */
public class AsyncCacheFilter implements Filter
{
	@Override
	public void init(FilterConfig config) throws ServletException
	{
	}

	@Override
	public void destroy()
	{
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
	{
		try
		{
			chain.doFilter(request, response);
		}
		finally
		{
			ListenableHook.completeAllPendingFutures();
		}
	}
}

@@ -446,19 +446,18 @@
 %3C/p%3E%0D%0A *
- 
 %0D%0A
+
  * %3Cp%3ETh
@@ -672,17 +672,594 @@
 %3C/p%3E%0D%0A *
- 
+%0D%0A * In your web.xml:%0D%0A *%3Cpre%3E%0D%0A *       &lt;filter&gt;%0D%0A *              &lt;filter-name&gt;AsyncCacheFilter&lt;/filter-name&gt;%0D%0A *              &lt;filter-class&gt;com.googlecode.objectify.cache.AsyncCacheFilter&lt;/filter-class&gt;%0D%0A *      &lt;/filter&gt;%0D%0A *      &lt;filter-mapping&gt;%0D%0A *              &lt;filter-name&gt;AsyncCacheFilter&lt;/filter-name&gt;%0D%0A *              &lt;url-pattern&gt;/*&lt;/url-pattern&gt;%0D%0A *      &lt;/filter-mapping&gt;%0D%0A *%3C/pre%3E%0D%0A *%0D%0A * Or, if you use Guice:%0D%0A *%0D%0A *%3Cpre%3E%0D%0A *      filter(%22/*%22).through(AsyncCacheFilter.class);%0D%0A *%3C/pre%3E%0D%0A *
 %0D%0A * @au

add documentation about configuration in the web.xml