0

problem with Execution.activate(Desktop)

asked 2009-04-23 20:07:35 +0800

issamlaabidi gravatar image issamlaabidi
217 2

updated 2009-04-24 08:03:45 +0800

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.

delete flag offensive retag edit

12 Replies

Sort by ยป oldest newest

answered 2009-04-24 02:06:29 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Hi,

Please glance the source from this demo.

/Jumper

link publish delete flag offensive edit

answered 2009-04-24 08:06:45 +0800

issamlaabidi gravatar image issamlaabidi
217 2

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

link publish delete flag offensive edit

answered 2009-04-24 08:53:35 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

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

link publish delete flag offensive edit

answered 2009-04-24 10:15:36 +0800

issamlaabidi gravatar image issamlaabidi
217 2

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.

link publish delete flag offensive edit

answered 2009-04-24 10:55:51 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

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

link publish delete flag offensive edit

answered 2009-04-24 15:20:45 +0800

issamlaabidi gravatar image issamlaabidi
217 2

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.

link publish delete flag offensive edit

answered 2009-04-27 02:14:32 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

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

link publish delete flag offensive edit

answered 2009-04-27 12:58:15 +0800

issamlaabidi gravatar image issamlaabidi
217 2

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.

link publish delete flag offensive edit

answered 2009-04-28 03:50:39 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

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

link publish delete flag offensive edit

answered 2009-04-28 08:14:18 +0800

issamlaabidi gravatar image issamlaabidi
217 2

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

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-04-23 20:07:35 +0800

Seen: 815 times

Last updated: Apr 29 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More