Class HotswapClassEvent
- Direct Known Subclasses:
HotswapClassSessionEvent
VaadinHotswapper implementations during
hotswap processing of Java classes.
This event provides methods for VaadinHotswapper implementations to:
- Trigger UI updates with
triggerUpdate(UIUpdateStrategy)ortriggerUpdate(UI, UIUpdateStrategy) - Update client-side resources via
updateClientResource(String, String) - Send Hot Module Replacement messages via
sendHmrEvent(String, JsonNode)
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final com.vaadin.flow.server.VaadinService -
Constructor Summary
ConstructorsConstructorDescriptionHotswapClassEvent(com.vaadin.flow.server.VaadinService vaadinService, Set<Class<?>> classes, boolean redefined) Creates a new hotswap class event. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines whether any of the active UIs requires a full page reload, based on global or specific UI update strategies.Retrieves the set of classes that were modified during a hotswap operation.final Optional<UIUpdateStrategy> getUIUpdateStrategy(com.vaadin.flow.component.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.final com.vaadin.flow.server.VaadinServiceRetrieves the active instance ofVaadinServiceassociated with the event.final booleanDetermines if the classes have been redefined by the hotswap mechanism.booleanDetermines whether a full page reload is required based on the current global UI update strategy.final voidsendHmrEvent(String event, tools.jackson.databind.JsonNode eventData) Sends a Hot Module Replacement (HMR) message to the client.final voidtriggerUpdate(UIUpdateStrategy uiUpdateStrategy) Sets the global UI update strategy for all UIs.final voidtriggerUpdate(com.vaadin.flow.component.UI ui, UIUpdateStrategy uiUpdateStrategy) Sets the UI update strategy for a specific UI.final voidupdateClientResource(String path, String content) Updates a client-side resource for Hot Module Replacement (HMR).
-
Field Details
-
vaadinService
protected final com.vaadin.flow.server.VaadinService vaadinService
-
-
Constructor Details
-
HotswapClassEvent
public HotswapClassEvent(com.vaadin.flow.server.VaadinService vaadinService, Set<Class<?>> classes, boolean redefined) Creates a new hotswap class event.- Parameters:
vaadinService- the activeVaadinServiceinstanceclasses- the set of classes that were updatedredefined- 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
-
getChangedClasses
Retrieves the set of classes that were modified during a hotswap operation.- Returns:
- a set of
Classobjects representing the classes that have been updated
-
isRedefined
public final boolean isRedefined()Determines if the classes have been redefined by the hotswap mechanism.- Returns:
- true if the classes have been redefined, false if they were loaded for the first time
-
triggerUpdate
Sets the global UI update strategy for all UIs.This method sets the update strategy that will be applied to all UIs. The
UIUpdateStrategy.RELOADstrategy 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
Sets the UI update strategy for a specific UI.This method sets the update strategy for an individual UI. The
UIUpdateStrategy.RELOADstrategy 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
Hotswapperthat 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 foruiUpdateStrategy- the UI update strategy to set
-
updateClientResource
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 emptycontent- the new content for the resource, can be null to indicate resource deletion- Throws:
IllegalArgumentException- if path is null or empty
-
sendHmrEvent
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 emptyeventData- 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 com.vaadin.flow.server.VaadinService getVaadinService()Retrieves the active instance ofVaadinServiceassociated with the event.- Returns:
- the current
VaadinServiceinstance, 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
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
Optionalcontaining theUIUpdateStrategyfor the specified UI, or the global UI update strategy if no specific strategy is found; an emptyOptionalif no strategy is defined
-