Class GridExporter.GridExporterConcurrentDownloadHandler
- All Implemented Interfaces:
DownloadHandler,ElementRequestHandler,Serializable
- Enclosing class:
- GridExporter<T>
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatstatic final floatstatic final float -
Method Summary
Modifier and TypeMethodDescriptionforComponent(Component component) Associates this download handler with a component (typically a button).floatgetCost(VaadinSession session) Returns the cost of this download.GridExporter<?>static floatgetLimit()Returns the limit for the number of concurrent operations.longSets the timeout for acquiring a permit to start a download when there are not enough permits available in the semaphore.getUI()Returns the UI associated with the current download.final voidHandles the download request using the providedDownloadEvent.voidonAccept()Callback method that is invoked when a download is accepted.voidonFinish()Callback method that is invoked when a download finishes.voidCallback method that is invoked when a timeout occurs while trying to acquire a permit for starting a download.protected voidrunWithSemaphore(VaadinSession session, com.flowingcode.vaadin.addons.gridexporter.ConcurrentOperationBase.RunnableWithIOException task) default voidsetButtonEnabled(boolean enabled) static voidsetLimit(float limit) Sets the limit for the cost of concurrent operations.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.server.streams.DownloadHandler
handleRequestMethods inherited from interface com.vaadin.flow.server.streams.ElementRequestHandler
getDisabledUpdateMode, getUrlPostfix, isAllowInert
-
Field Details
-
MAX_COST
public static final float MAX_COST- See Also:
-
MIN_COST
public static final float MIN_COST- See Also:
-
DEFAULT_COST
public static final float DEFAULT_COST- See Also:
-
-
Method Details
-
getExporter
-
getButton
-
getCost
Returns the cost of this download. Note that the method is not called under the session lock. It means that if implementation requires access to the application/session data then the session has to be locked explicitly.- Parameters:
session- vaadin session
-
getTimeout
public long getTimeout()Sets the timeout for acquiring a permit to start a download when there are not enough permits available in the semaphore.- Returns:
- the timeout in nanoseconds.
-
getUI
Returns the UI associated with the current download.This method is used to ensure that the UI is still attached to the current session when a download is initiated. Implementations should return the appropriate UI instance.
- Returns:
- the
UIinstance associated with the current download, ornullif no UI is available.
-
onTimeout
public void onTimeout()Callback method that is invoked when a timeout occurs while trying to acquire a permit for starting a download.Implementations can use this method to perform any necessary actions in response to the timeout, such as logging a warning or notifying the user.
-
onAccept
public void onAccept()Callback method that is invoked when a download is accepted.This method is called at the start of the download process. Subclasses should implement this method to perform any necessary actions before the download begins.
-
onFinish
public void onFinish()Callback method that is invoked when a download finishes.This method is called at the end of the download process. Subclasses should implement this method to perform any necessary actions after the download completes.
-
forComponent
Associates this download handler with a component (typically a button). This allows the handler to enable/disable the component during download.- Parameters:
component- the component to associate with this handler- Returns:
- this handler for method chaining
-
setButtonEnabled
default void setButtonEnabled(boolean enabled) -
handleDownloadRequest
Handles the download request using the providedDownloadEvent.Note that the method is not called under the session lock. It means that if implementation requires access to the application/session data then the session has to be locked explicitly.
If a semaphore has been set, it controls access to this method, enforcing a timeout. A permit will be acquired from the semaphore, if one becomes available within the given waiting time and the current thread has not been interrupted.
- Specified by:
handleDownloadRequestin interfaceDownloadHandler- Parameters:
event- the download event containing the output stream and session- Throws:
IOException- if an IO error occurredInterruptedIOException- if the current thread is interruptedInterruptedByTimeoutException- if the waiting time elapsed before a permit was acquired
-
setLimit
public static void setLimit(float limit) Sets the limit for the cost of concurrent operations.Finite limits are capped to
MAX_COST(32767). If the limit isPOSITIVE_INFINITY, the semaphore will not be used for controlling concurrent operations.- Parameters:
limit- the maximum cost of concurrent operations allowed- Throws:
IllegalArgumentException- if the limit is zero or negative.
-
getLimit
public static float getLimit()Returns the limit for the number of concurrent operations.- Returns:
- the limit for the number of concurrent operations, or
Float.POSITIVE_INFINITYif the semaphore is disabled.
-
runWithSemaphore
protected void runWithSemaphore(VaadinSession session, com.flowingcode.vaadin.addons.gridexporter.ConcurrentOperationBase.RunnableWithIOException task) throws IOException - Throws:
IOException
-