Class DataFetchEndedEvent
- All Implemented Interfaces:
Serializable
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:
-
Field Summary
Fields inherited from class java.util.EventObject
source -
Constructor Summary
ConstructorsConstructorDescriptionDataFetchEndedEvent(UI ui, Component component, int offset, int limit, boolean filtered, int rowsReturned) Creates a new event for a fetch whose duration was not measured.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. -
Method Summary
Modifier and TypeMethodDescriptionGets how long the fetch took, measured from just before theDataFetchStartedEventwas fired until the returned items were consumed or the fetch threw.intGets the number of items the data provider actually returned.Methods inherited from class com.vaadin.flow.server.data.AbstractDataFetchEvent
getComponent, getLimit, getOffset, getSource, getUI, isFilteredMethods inherited from class java.util.EventObject
toString
-
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
zeroduration. UseDataFetchEndedEvent(UI, Component, int, int, boolean, int, Duration)to create an event with a measured duration.- Parameters:
ui- the UI the fetching component belongs to, notnullcomponent- the component whose data is being fetched, ornullif it could not be resolvedoffset- the index of the first item requestedlimit- the number of items requestedfiltered- whether a filter was set on the queryrowsReturned- the number of items the data provider actually returned, which may be fewer thanAbstractDataFetchEvent.getLimit(), or-1if the fetch threw, in which case aDataFetchFailedEventcarrying 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, notnullcomponent- the component whose data is being fetched, ornullif it could not be resolvedoffset- the index of the first item requestedlimit- the number of items requestedfiltered- whether a filter was set on the queryrowsReturned- the number of items the data provider actually returned, which may be fewer thanAbstractDataFetchEvent.getLimit(), or-1if the fetch threw, in which case aDataFetchFailedEventcarrying the throwable was fired firstduration- the time from just before the started event was fired until the returned items were consumed or the fetch threw, notnull
-
-
Method Details
-
getRowsReturned
public int getRowsReturned()Gets the number of items the data provider actually returned.A value of
-1is how this event reports that the fetch threw, so a listener can tell a failed fetch from an empty page without listening forDataFetchFailedEvent, which carries the throwable itself.- Returns:
- the row count, or
-1if the fetch threw
-
getDuration
Gets how long the fetch took, measured from just before theDataFetchStartedEventwas 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
-