Class GridExporterConcurrentSettings
java.lang.Object
com.flowingcode.vaadin.addons.gridexporter.GridExporterConcurrentSettings
Provides global settings for managing concurrent downloads in
GridExporter
.
This class allows for setting limits on concurrent downloads, configuring timeouts for acquiring download permits, and adding global listeners for concurrent download timeout events.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Registration
addGlobalConcurrentDownloadTimeoutEvent
(SerializableConsumer<ConcurrentDownloadTimeoutEvent> listener) Adds a global listener for concurrent download timeout events.static float
Returns the limit for the number of concurrent downloads.static long
static void
setConcurrentDownloadLimit
(float limit) Sets the limit for the cost of concurrent downloads.static void
setConcurrentDownloadTimeout
(long timeout, TimeUnit unit) Sets the timeout for acquiring a permit to start a download when the maximum number of concurrent downloads is reached.static void
setFailOnUiChange
(boolean failOnUiChange) Configures the behavior of the stream operation when the UI changes during execution.
-
Constructor Details
-
GridExporterConcurrentSettings
public GridExporterConcurrentSettings()
-
-
Method Details
-
setConcurrentDownloadLimit
public static void setConcurrentDownloadLimit(float limit) Sets the limit for the cost of concurrent downloads. If all the downloads have a cost ofGridExporter.DEFAULT_COST
, the limit represents the number of concurrent downloads that are allowed.Finite limits are capped to
GridExporter.MAX_COST
(32767). If the limit isPOSITIVE_INFINITY
, concurrent downloads will not be limited.- Parameters:
limit
- the maximum cost of concurrent downloads allowed- Throws:
IllegalArgumentException
- if the limit is zero or negative.
-
getConcurrentDownloadLimit
public static float getConcurrentDownloadLimit()Returns the limit for the number of concurrent downloads.- Returns:
- the limit for the number of concurrent downloads, or
Float.POSITIVE_INFINITY
if concurrent downloads are not limited.
-
setFailOnUiChange
public static void setFailOnUiChange(boolean failOnUiChange) Configures the behavior of the stream operation when the UI changes during execution.- Parameters:
failOnUiChange
- Iftrue
, the operation will throw anIOException
if the UI changes (e.g., becomes detached) after acquiring the semaphore. Iffalse
, the operation will proceed regardless of any UI changes.
-
setConcurrentDownloadTimeout
Sets the timeout for acquiring a permit to start a download when the maximum number of concurrent downloads is reached. If the timeout is less than or equal to zero, the downloads will fail immediately if no enough permits can be acquired. This timeout is crucial for preventing the system from hanging indefinitely while waiting for available resources. If the timeout expires before a permit can be acquired, the download is cancelled.- Parameters:
timeout
- the maximum time to wait for a permitunit
- the time unit of thetimeout
argument
-
getConcurrentDownloadTimeout
-
addGlobalConcurrentDownloadTimeoutEvent
public static Registration addGlobalConcurrentDownloadTimeoutEvent(SerializableConsumer<ConcurrentDownloadTimeoutEvent> listener) Adds a global listener for concurrent download timeout events.The listener will be called whenever a concurrent download timeout event occurs.
Note that instance-specific listeners take precedence over global listeners. If an instance listener stops the event propagation by calling
stopPropagation()
, the global listeners will not be notified.- Parameters:
listener
- the listener to be added- Returns:
- a
Registration
object that can be used to remove the listener
-