JPPF Forums

JPPF Help => Developers help => Topic started by: hoho23 on February 15, 2021, 01:11:54 PM

Title: Getting Result from BroadcastJob
Post by: hoho23 on February 15, 2021, 01:11:54 PM
Hello,

I am using JPPF API to optimize an application executing multiple tasks.
Actually I am using the method "jppfJob.getSLA().setBroadcastJob(true)" since I need to execute a job on all the nodes present in the grid.
At the same time, I need a result from this job, precisely I need to know whether the execution is completed or not (in other words I need to know the state of the execution), nut since the broadcast job didn't return anything I don't know what to do to solve this problem. I need your help to know if there is a solution to implement in order to get result from this job.
Waiting for your interaction, have a nice day!

hoho23.
Title: Re: Getting Result from BroadcastJob
Post by: lolo on February 16, 2021, 07:24:36 AM
Hello,

If all you need is to know whether the job has completed, then you can use several techniques thart are easy to implement:

- if you submit the job synchrnonously with JPPFClient.submit() (https://www.jppf.org/javadoc/6.2/org/jppf/client/JPPFClient.html#submitAsync-org.jppf.client.JPPFJob-), then when the submit() method returns, the job has completed. Thie list of tasks that is returned is the initial list of tasks that were put into the job.
- if you submit the job asynchronusly with JPPFClient.submitAsync() (https://www.jppf.org/javadoc/6.2/org/jppf/client/JPPFClient.html#submitAsync-org.jppf.client.JPPFJob-), then you can later use of the JPPFJob.awaitResults() or JPPFJob.get() methods, which will block until completion of the job
- you may also regsiter a job listener (https://www.jppf.org/doc/6.2/index.php?title=Jobs_runtime_behavior,_recovery_and_failover#Job_lifecycle_notifications:_JobListener) and override its jobEnded() method, so that you can trigger an action when notified of the job's completion

I hope this helps,
-Laurent
Title: Re: Getting Result from BroadcastJob
Post by: hoho23 on February 19, 2021, 09:57:41 AM
Hello,

For the two codes below there is no result since the job is set as Broadcast job ( jppfJob.getSLA().setBroadcastJob(true); )  :
Code: [Select]
List<Task<?>> results = jppfClient.submit(jppfJob);or
Code: [Select]
jppfClient.submitAsync(jppfJob);
List<Task<?>> results = jppfJob.awaitResults();

In this case,The only way to know whether the job is completed or not is to regsiter a job listener and override its jobEnded() method.

Thank you for your help!

hoho23
Title: Re: Getting Result from BroadcastJob
Post by: lolo on February 19, 2021, 05:30:35 PM
Hello,

Quote
For the two codes below there is no result since the job is set as Broadcast job

That is true, however I meant to say that the 2 methods JPPFClient.submit() and JPPFJob.awaitResults() that you mentiined are blocking, and will only return when the job has completed. I hope this clarifies.

-Laurent