-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Please i am working on comet in which i push data to client. so every time i want to add data on the desktop i must do Executions.activat(desktop) but whene the client close his browser this execution is not executed and it makes for me many problems how can i do to know if the desktop is available.
it is ok but Executions.activate(desktop) is not working whene a desktop is closed. any solutions to detect the closed desktop so that i disable the server push. beause if not thi server push still running in tomcat
Hi,
Didn't you see the tips from the run() method of org.zkoss.zkdemo.userguide.CometServerPush implementation as follows?
if (_info.getDesktop() == null
/Jumper
i am sorry i am working on rough, professional project, so every time i test on the desktop!=null and desktop.isAlive(), but whene the client close his browser it still indicates that the desktop is not null nd it is alive but Executions.activate(desktop) is not working....even i have done a session listener but it does not work fine.
As our demo, we used the try-catch to ignore the error when user close the browser, because some of the modern browser won't fire an event when the browser is closed.
/Jumper
here you are my code:
AlertServerPush service = AlertServerPush.lookup(employerId);
Vector<Caption> captions = (Vector<Caption>) AlertServerPush.actifCaptions.get(employerId);
// all clients listBoxs in order to update them
Vector<Listbox> listBoxs = (Vector<Listbox>) AlertServerPush.actifListBox.get(employerId);
int size = captions.size();
if(listBoxs != null && listBoxs.size()>0 && captions != null && captions.size()>0){
for(int i =0; i<size; i++){
Listbox listbox = listBoxs.get(i);
Caption caption = captions.get(i);
Desktop desktop = caption.getDesktop();
if(desktop != null && desktop.isAlive()){
if(!desktop.isServerPushEnabled())
desktop.enableServerPush(true);
try {
Executions.activate(desktop);
try {
int number = service.getAlertNumber();
if(number == 0 || number<0){
caption.setLabel( "Alert Messages");
caption.setImage("");
}else{
caption.setLabel( number + " Alert Messages");
caption.setImage("/images/alert2.gif");
}
} finally {
Executions.deactivate(desktop);
}
}
catch (DesktopUnavailableException e) {
// captions.remove(caption);
logger.error("run() Desktop not avalaible" + e.toString() + " " + e.getMessage());
}
catch (InterruptedException e) {
logger.error("run() Server push thread interrupted " + e.toString() + " " + e.getMessage());
}
}
now i want to inform you that when the browser is closed my program stop in Executions.activate(desktop); and it did not go to catch. know i have tried to work with timer in odrer to check desktop availability but i have noticed also that when the browser is closed the timer stop working?? so hard this please help.
Please i am working in a real project i need your help.
Hi,
The following example works for me.
public void run() { try { while (true) { if (_info.getDesktop() == null || !_desktop.isServerPushEnabled()) { _desktop.enableServerPush(false); return; } Executions.activate(_desktop); try { ((Image) _info).setContent(paint()); } finally { Executions.deactivate(_desktop); } Threads.sleep(1000); } } catch (DesktopUnavailableException ex) { System.out.println("The server push thread interrupted"); } catch (InterruptedException e) { System.out.println("The server push thread interrupted"); } }
/Jumper
did you test it whene you close your browser. try to put a logger just before Executions.activate(_desktop); and just after it. whene you test in the case of closed browser you will notice that the thread is blocked in this line Executions.activate(_desktop);
that is my problem.
Yes, I tested the case you mentioned. The question is when user closes the browser, the remove desktop command doesn't be sent from client to server, then, these threads will be removed until the session is time out.
/Jumper
Ok that is good know i want to inform you that the server push prevent session time out so i can confirm that it is a problem. Thanks for your help
Asked: 2009-04-23 20:07:35 +0800
Seen: 815 times
Last updated: Apr 29 '09