Class AbstractSessionLockEvent

java.lang.Object
java.util.EventObject
com.vaadin.flow.server.AbstractSessionLockEvent
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
SessionLockAcquiredEvent, SessionLockEvent, SessionLockReleasedEvent, SessionLockRequestedEvent

public abstract class AbstractSessionLockEvent extends EventObject
Describes which service and session an event fired through the service event bus around acquisition and release of a Vaadin session lock is about.

The same lock instance protects a session whether it is acquired by the framework while handling a request or via VaadinSession.lock() (for example from UI.access(Command)). Events are only fired for the outermost lock-hold: taking the lock again on a thread that already holds it fires nothing. Flow measures the lock-hold itself: SessionLockAcquiredEvent.getWaitTime() tells how long the thread waited for the lock and SessionLockReleasedEvent.getHoldTime() how long it held it.

All events of a lock-hold are fired on the thread that takes the lock. A listener can therefore tell whether the lock is taken while handling a request (an incoming push message included) or outside of one, for example from UI.access(Command) in a background thread, by checking whether VaadinService.getCurrentRequest() returns a request. Note that the request may belong to another session, when a request thread locks a session that is not its own.

Listeners are added for the concrete event types SessionLockRequestedEvent, SessionLockAcquiredEvent and SessionLockReleasedEvent, since the event bus dispatches events by their exact type. The wait time and the hold time are only measured while there is a listener for the event that reports them.

Since:
25.3
See Also:
  • Constructor Details

    • AbstractSessionLockEvent

      protected AbstractSessionLockEvent(VaadinService service)
      Creates a new event without a session.
      Parameters:
      service - the Vaadin service whose session lock is being acquired or released, not null
    • AbstractSessionLockEvent

      protected AbstractSessionLockEvent(VaadinService service, VaadinSession session)
      Creates a new event for the given session.
      Parameters:
      service - the Vaadin service whose session lock is being acquired or released, not null
      session - the Vaadin session the lock belongs to, or null if it is not known
  • Method Details

    • getSource

      public VaadinService getSource()
      Gets the Vaadin service from which this event originates.
      Overrides:
      getSource in class EventObject
      Returns:
      the Vaadin service instance
    • getService

      public VaadinService getService()
      Gets the Vaadin service from which this event originates.
      Returns:
      the Vaadin service instance
    • getSession

      public Optional<VaadinSession> getSession()
      Gets the Vaadin session whose lock is acquired or released.

      The session is not known when the lock is taken for a new HTTP session before the Vaadin session has been created in it. It may also not be known after the Vaadin session has been removed from the HTTP session, since the lock does not keep a removed session in memory.

      Returns:
      the Vaadin session, or an empty optional if it is not known