Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Jobs API: Notify when Jobs finished
Jobs API: Notify when Jobs finished [message #517819] Tue, 02 March 2010 04:30 Go to next message
Matthias is currently offline Matthias
Messages: 52
Registered: September 2009
Member
Hi there,
With a JobChangeListener i'm able to listen to the status of a single Job.
But how can i listen to status of a set of jobs (job family).
Re: Jobs API: Notify when Jobs finished [message #517986 is a reply to message #517819] Tue, 02 March 2010 06:36 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
On 02.03.2010 10:30, Matthias wrote:
> Hi there,
> With a JobChangeListener i'm able to listen to the status of a single Job.
> But how can i listen to status of a set of jobs (job family).

Just register as a listener (IJobChangeListener) at the IJobManager and
filter yourself:

The event (IJobChangeEvent) returns the Job and you can check this
instance via the method belongsTo for a family association.

Btw.: You can get the IJobManager via the static method
Job.getJobManager().

HTH & Greetings from Bremen,

Daniel Krügler
Re: Jobs API: Notify when Jobs finished [message #518117 is a reply to message #517986] Wed, 03 March 2010 02:10 Go to previous messageGo to next message
Matthias is currently offline Matthias
Messages: 52
Registered: September 2009
Member
that way i also get the status of a single job (within a job family). but i want to be notified when all the jobs of a family are done.
I grouped the jobs with setProgressGroup() to an IProgressMonitor. I didn't find out how to listen to its "done" event.
any ideas?
Re: Jobs API: Notify when Jobs finished [message #518147 is a reply to message #518117] Wed, 03 March 2010 04:18 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
On 03.03.2010 08:10, Matthias wrote:
> that way i also get the status of a single job (within a job family).
> but i want to be notified when all the jobs of a family are done.
> I grouped the jobs with setProgressGroup() to an IProgressMonitor. I
> didn't find out how to listen to its "done" event.
> any ideas?

You have to manage that on your own. The spec of belongsTo clearly
documents the following:

"[..] Job families are represented as objects that are not interpreted
or specified in any way by the job manager. Thus, a job can choose to
belong to any number of families. [..]"

This makes it clear that the job manager cannot do that for you.
It should be rather easy to implement that on you own: Create a Set
that contains all of your started jobs that belong to the family
you are interested in. Since you must already provide glue-code
to properly implement belongsTo, this is already work that would
belong to the responsibilities of the proper belongsTo implementation.

Then register as filtered listener as described in my first reply.
If the filter matches and belongsTo return true, ensure that
you remove the corresponding entry from your set. Finally there will
be some done event, where you have removed the last element from
this Set and isEmpty returns true after the removal. This is the
event you are interested in.

HTH & Greetings from Bremen,

Daniel Krügler
Re: Jobs API: Notify when Jobs finished [message #518148 is a reply to message #518147] Wed, 03 March 2010 04:22 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
On 03.03.2010 10:18, Daniel Krügler wrote:
> On 03.03.2010 08:10, Matthias wrote:
>> that way i also get the status of a single job (within a job family).
>> but i want to be notified when all the jobs of a family are done.
>> I grouped the jobs with setProgressGroup() to an IProgressMonitor. I
>> didn't find out how to listen to its "done" event.
>> any ideas?
>
> You have to manage that on your own. The spec of belongsTo clearly
> documents the following:
>
> "[..] Job families are represented as objects that are not interpreted
> or specified in any way by the job manager. Thus, a job can choose to
> belong to any number of families. [..]"
>
> This makes it clear that the job manager cannot do that for you.
> It should be rather easy to implement that on you own: Create a Set
> that contains all of your started jobs that belong to the family
> you are interested in. Since you must already provide glue-code
> to properly implement belongsTo, this is already work that would
> belong to the responsibilities of the proper belongsTo implementation.

Should that be unclear: I mean here that there must exist your
own business logic that decides what belongsTo means. The same
business logic should probably administrate the Set of jobs,
I referred to in the text.

> Then register as filtered listener as described in my first reply.
> If the filter matches and belongsTo return true, ensure that
> you remove the corresponding entry from your set.

... in the done event, of-course.

Finally there will
> be some done event, where you have removed the last element from
> this Set and isEmpty returns true after the removal. This is the
> event you are interested in.
>
> HTH & Greetings from Bremen,
>
> Daniel Krügler
>
Re: Jobs API: Notify when Jobs finished [message #518213 is a reply to message #518148] Wed, 03 March 2010 08:58 Go to previous messageGo to next message
Matthias is currently offline Matthias
Messages: 52
Registered: September 2009
Member
Hi Daniel,
thanks for you help. I think i did it as you mentioned, it works!

- I added the Jobs to the corresponding family ("myFamily").

- In the Job.addJobChangeListener "done" event i reset the corresponding family (set to "").

- In the IJobManager.addJobChangeListener "done" event i check if there are still Jobs belonging to "myFamily". If not, all the jobs are done.
Re: Jobs API: Notify when Jobs finished [message #518252 is a reply to message #518213] Wed, 03 March 2010 10:19 Go to previous message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
On 03.03.2010 14:58, Matthias wrote:
> Hi Daniel,
> thanks for you help. I think i did it as you mentioned, it works!
>
> - I added the Jobs to the corresponding family ("myFamily").
> - In the Job.addJobChangeListener "done" event i reset the corresponding
> family (set to "").
> - In the IJobManager.addJobChangeListener "done" event i check if there
> are still Jobs belonging to "myFamily". If not, all the jobs are done.

Yes, this is a nice alternative solution!

- Daniel
Previous Topic:Enable a handler based on roles required for the method it is calling
Next Topic:How to add views from other plugins to perspective
Goto Forum:
  


Current Time: Wed Apr 16 03:36:05 EDT 2014

Powered by FUDForum. Page generated in 0.03088 seconds