Class DataCountEndedEvent

All Implemented Interfaces:
Serializable

public class DataCountEndedEvent extends AbstractDataCountEvent
Event fired through the service event bus once a count query has returned or thrown, on the thread that issued it.

Fired in reverse listener registration order, so that listeners nest around the matching DataCountStartedEvent. It is fired whether the query returned normally or threw, so a listener can clean up its state in one place.

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

Since:
25.3
See Also:
  • Constructor Details

    • DataCountEndedEvent

      public DataCountEndedEvent(UI ui, Component component, boolean filtered, int count)
      Creates a new event for a count query whose duration was not measured.

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

      Parameters:
      ui - the UI the counting component belongs to, not null
      component - the component whose data is being counted, or null if it could not be resolved
      filtered - whether a filter was set on the query
      count - the number of items the data provider reported, or -1 if the query threw, in which case a DataCountFailedEvent carrying the throwable was fired first
    • DataCountEndedEvent

      public DataCountEndedEvent(UI ui, Component component, boolean filtered, int count, Duration duration)
      Creates a new event carrying the measured duration of the count query.
      Parameters:
      ui - the UI the counting component belongs to, not null
      component - the component whose data is being counted, or null if it could not be resolved
      filtered - whether a filter was set on the query
      count - the number of items the data provider reported, or -1 if the query threw, in which case a DataCountFailedEvent carrying the throwable was fired first
      duration - the time from just before the started event was fired until the query returned or threw, not null
  • Method Details

    • getCount

      public int getCount()
      Gets the number of items the data provider reported.

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

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

      public Duration getDuration()
      Gets how long the count query took, measured from just before the DataCountStartedEvent was fired until the query returned or 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