users@grizzly.java.net

unregister context

From: Kawajiri Takeshi <taken.kz_at_gmail.com>
Date: Tue, 21 Oct 2008 18:48:02 +0900

Hello.

I'm using glassfish-v3-prelude-b28(Grizzly-Comet-1.8.6.1, NetBeans6.5
Dev 200810041417)

My application have to use multi comet-contexts in a servlet.
and I want to unregister it when the context has no handlers.

So I wrote CometHandler like this.
--------------------------------------------------------------------
    public void onInterrupt(CometEvent event) throws IOException {

      CometContext context = event.getCometContext();

      if (context.getCometHandlers().size() == 1) {
        CometEngine.getEngine().unregister(topic);
      } else {
        context.removeCometHandler(this);
      }

    }
--------------------------------------------------------------------

But when CometEngine#unregister is called,
all handler(Response) is closed regardless of attaching context.

and a exception occoured

--------------------------------------------------------------------
CometSelector
java.lang.IllegalStateException: cometTask cannot be null
        at com.sun.grizzly.comet.CometEngine.interrupt(CometEngine.java:465)
        at com.sun.grizzly.comet.CometSelector.cancelKey(CometSelector.java:273)
        at com.sun.grizzly.comet.CometTask.doTask(CometTask.java:286)
        at com.sun.grizzly.http.TaskBase.call(TaskBase.java:359)
        at com.sun.grizzly.util.WorkerThreadImpl.processTask(WorkerThreadImpl.java:325)
        at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:184)
--------------------------------------------------------------------

If I comment out CometEngine#unregister, these don't happen.


My questions are

(1) Can I use multi contexts?
(2) How to unregister context without effect to other contexts ?

Thanks ahead of time !