Salut,
Richard Zschech wrote:
> I have a test servlet below. I can't seem to get any comet events for async
> writes to be generated. I'm guessing I'm missing a step but I can't work it
> out based on the documentation. Any help would be appreciated.
Can you send me the exact test you are doing? You need to do something
like that once you have registered:
> 32 if (event.getType() == CometEvent.WRITE){
> 33 CometWriter sc = (CometWriter)event.attachment();
> 34 int nWrite = sc.write("success".getBytes());
> 35 if (nWrite != 7){
> 36 cometContext.registerAsyncWrite(this);
> 37 } else {
> 38 event.getCometContext().resumeCometHandler(this);
> 39 }
> 40 }
This is a really stupid example but just wanted to share :-). Above if
the expected number of bytes weren't all written, then we register for
async write events and the Comet Framework will invoke onEvent(...) as
soon as write operation are permitted.
A+
-- Jeanfrancois
>
> 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);
> }
> }
> }
>