Class HotswapClassSessionEvent

java.lang.Object
com.vaadin.flow.hotswap.HotswapClassEvent
com.vaadin.flow.hotswap.HotswapClassSessionEvent

public class HotswapClassSessionEvent extends HotswapClassEvent
Event object passed to VaadinHotswapper implementations during hotswap processing of Java classes for a specific VaadinSession.

This event provides methods for VaadinHotswapper implementations to:

The event enforces a priority system where UIUpdateStrategy.RELOAD takes precedence over UIUpdateStrategy.REFRESH. Once a RELOAD strategy is set (either globally or for a specific UI), it cannot be changed to REFRESH. This ensures that critical updates requiring a full page reload are not downgraded to partial refreshes.

For internal use only. May be renamed or removed in a future release.

Since:
25.0
  • Field Details

  • Constructor Details

    • HotswapClassSessionEvent

      public HotswapClassSessionEvent(VaadinService vaadinService, VaadinSession vaadinSession, Set<Class<?>> classes, boolean redefined)
      Creates a new hotswap class event.
      Parameters:
      vaadinService - the active VaadinService instance
      classes - the set of classes that were updated
      redefined - true if the classes have been redefined by the hotswap mechanism, false if they have been loaded for the first time by the ClassLoader
  • Method Details

    • getVaadinSession

      public final VaadinSession getVaadinSession()
      Retrieves the associated VaadinSession for this event.
      Returns:
      the VaadinSession instance linked to this event, never null
    • triggerUpdate

      public final void triggerUpdate(UIUpdateStrategy uiUpdateStrategy)
      Sets the global UI update strategy for all UIs.

      This method sets the update strategy that will be applied to all UIs. The UIUpdateStrategy.RELOAD strategy has priority and cannot be changed once set. If the current strategy is already RELOAD, calling this method with REFRESH will have no effect.

      Parameters:
      uiUpdateStrategy - the UI update strategy to set
    • triggerUpdate

      public final void triggerUpdate(UI ui, UIUpdateStrategy uiUpdateStrategy)
      Sets the UI update strategy for a specific UI.

      This method sets the update strategy for an individual UI. The UIUpdateStrategy.RELOAD strategy has priority and cannot be changed once set for a specific UI. The first call for a given UI sets the strategy, and subsequent calls will only be honored if attempting to upgrade from REFRESH to RELOAD.

      NOTE: setting the strategy is a hint for Hotswapper that can however decide to perform a full page reload based on strategies selected for other UIs by any other event users.

      Parameters:
      ui - the UI to set the update strategy for
      uiUpdateStrategy - the UI update strategy to set
    • updateClientResource

      public final void updateClientResource(String path, String content)
      Updates a client-side resource for Hot Module Replacement (HMR).

      This method registers a client resource that should be updated in the browser without requiring a full page reload. The path identifies the resource to update, and the content provides the new resource content.

      Note: This method delegates to the BrowserLiveReload instance and is provided as a convenience to avoid requiring VaadinHotswapper implementations to use Lookup directly.

      Parameters:
      path - the path of the resource to update, must not be null or empty
      content - the new content for the resource, can be null to indicate resource deletion
      Throws:
      IllegalArgumentException - if path is null or empty
    • sendHmrEvent

      public final void sendHmrEvent(String event, tools.jackson.databind.JsonNode eventData)
      Sends a Hot Module Replacement (HMR) message to the client.

      This method queues a custom HMR message to be sent to the browser. HMR messages can be used to notify the client about specific changes that require custom handling beyond standard resource updates.

      Note: This method delegates to the BrowserLiveReload instance and is provided as a convenience to avoid requiring VaadinHotswapper implementations to use Lookup directly.

      Parameters:
      event - the event name/type, must not be null or empty
      eventData - additional data for the event, can be null if no additional data is needed
      Throws:
      IllegalArgumentException - if event is null or empty
    • getVaadinService

      public final VaadinService getVaadinService()
      Retrieves the active instance of VaadinService associated with the event.
      Returns:
      the current VaadinService instance, which provides various services and functionalities required to manage Vaadin applications.
    • requiresPageReload

      public boolean requiresPageReload()
      Determines whether a full page reload is required based on the current global UI update strategy.
      Returns:
      true if the global UI update strategy is set to UIUpdateStrategy.RELOAD, indicating that a full page reload is needed; false otherwise
    • anyUIRequiresPageReload

      public boolean anyUIRequiresPageReload()
      Determines whether any of the active UIs requires a full page reload, based on global or specific UI update strategies.
      Returns:
      true if any UI needs a page reload; false otherwise
    • getUIUpdateStrategy

      public final Optional<UIUpdateStrategy> getUIUpdateStrategy(UI ui)
      Retrieves the UI update strategy for a specific UI, or the global UI update strategy if none is set for the given UI.
      Parameters:
      ui - the UI for which the update strategy is to be retrieved
      Returns:
      an Optional containing the UIUpdateStrategy for the specified UI, or the global UI update strategy if no specific strategy is found; an empty Optional if no strategy is defined