Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » [neon] Can the JobAPI replace the Eclipse.JobGroup functionality
[neon] Can the JobAPI replace the Eclipse.JobGroup functionality [message #1751694] Thu, 12 January 2017 15:38 Go to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 565
Registered: October 2012
Location: Bern, Switzerland
Senior Member
As part of our Mars -> Neon migration I've migrated quite a few of single Sync/Async jobs using the new Job-API and that works nicely.

However, I have now stumbled across some code that uses ch.sbb.cisi.fos.scout.client.ui.forms.JobGroup. Is there a corresponding feature in the Neon Job-API?

How do I best migrate the following code:
              // OurClientAsyncJob extends scout's ClientAsyncJob by adding some initial data and having a way to handle it at the end of calculation

              List<OurClientAsyncJob> jobs = new ArrayList<>();
              JobGroup jobGroup = new JobGroup("job-group", numImporterThreads, partitions.size());
              int block = 1;
              int blocksTotal = partitions.size();
              for (List<AnotherBusinessBean> partition : partitions) {
                OurClientAsyncJob asyncJob = createAsyncJob(partition), block + "-of-" + blocksTotal);
                asyncJob.setSystem(false);
                asyncJob.setUser(true);
                asyncJob.setJobGroup(jobGroup);
                asyncJob.schedule();
                jobs.add(asyncJob);
                block++;
              }
              try {
                jobGroup.join(0, null);
              } catch (OperationCanceledException | InterruptedException e) {
                LOGT.error("Error creating job groups", e);
                return importResults;
              }

              for (OurClientAsyncJob job : jobs) {
                job.throwOnError();
                job.handleResult();
                }
              }


The main question being how Scout Neon can give me the jobGroup.join() functionality.

[Updated on: Thu, 12 January 2017 15:41]

Report message to a moderator

Re: [neon] Can the JobAPI replace the Eclipse.JobGroup functionality [message #1751701 is a reply to message #1751694] Thu, 12 January 2017 16:28 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan MotschFriend
Messages: 123
Registered: March 2010
Senior Member
  public void exampleOfJobBatchExecution() throws Exception {
    //assume we want no more than 10 parallel threads at a time
    int maxParallelThreads = 10;
    IExecutionSemaphore lock = Jobs.newExecutionSemaphore(maxParallelThreads);
    //collect all futures. An alternative would be to give the Jobs an executionHint in the JobInput
    ArrayList<IFuture<String>> futures = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
      String operationValue = "operation " + i;
      Callable<String> operation = () -> operationValue;
      JobInput input = Jobs
          .newInput()
          .withExecutionSemaphore(lock);
      IFuture<String> f = Jobs.schedule(operation, input);
      futures.add(f);
    }
    //wait until all done and collect results
    List<String> results = futures
        .stream()
        .map(f -> f.awaitDoneAndGet())
        .collect(Collectors.toList());
    //...
  }
Re: [neon] Can the JobAPI replace the Eclipse.JobGroup functionality [message #1751850 is a reply to message #1751701] Mon, 16 January 2017 09:04 Go to previous message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 565
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Thanks Ivan, I'll give this a go!
Previous Topic:Download file
Next Topic:[neon] How to specify different config.properties file when starting client
Goto Forum:
  


Current Time: Thu Jul 27 19:05:53 GMT 2017

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

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