@Override
  public void solveAsync() throws Exception {
    if (requestJob() == null) {
      LOG.log(Level.INFO, "Optim is already requested, ignoring...");
      return;
    }

    String jobid = null;
    try {
      // create the request
      JobRequest request =
          jobclient
              .newRequest()
              .input("model.mod", modFile)
              .input(new TruckingJobInput(this.mongoDB))
              .build();

      // submit and get the job id
      Future<JobResponse> submit = executor.submit(request, null);
      jobid = request.getJobId();
      requestJobCreated(jobid);
      LOG.log(Level.INFO, "Job submitted " + jobid);
      StatusEventEndpoint.broadcastStatus(
          new RequestStatus(true, jobid, JobExecutionStatus.CREATED));

      // wait for completion of submission
      submit.get(60, TimeUnit.SECONDS);

    } catch (Exception e) {
      LOG.log(Level.WARNING, "Error submitting executing job", e);

      // always cleanup the job by deleting it
      if (jobid != null) {
        try {
          jobclient.deleteJob(jobid);
        } catch (Exception e1) {
          // ignore any exception
        }
      }
      requestJobDone();
      broadcastLatestSolution();
      throw e;
    }
  }
  @Override
  public void solve() {
    if (requestJob() == null) {
      LOG.log(Level.INFO, "Job is already requested, ignoring...");
      return;
    }

    String jobid = null;
    JobExecutionStatus status = null;
    try {
      // create the request
      TruckingJobOutput updater = new TruckingJobOutput(this.mongoDB);
      JobRequest request =
          jobclient
              .newRequest()
              .input("model.mod", modFile)
              .input(new TruckingJobInput(this.mongoDB))
              .livelog(System.out)
              .output(updater)
              .timeout(5, TimeUnit.MINUTES)
              .build();
      updater.setRequest(request);

      // submit and get the job id
      Future<JobResponse> submit = executor.execute(request);
      jobid = request.getJobId();
      requestJobCreated(jobid);
      requestJobProcessed(jobid);

      StatusEventEndpoint.broadcastStatus(
          new RequestStatus(true, jobid, JobExecutionStatus.CREATED));
      LOG.info("Job submitted " + jobid);

      // wait for completion
      JobResponse response = submit.get();

      status = response.getJob().getExecutionStatus();

      switch (status) {
        case PROCESSED:
          break;
        case FAILED:
          // get failure message if defined
          String message = "";
          if (response.getJob().getFailureInfo() != null) {
            message = response.getJob().getFailureInfo().getMessage();
          }
          LOG.warning("Failed " + message);
          break;
        default:
          break;
      }

    } catch (Exception e) {
      LOG.log(Level.WARNING, "Error while executing job", e);
    } finally {
      // always cleanup the job by deleting it
      if (jobid != null) {
        try {
          jobclient.deleteJob(jobid);
        } catch (Exception e) {
          // ignore any exception
        }
      }
      requestJobDone();
      broadcastLatestSolution();
    }
  }