GWT multi-tab / multiple CometSessions per sessions workaround

460 views
Skip to first unread message

Kixx

unread,
Jul 28, 2011, 2:35:35 AM7/28/11
to gwt-comet, ric...@zschech.net
Since there is only suggestion threads about this problem's workaround
and general ideas, i propose to create a fully functional workaround
for the multiple sessions issue, so any new users that might be having
problems with it can read up and make it happen.

So, in earlier threads it has been stated that working with 2
connections from the same sessions can wreak havoc on the internal
implementation of CometSession, like <a href="http://groups.google.com/
group/gwt-comet/browse_thread/thread/4af677f6da363324">Here</a> 2
types of workarounds were implemented.

Icky's suggestion that sounds good
"1) I don't use comet session, I use cometResponse explicitly.
2) Each new browser tab/window is allocated an ID.
3) When connect to CometServlet I save their cometResponse against
that ID
4) When they subscribe/unsusbcribe, I store all subscriptions against
the ID
5) Then when server need to push, it retrieves the saved
cometResponse
associated with the ID and queue messages to it. "

but i failed to make it work since the server wasn't holding on to any
connections and closed them immediately after doing doComet(...) by
sending an error of type "Unexpected Disconnection". So i might be
doing something wrong and i hope someone will correct me if im doing
something wrong

<code>
@Override
protected void doComet(CometServletResponse cometResponse) throws
ServletException, IOException {
System.out.println("Connection Req");
HttpServletRequest request = cometResponse.getRequest();
String cometClientId = request.getParameter("id");
String requestSessionId = request.getSession(true).getId();
StreamingEventHandler.registerListener(cometResponse);
CometServletResponseImpl resp = (CometServletResponseImpl)
cometResponse;
//cometResponse.getSession();
}
</code>

Whereas if i uncomment the last row it works, but by creating a
session witch in return disables multiple instances of tabs.

Other method was mentioned by the owner of this project (Richard)

"A simple possibility would be to change
CometServlet.getCometSession(...) to take the HttpServletRequest
which
you could add a "new connection" parameter too. When the "new
connection" parameter is set then rather than looking up the
CometSession from the HttpSession basked on
CometSession.HTTP_SESSION_KEY you could generate a connection id and
do the HttpSession mapping based on that. You could then return the
connection id back to the client which could use it for subsequent
requests."

This part confuses me a little bit, we need to alter the project to
inject additional parameters into CometSession... I think i have an
idea what you mean but it doesn't hurt to clarify a little bit. So we
will have to change CometSessionImplementation aswell since that
creates the session? Or CometResponseImpl ?

Any help is greatly appreciated, by me and anyone who needs to
overcome this problem.

If we make this work, i would be happy to change the chat application
to work with multiple tabs as an example as well as a token of my
gratitude...

Let's make this happen!

Icky

unread,
Jul 28, 2011, 3:31:39 AM7/28/11
to gwt-comet
Hi Stefan,

Thanks for making this thread, I'll take a look and see what the
differences are.. it looks really similar to what i've done...

I have a really silly question though, when you do:
CometServletResponseImpl resp = (CometServletResponseImpl)
cometResponse;
is it possible that the resp gets garbage collected?

Could you try to save the resp + id in a map or something and see what
happens?

Kixx

unread,
Jul 28, 2011, 3:54:37 AM7/28/11
to gwt-comet
Dear Icky,

<code>
public Map<String,CometServletResponse> map = new
HashMap<String,CometServletResponse >();

@Override
protected void doComet(CometServletResponse cometResponse) throws
ServletException, IOException {
System.out.println("Connection Req");
HttpServletRequest request = cometResponse.getRequest();
String cometClientId = request.getParameter("id");
//String requestSessionId = request.getSession(true).getId();
map.put(cometClientId, cometResponse);
//StreamingEventHandler.registerListener(cometResponse);
//cometResponse.getSession();
}
</code>
Even though i put cometResponse in a map with
StreamingEventHandler.registerListener(cr) i thought maybe it was
having a problem

The thing is that CometServletResponse is saved in a map, but to no
avail... I dont know, maybe the client side is messed up?
<listener code>
...

@Override
public void onError(Throwable exception, boolean connected) {
//comm.stopListening();
comm.sendString("Client Error Connected "+connected+" Message "
+exception.getLocalizedMessage());
}

@Override
public void onHeartbeat() {
comm.sendString("Client Heartbeat");
}

@Override
public void onRefresh()...

