org.apache.jmeter.protocol.http.sampler

## Class ResourcesDownloader

- java.lang.Object
- - org.apache.jmeter.protocol.http.sampler.ResourcesDownloader

-     public class ResourcesDownloader
      extends java.lang.Object

  Manages the parallel http resources download.
  A shared thread pool is used by all the sample.
  A sampler will usually do the following

         // list of AsynSamplerResultHolder to download
         List<Callable<AsynSamplerResultHolder>> list = ...

         // max parallel downloads
         int maxConcurrentDownloads = ...

         // get the singleton instance
         ResourcesDownloader resourcesDownloader = ResourcesDownloader.getInstance();

         // schedule the downloads and wait for the completion
         List<Future<AsynSamplerResultHolder>> retExec = resourcesDownloader.invokeAllAndAwaitTermination(maxConcurrentDownloads, list);

  the call to invokeAllAndAwaitTermination will block until the downloads complete or get interrupted
  the Future list only contains task that have been scheduled in the threadpool.
  The status of those futures are either done or cancelled
  Future enhancements :
  - this implementation should be replaced with a NIO async download in order to reduce the number of threads needed
  Since:
    3.0

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ResourcesDownloader.AsynSamplerResultHolder` Holder of AsynSampler result

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static ResourcesDownloader` | `getInstance()`
    `java.util.List<java.util.concurrent.Future<ResourcesDownloader.AsynSamplerResultHolder>>` | `invokeAllAndAwaitTermination(int maxConcurrentDownloads, java.util.List<java.util.concurrent.Callable<ResourcesDownloader.AsynSamplerResultHolder>> list)` This method will block until the downloads complete or it get interrupted the Future list returned by this method only contains tasks that have been scheduled in the threadpool.
    `void` | `shrink()` this method will try to shrink the thread pool size as much as possible it should be called at the end of a test

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getInstance

          public static ResourcesDownloader getInstance()

    - #### shrink

          public void shrink()

      this method will try to shrink the thread pool size as much as possible it should be called at the end of a test

    - #### invokeAllAndAwaitTermination

          public java.util.List<java.util.concurrent.Future<ResourcesDownloader.AsynSamplerResultHolder>> invokeAllAndAwaitTermination(int maxConcurrentDownloads,
                                                                                                                                       java.util.List<java.util.concurrent.Callable<ResourcesDownloader.AsynSamplerResultHolder>> list)
                                                                                                                                throws java.lang.InterruptedException

      This method will block until the downloads complete or it get interrupted the Future list returned by this method only contains tasks that have been scheduled in the threadpool.
      The status of those futures are either done or cancelled
      Parameters:
        `maxConcurrentDownloads` - max concurrent downloads
        `list` - list of resources to download
      Returns:
        list tasks that have been scheduled
      Throws:
        `java.lang.InterruptedException` - when interrupted while waiting

Copyright © 1998-2019 Apache Software Foundation. All Rights Reserved.