users@grizzly.java.net

CanregisterAsyncWrite

From: Richard Zschech <richard_at_zschech.net>
Date: Sun, 21 Jun 2009 06:46:54 -0700 (PDT)

public class GrizzlyServlet extends HttpServlet {
        
        private CometContext cometContext;
        
        public void init(ServletConfig config) throws ServletException {
                String topic = config.getServletContext().getContextPath();
                CometEngine cometEngine = CometEngine.getEngine();
                cometContext = cometEngine.register(topic);
                cometContext.setExpirationDelay(-1);
        }
        
        protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
                CometHandlerImpl handler = new CometHandlerImpl();
                handler.attach(response);
                cometContext.addCometHandler(handler);
                cometContext.registerAsyncWrite(handler);
        }
        
        private class CometHandlerImpl implements CometHandler<HttpServletResponse>
{
                private HttpServletResponse response;
                
                public void attach(HttpServletResponse response) {
                        this.response = response;
                }
                
                public void onInitialize(CometEvent event) throws IOException {
                        System.out.println("onInitialize");
                }
                
                public void onInterrupt(CometEvent event) throws IOException {
                        System.out.println("onInterrupt");
                }
                
                public void onTerminate(CometEvent event) throws IOException {
                        System.out.println("onTerminate");
                }
                
                public void onEvent(CometEvent event) throws IOException {
                        System.out.println("onEvent" + event);
                }
        }
}

-- 
View this message in context: http://www.nabble.com/CanregisterAsyncWrite-tp24134468p24134468.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.