users@grizzly.java.net

(proxy) close connection technique

From: Kawajiri Takeshi <taken.kz_at_gmail.com>
Date: Mon, 17 Nov 2008 22:29:39 +0900

Hello.
After I posted this thread, I tried to use other reverse proxy.
https://glassfish.dev.java.net/servlets/BrowseList?list=users&by=thread&from=1187803
and I realize some proxy can tell client's exit to server correctly.

For example.
[PC] -> [GlassFish] Good. onInterrupt is called immediately when
page is closed.
[PC] -> [mod_proxy] -> [GlassFish] NG. onInterrupt is not called.
[PC] -> [nginx] -> [GlassFish] Good. onInterrupt is called immediately.
(I don't try V3's mod_jk yet)

And I realize our auth proxy(I guess it is Squid) don't tell client's
close to server.

For example.
[PC] -> [auth proxy] -> [GlassFish] NG.
[PC] -> [auth proxy] -> [mod_proxy] -> [GlassFish] NG.
[PC] -> [auth proxy] -> [nginx] -> [GlassFish] NG.

Finally, I gave up. because I don't have permission to configure it.
So, I've changed my approch.
If server cannot detect connection-close, client should notify it :):):)

Here is javascript-code(prototype.js)
which will post handlerId when page closed.

Event.observe(window, 'unload', function(){
  new Ajax.Request("your_comet_path", {
     method: 'post',
     parameters: your_handler_id //TODO: resume the handler at server
  });
});

This code have some problem.
1) Browser sometimes exit before finishing unload-event.
2) this is ugly ;)

But I believe it is a best way.
If you will publish comet application (There may be a "lazly proxy")
and you have to call onInterrupt immediately,
remember this post.

Thanks!