@Override
public void onMessage(List<? extends Serializable> messages)...
</listener code>

Since debuging GWT while running on Glassfish is hard i used message
sending to server witch prints them out,

it currently terminates the session as in sends a error and terminates
the connection soon after client requests a doComet
trace:
INFO: Connection Req
INFO: Client> Client Error Connected false Message EventSource error

Now that i look at it, first time i saw EventSource error, ill look
into that

Whereas i downloaded the full source of gwt-comet and planning to
implement that method that Richard mentioned.

Will be writing here soon!
Message has been deleted

Kixx

unread,
Jul 28, 2011, 5:44:52 AM7/28/11
to gwt-comet
Dear All,

I have managed to make a JAR file that supports multiple instances in
the same session.

New method implemented is cometResponse.getSession(boolean true,String
sessionID) that can be used to track multiple instances over the same
session. It supports all the methods from the previous versions.

If anyone needs the jar i can send it to him via email because i don't
know otherwise.

Cheers

Emil Daoura

unread,
Oct 11, 2012, 10:38:47 AM10/11/12
to gwt-...@googlegroups.com
Hi Stefan,

I have the same Problem.

I don't know how to use the cometResponse. I am new in GWT.

Please can you send me an example?
I have read that the CometServletResponse is terminated and refreshed occasionally so you can't directly send messages to the client while this is happening so you will have to pause the processing of the JMS messages. Otherwise the CometSession handles message queueing across these refreshes for you but requires a HTTP session to be established.

It seems to be complicated using the cometResponse. how did you resolve this problem?
Please send me an example of how do I change the library to let it works.

Thanks
best regards
Emil
Message has been deleted

Stefan Martinov

unread,
Oct 24, 2012, 6:41:31 AM10/24/12
to gwt-...@googlegroups.com
Forwarded the whole conversation of how to implement it, and the jar file!

 


---------- Forwarded message ----------
From: Stefan Martinov <stefanm...@gmail.com>
Date: Thu, Jul 28, 2011 at 12:33 PM
Subject: Re: [gwt-comet] Re: GWT multi-tab / multiple CometSessions per sessions workaround
To: Mats Persson <ma...@eldea.se>


Hello,

you just need something to identify the special session with. Something unique you can later reference from the CometServletRequest. I for instance used when connecting with client to add a request parameter like ID so i can do
(connection url looks like this YourModlue/comet?id=123

cometRequest.getRequest().getParameter("id");

I've tested it on google chrome and firefox.

On Thu, Jul 28, 2011 at 11:50 AM, Mats Persson <ma...@eldea.se> wrote:
Hello Stefan, 
I'd really like to check out your solution! If you can send me the jar I'd be greatful

Mats



2011/7/28 Kixx <stefanm...@gmail.com>




-- 
Pozdrav,
Stefan Martinov




-- 
Pozdrav/ Greetings/ Gruß,
Stefan Martinov




-- 
Pozdrav/ Greetings/ Gruß,
Stefan Martinov

kwai...@gmail.com

unread,
Oct 25, 2012, 9:37:34 PM10/25/12
to gwt-...@googlegroups.com, ric...@zschech.net
Dear Kixx, 
 
I'm facing the same problem as you describe at your post. Would you please kindly send me the modified jar and the working samples to my email?
Really appreciated! :-)

Thank you!

Br
Karen

Kixx於 2011年7月28日星期四UTC+8下午2時35分35秒寫道:

iye...@gmail.com

unread,
Jun 21, 2013, 11:48:50 PM6/21/13
to gwt-...@googlegroups.com
Hi Stefan,
 Am interested in your solution for this. Am currently using the gwt-comet version for GWT 2.5.0. Is it possible to get the jar and any samples to my email. Hugely appreciate your help.

kamda...@gmail.com

unread,
Nov 18, 2013, 10:44:37 AM11/18/13
to gwt-...@googlegroups.com, ric...@zschech.net
Please i also need your solution. will be very greatfull

cataclysm...@gmail.com

unread,
Jun 18, 2014, 7:13:28 AM6/18/14
to gwt-...@googlegroups.com
Sir ! I also need your modified jar. Please email me sir. I would really appreciate. I am waiting your nicefully jar.

Regardless. cataclysm...@gmail.com

bbuild...@gmail.com

unread,
Sep 5, 2014, 4:17:17 PM9/5/14
to gwt-...@googlegroups.com
I would be very interested in a copy of the jar that supports multipe sessions.  How can I get it?
Reply all
Reply to author
Forward
0 new messages