Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Job Api
Job Api [message #664861] Tue, 12 April 2011 10:32 Go to next message
Oliver Pfau is currently offline Oliver PfauFriend
Messages: 28
Registered: July 2009
Junior Member
Hi,

I have a background job which updates the UI. This works as expected with RCP. But in RAP the UI background task is scheduled only once.

Here is the code which shall run the job delayed.

if (wholeTreeUpdatejob != null) {
final int jobState = wholeTreeUpdatejob.getState();
if (jobState == Job.SLEEPING) {
wholeTreeUpdatejob.wakeUp();
} else {
wholeTreeUpdatejob.schedule();
wholeTreeUpdatejob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(final IJobChangeEvent event) {
wholeTreeUpdatejob.schedule(WHOLE_DELAY);
}
});
}
}

Any ideas why with RAP the job is only executed once?

Regards
Oliver
Re: Job Api [message #664881 is a reply to message #664861] Tue, 12 April 2011 11:58 Go to previous messageGo to next message
Oliver Pfau is currently offline Oliver PfauFriend
Messages: 28
Registered: July 2009
Junior Member
Figured out that the delayed job is only executed after an user interaction.
Re: Job Api [message #664903 is a reply to message #664861] Tue, 12 April 2011 13:14 Go to previous messageGo to next message
Oliver Pfau is currently offline Oliver PfauFriend
Messages: 28
Registered: July 2009
Junior Member
Fount out that the update thread is executed how expected if I deploy the code as war in tomcat or jetty. Only inside eclipse "Run as RAP application" the update thread is only executed if an user interaction was done (e. g. stepping throught the menues).
Re: Job Api [message #664964 is a reply to message #664861] Tue, 12 April 2011 15:38 Go to previous messageGo to next message
Oliver Pfau is currently offline Oliver PfauFriend
Messages: 28
Registered: July 2009
Junior Member
I think the JobChangeListener is only invoked if a user interaction is done. But not always...strange.
Re: Job Api [message #664968 is a reply to message #664861] Tue, 12 April 2011 15:39 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 335
Registered: July 2009
Senior Member
if you want a Job to be able to update the UI, it has to be started
(schedule()) from the UI thread.
If you (re-)schedule a Job from within a background thread (e.g. in a
Job) you will have to manually activate and deactivate the UICallback.

HTH
Rüdiger

On 12.04.2011 12:32, Oliver Pfau wrote:
> Hi,
>
> I have a background job which updates the UI. This works as expected
> with RCP. But in RAP the UI background task is scheduled only once.
>
> Here is the code which shall run the job delayed.
>
> if (wholeTreeUpdatejob != null) {
> final int jobState = wholeTreeUpdatejob.getState();
> if (jobState == Job.SLEEPING) {
> wholeTreeUpdatejob.wakeUp();
> } else {
> wholeTreeUpdatejob.schedule();
> wholeTreeUpdatejob.addJobChangeListener(new JobChangeAdapter() {
> @Override
> public void done(final IJobChangeEvent event) {
> wholeTreeUpdatejob.schedule(WHOLE_DELAY);
> }
> });
> }
> }
>
> Any ideas why with RAP the job is only executed once?
>
> Regards Oliver
Re: Job Api [message #665110 is a reply to message #664861] Wed, 13 April 2011 10:08 Go to previous messageGo to next message
Oliver Pfau is currently offline Oliver PfauFriend
Messages: 28
Registered: July 2009
Junior Member
Have done this. Now the UI is updated. Unfortunately with RAP the job and the ui thread waiting for another. This leads to a deadlock and tomcat shutdown does no more work. With RCP this does not happen.

Added

display.

display.asyncExec(new Runnable() {

@Override
public void run() {
UICallBack.activate(CALLBACK_ID);
}
});

before schedule() call and

display.asyncExec(new Runnable() {

@Override
public void run() {
UICallBack.deactivate(CALLBACK_ID);
}
});

before end of run() of the job.


Re: Job Api [message #665204 is a reply to message #665110] Wed, 13 April 2011 16:21 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 335
Registered: July 2009
Senior Member
Oliver,

from what I understand is that you _schedule_ the UIBallback calls to be
run from within the UI thread. In order to work, the
UICallback.activate/deactivate call has to be made from an actually
running UI thread.

What the UICallback.active() does is that it establishes a communication
channel from the server to the client. It does so in that it tells the
client within an ordinary request to issue an extra request and then
blocks this very request. Now there is a channel that the server can sue
to inform the client about pending asyncExec runnables.

For the simple cases you don't need to do anything. The JobManager in
RAP activates (and later deactivates) the UICallback if a job is run
from the UI thread.
Since you re-scheduling a job, it's best (if you are able to figure that
out) to activate the UICallback before the job starts and deactivate it
when it is done.

HTH
Rüdiger


On 13.04.2011 12:08, Oliver Pfau wrote:
> Have done this. Now the UI is updated. Unfortunately with RAP the job
> and the ui thread waiting for another. This leads to a deadlock and
> tomcat shutdown does no more work. With RCP this does not happen.
>
> Added
> display.
>
> display.asyncExec(new Runnable() {
>
> @Override
> public void run() {
> UICallBack.activate(CALLBACK_ID);
> }
> });
>
> before schedule() call and
>
> display.asyncExec(new Runnable() {
>
> @Override
> public void run() {
> UICallBack.deactivate(CALLBACK_ID);
> }
> });
>
> before end of run() of the job.
>
>
>
Re: Job Api [message #665284 is a reply to message #664861] Thu, 14 April 2011 06:41 Go to previous message
Oliver Pfau is currently offline Oliver PfauFriend
Messages: 28
Registered: July 2009
Junior Member
Hi Rüdiger,

thanks for your reply. Probably it could help to describe what the application does...it shows something like a fill level in a TreeViewer. Therefore the UI has to be updated periodically. It is a RCP and RAP application. I added hooks for the periodic job an add the UICallBack calls in a RAP fragment. It runs with RCP, but in RAP the UIThread and the periodic job being deadlocked after some time (faster if I show it in 4 browsers). Because of the periodic thread is not started from the UIThread, I execute the UICallBack always with a asyncExec() around.
Furthermore another job exists which runs if the user expands a node of the tree (to trigger the update immediately).

Is there probably a general problem?

Regards,
Oliver
Previous Topic:Problem with System.out of ECF chat over RAP
Next Topic:Execute/Open a File on Client
Goto Forum:
  


Current Time: Mon Dec 22 22:03:22 GMT 2014

Powered by FUDForum. Page generated in 0.02030 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software