Report progress of task |
You want to report progress from the task to the client for monitoring purposes.
First, to receive the progress messages sent from the task to the client, subscribe to the job's addTaskProgressListener event or the task's addProgressUpdatedListener event.
job.addTaskProgressListener(new TaskProgressUpdatedListener() { @Override public void onTaskProgressUpdated(Job job, TaskProgressEventArgs e) { System.out.format("%s %s%n", e.getDescription().getProgress(), e.getDescription().getAdditionalInformation()); } });
Then, on the task, call setProgress(int, java.lang.Object). The values passed to SetProgress will be received on the client's progress event handling method.
this.setProgress(40, 4);
package stkparallelcomputingserversdk.howto; import agi.parallel.client.ClusterJobScheduler; import agi.parallel.client.IJobScheduler; import agi.parallel.client.Job; import agi.parallel.client.TaskProgressEventArgs; import agi.parallel.client.TaskProgressUpdatedListener; import agi.parallel.infrastructure.Task; public class TaskProgress { public static void main(String[] args) { try (IJobScheduler scheduler = new ClusterJobScheduler("localhost")) { scheduler.connect(); Job job = scheduler.createJob(); job.addTask(new ProgressTask()); // Subscribe to TaskProgressUpdated job.addTaskProgressListener(new TaskProgressUpdatedListener() { @Override public void onTaskProgressUpdated(Job job, TaskProgressEventArgs e) { System.out.format("%s %s%n", e.getDescription().getProgress(), e.getDescription().getAdditionalInformation()); } }); job.submit(); job.waitUntilDone(); } /* * The output of the application should resemble: * 0 1 * 20 B * 40 4 * 60 D * 80 E */ } public static class ProgressTask extends Task { @Override public void execute() { try { this.setProgress(0, 1); Thread.sleep(1_000); this.setProgress(20, "B"); Thread.sleep(1_000); this.setProgress(40, 4); Thread.sleep(1_000); this.setProgress(60, "D"); Thread.sleep(1_000); this.setProgress(80, "E"); Thread.sleep(1_000); } catch (InterruptedException e) { e.printStackTrace(); } } } }
If a job could potentially take a long time to finish, reporting the progress of tasks while the task is running helps to notify the user how long the task could take. You can read more about working with task progress here.
To view the progress through the monitoring applications, open the task monitor (through the coordinator or agent tray application). Right click on the column headings and then click on "Status Description" on the drop down menu.
Once the Status Description column is visible, the value of the task progress description can be seen. This is shown in the example above.
STK Parallel Computing Server 2.9 API for Java