public void start()

in import/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/cstore/multipledest/MultipleDestinationUploadService.java [48:139]


  public void start(
      ImmutableList<IDicomWebClient> healthcareDestinations,
      ImmutableList<AetDictionary.Aet> dicomDestinations,
      InputStream inputStream,
      String sopClassUID,
      String sopInstanceUID,
      int associationId)
      throws MultipleDestinationUploadServiceException {
    if (backupUploadService == null) {
      throw new IllegalArgumentException("backupUploadService is null. Some flags not set.");
    }

    List<Throwable> asyncUploadProcessingExceptions = new ArrayList<>();
    String uniqueFileName = String.format("%s_%s.dcm", sopInstanceUID, rand.nextInt(1000));

    try {
      backupUploadService.createBackup(inputStream, uniqueFileName);
    } catch (BackupException be) {
      MonitoringService.addEvent(Event.CSTORE_BACKUP_ERROR);
      log.error("{} processing failed.", this.getClass().getSimpleName(), be);
      throw new MultipleDestinationUploadServiceException(be);
    }

    List<CompletableFuture> uploadFutures = new ArrayList<>();

    CompletableFuture healthcareUploadFuture;
    for (IDicomWebClient healthcareDest : healthcareDestinations) {
      try {
        healthcareUploadFuture =
            backupUploadService.startUploading(
                healthcareDest, new BackupState(uniqueFileName, attemptsAmount));

        uploadFutures.add(healthcareUploadFuture);
      } catch (BackupException be) {
        log.error("Async upload to healthcareDest task not started.", be);
        asyncUploadProcessingExceptions.add(be);
      }
    }

    if (dicomDestinations.isEmpty() == false) {
      CStoreSender cStoreSender = cStoreSenderFactory.create();

      CompletableFuture dicomUploadFuture;
      for (AetDictionary.Aet dicomDest : dicomDestinations) {
        try {
          dicomUploadFuture =
              backupUploadService.startUploading(
                  cStoreSender,
                  dicomDest,
                  sopInstanceUID,
                  sopClassUID,
                  new BackupState(uniqueFileName, attemptsAmount));

          uploadFutures.add(dicomUploadFuture);
        } catch (BackupException be) {
          log.error("Async upload to dicomDest task not started.", be);
          asyncUploadProcessingExceptions.add(be);
        }
      }
    }

    // Don't wait on upload when we are auto-acknowledging and add lazy resolvers to cleanup the
    // files when the association closes.
    if (autoAckCStore) {
      addLazyResolvers(associationId, uniqueFileName, uploadFutures);
    } else {
      for (CompletableFuture uploadFuture : uploadFutures) {
        try {
          uploadFuture.get();
        } catch (ExecutionException eex) {
          log.error("Exception on asyncUpload Job processing.", eex);
          asyncUploadProcessingExceptions.add(eex.getCause());
        } catch (InterruptedException ie) {
          log.error("CStoreSender task interrupted. Upload tasks cancelled.", ie);
          Thread.currentThread().interrupt();
          throw new MultipleDestinationUploadServiceException(ie);
        }
      }
      if (asyncUploadProcessingExceptions.isEmpty()) {
        backupUploadService.removeBackup(uniqueFileName);
      }
    }

    if (!asyncUploadProcessingExceptions.isEmpty()) {
      log.error(
          "Exception messages of the upload async jobs:\n{}",
          asyncUploadProcessingExceptions.stream()
              .map(t -> t.getMessage())
              .collect(Collectors.joining("\n")));
      throw new MultipleDestinationUploadServiceException(asyncUploadProcessingExceptions.get(0));
    }
  }