Class DataFetchEndedEvent

All Implemented Interfaces:
Serializable

public class DataFetchEndedEvent extends AbstractDataFetchEvent
Event fired through the service event bus once a page of items has been loaded and consumed, or the fetch threw, on the thread that requested it.

Fired in reverse listener registration order, so that listeners nest around the matching DataFetchStartedEvent. Because a data provider may return a lazily evaluated Stream, this is fired after the returned items have been consumed, so the measured duration covers the backend round-trip rather than only the call that started it.

The event tells how long the fetch took and, through a row count of -1, whether it threw, so a listener that times fetches needs no state of its own and no listener for the started or failed event.

Since:
25.3
See Also:
  • Constructor Details

    • DataFetchEndedEvent

      public DataFetchEndedEvent(UI ui, Component component, int offset, int limit, boolean filtered, int rowsReturned)
      Creates a new event for a fetch whose duration was not measured.

      The event reports a zero duration. Use DataFetchEndedEvent(UI, Component, int, int, boolean, int, Duration) to create an event with a measured duration.

      Parameters:
      ui - the UI the fetching component belongs to, not null
      component - the component whose data is being fetched, or null if it could not be resolved
      offset - the index of the first item requested
      limit - the number of items requested
      filtered - whether a filter was set on the query
      rowsReturned - the number of items the data provider actually returned, which may be fewer than AbstractDataFetchEvent.getLimit(), or -1 if the fetch threw, in which case a DataFetchFailedEvent carrying the throwable was fired first
    • DataFetchEndedEvent

      public DataFetchEndedEvent(UI ui, Component component, int offset, int limit, boolean filtered, int rowsReturned, Duration duration)
      Creates a new event carrying the measured duration of the fetch.
      Parameters:
      ui - the UI the fetching component belongs to, not null
      component - the component whose data is being fetched, or null if it could not be resolved
      offset - the index of the first item requested
      limit - the number of items requested
      filtered - whether a filter was set on the query
      rowsReturned - the number of items the data provider actually returned, which may be fewer than AbstractDataFetchEvent.getLimit(), or -1 if the fetch threw, in which case a DataFetchFailedEvent carrying the throwable was fired first
      duration - the time from just before the started event was fired until the returned items were consumed or the fetch threw, not null
  • Method Details

    • getRowsReturned

      public int getRowsReturned()
      Gets the number of items the data provider actually returned.

      A value of -1 is how this event reports that the fetch threw, so a listener can tell a failed fetch from an empty page without listening for DataFetchFailedEvent, which carries the throwable itself.

      Returns:
      the row count, or -1 if the fetch threw
    • getDuration

      public Duration getDuration()
      Gets how long the fetch took, measured from just before the DataFetchStartedEvent was fired until the returned items were consumed or the fetch threw. It includes the time the listeners of the started and failed events took, but not the time spent on this event.
      Returns:
      the duration, never negative