Supporting ICEpush on GAE is fundamentally difficult and may require changes to GAE. consider the following Servlet. The expected behavior is that an initial request to the URL should block and then be unblocked by the next request. Each successive request should unblock the previous one.
package org.icepush;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletConfig;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.io.Writer;
import java.util.Collections;
import net.sf.jsr107cache.Cache;
import net.sf.jsr107cache.CacheException;
import net.sf.jsr107cache.CacheFactory;
import net.sf.jsr107cache.CacheManager;
import net.sf.jsr107cache.CacheListener;
public class BlockingServlet extends HttpServlet implements CacheListener {
private ServletContext context;
private Object kicker = new Object();
private static Cache cache;
private static String CACHE_KICK = "cachekick";
public void init(ServletConfig servletConfig) throws ServletException
{
super.init(servletConfig);
context = servletConfig.getServletContext();
initCache();
}
public void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException {
Writer out = servletResponse.getWriter();
cache.put(CACHE_KICK, CACHE_KICK);
long startMillis = System.currentTimeMillis();
synchronized (kicker) {
kicker.notifyAll();
try
{
kicker.wait(10000);
}
catch (Exception e)
{
out.write(e.toString());
}
}
out.write("hello, you waited " + (System.currentTimeMillis() - startMillis) + " on " +kicker +"\n");
}
public void initCache() {
try {
if (null == cache)
{
System.out.println("initializing memcache");
cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
}
} catch (CacheException e)
{
System.out.println(e);
}
cache.addListener(this);
}
public void onLoad(Object key)
{
System.out.println("cache onLoad " + key);
}
public void onPut(Object key){
System.out.println("should be kicking from cache onPut " + key);
// synchronized (kicker)
{
// kicker.notifyAll();
// }
}
public void onEvict(Object key)
{
System.out.println("cache onEvict " + key);
}
public void onRemove(Object key)
{
System.out.println("cache onRemove " + key);
}
public void onClear()
{
System.out.println("cache clear");
}
}
Supporting ICEpush on GAE is fundamentally difficult and may require changes to GAE. consider the following Servlet. The expected behavior is that an initial request to the URL should block and then be unblocked by the next request. Each successive request should unblock the previous one.
package org.icepush;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletConfig;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.io.Writer;
import java.util.Collections;
import net.sf.jsr107cache.Cache;
import net.sf.jsr107cache.CacheException;
import net.sf.jsr107cache.CacheFactory;
import net.sf.jsr107cache.CacheManager;
import net.sf.jsr107cache.CacheListener;
public class BlockingServlet extends HttpServlet implements CacheListener {
private ServletContext context;
private Object kicker = new Object();
private static Cache cache;
private static String CACHE_KICK = "cachekick";
public void init(ServletConfig servletConfig) throws ServletException
{ super.init(servletConfig); context = servletConfig.getServletContext(); initCache(); }public void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException {
{ kicker.wait(10000); }Writer out = servletResponse.getWriter();
cache.put(CACHE_KICK, CACHE_KICK);
long startMillis = System.currentTimeMillis();
synchronized (kicker) {
kicker.notifyAll();
try
catch (Exception e)
{ out.write(e.toString()); }}
out.write("hello, you waited " + (System.currentTimeMillis() - startMillis) + " on " +kicker +"\n");
}
public void initCache() {
try {
{ System.out.println("initializing memcache"); cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap()); }if (null == cache)
} catch (CacheException e)
{ System.out.println(e); }cache.addListener(this);
}
public void onLoad(Object key)
{ System.out.println("cache onLoad " + key); }public void onPut(Object key){
{ // kicker.notifyAll(); // }System.out.println("should be kicking from cache onPut " + key);
// synchronized (kicker)
}
public void onEvict(Object key)
{ System.out.println("cache onEvict " + key); }public void onRemove(Object key)
{ System.out.println("cache onRemove " + key); }public void onClear()
{ System.out.println("cache clear"); }}