Class GridExporter.GridExporterConcurrentDownloadHandler

java.lang.Object
com.flowingcode.vaadin.addons.gridexporter.GridExporter.GridExporterConcurrentDownloadHandler
All Implemented Interfaces:
DownloadHandler, ElementRequestHandler, Serializable
Enclosing class:
GridExporter<T>

public class GridExporter.GridExporterConcurrentDownloadHandler extends Object
Inner class that extends ConcurrentDownloadHandler for use with the new DownloadHandler API. This provides the same concurrent download control as GridExporterConcurrentStreamResourceWriter but for the new API.
See Also:
  • Field Details

  • Method Details

    • getExporter

      public GridExporter<?> getExporter()
    • getButton

      public Component getButton()
    • getCost

      public float getCost(VaadinSession session)
      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

      public UI 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 UI instance associated with the current download, or null if 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

      public final void handleDownloadRequest(DownloadEvent event) throws IOException
      Handles the download request using the provided DownloadEvent.

      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:
      handleDownloadRequest in interface DownloadHandler
      Parameters:
      event - the download event containing the output stream and session
      Throws:
      IOException - if an IO error occurred
      InterruptedIOException - if the current thread is interrupted
      InterruptedByTimeoutException - 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 is POSITIVE_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_INFINITY if the semaphore is disabled.
    • runWithSemaphore

      protected void runWithSemaphore(VaadinSession session, com.flowingcode.vaadin.addons.gridexporter.ConcurrentOperationBase.RunnableWithIOException task) throws IOException
      Throws:
      IOException