Class Hotswapper
- All Implemented Interfaces:
com.vaadin.flow.server.ServiceDestroyListener,com.vaadin.flow.server.SessionDestroyListener,com.vaadin.flow.server.SessionInitListener,com.vaadin.flow.server.UIInitListener,Serializable
This class is meant to be used in combination with class live reloading tools like JRebel, Hotswap agent and Spring Boot Developer Tools, to immediately apply changes on components that should be updated when classes have been added or modified. Currently, class deletion is not supported because of issues with several hotswap agents.
Hotswap tools should obtain an instance of this class by calling the
register(VaadinService) method, providing an active
VaadinService instance. For example, an agent can inject the
following code at the beginning of the VaadinService.init() method:
com.vaadin.flow.hotswap.Hotswapper.register(this);
The component delegates specific hotswap logic to registered implementors of
VaadinHotswapper interface.
By default, Hotswapper determines the best browser page refresh strategy, but
a full page reload can be forced by setting the
vaadin.hotswap.forcePageReload system property. Hotswap tools can
alter the behavior at runtime by calling
forcePageReload(VaadinService, boolean)
For internal use only. May be renamed or removed in a future release.
- Since:
- 24.5
- Author:
- Vaadin Ltd
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConfiguration name for the system parameter that determines whether Hotswapper should always trigger a full page reload instead of computing an appropriate UI refresh strategy. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidforcePageReload(com.vaadin.flow.server.VaadinService vaadinService, boolean forceReload) Instructs theHotswapperif a full page reload should always be triggered instead of detecting the best UI refresh strategy.static booleanisForcedPageReload(com.vaadin.flow.server.VaadinService vaadinService) Gets whether a forced full page reload is triggered on class changes.voidCalled by hotswap tools when one or more application classes have been updated.voidCalled by hotswap tools when one or more application resources have been changed.static Optional<Hotswapper> register(com.vaadin.flow.server.VaadinService vaadinService) Register the hotwsapper entry point for the givenVaadinService.voidserviceDestroy(com.vaadin.flow.server.ServiceDestroyEvent event) voidsessionDestroy(com.vaadin.flow.server.SessionDestroyEvent event) voidsessionInit(com.vaadin.flow.server.SessionInitEvent event) voiduiInit(com.vaadin.flow.server.UIInitEvent event)
-
Field Details
-
FORCE_RELOAD_PROPERTY
Configuration name for the system parameter that determines whether Hotswapper should always trigger a full page reload instead of computing an appropriate UI refresh strategy.- See Also:
-
-
Method Details
-
onHotswap
Called by hotswap tools when one or more application classes have been updated.This method delegates update operations to registered
VaadinHotswapperimplementors. invoking firstVaadinHotswapper.onClassesChange(HotswapClassEvent)and then invokingVaadinHotswapper.onClassesChange(HotswapClassSessionEvent)for each activeVaadinSession.- Parameters:
classes- the set of affected classes.redefined- true if the classes have been redefined by hotswap mechanism, false if they have been loaded for time by the ClassLoader.- See Also:
-
onHotswap
Called by hotswap tools when one or more application resources have been changed.- Parameters:
createdResources- the list of potentially newly created resources. Never null.modifiedResources- the list of potentially modified resources. Never null.deletedResources- the list of potentially deleted resource. Never null.
-
sessionInit
public void sessionInit(com.vaadin.flow.server.SessionInitEvent event) throws com.vaadin.flow.server.ServiceException - Specified by:
sessionInitin interfacecom.vaadin.flow.server.SessionInitListener- Throws:
com.vaadin.flow.server.ServiceException
-
sessionDestroy
public void sessionDestroy(com.vaadin.flow.server.SessionDestroyEvent event) - Specified by:
sessionDestroyin interfacecom.vaadin.flow.server.SessionDestroyListener
-
serviceDestroy
public void serviceDestroy(com.vaadin.flow.server.ServiceDestroyEvent event) - Specified by:
serviceDestroyin interfacecom.vaadin.flow.server.ServiceDestroyListener
-
uiInit
public void uiInit(com.vaadin.flow.server.UIInitEvent event) - Specified by:
uiInitin interfacecom.vaadin.flow.server.UIInitListener
-
register
Register the hotwsapper entry point for the givenVaadinService.The hotswapper is registered only in development mode.
- Parameters:
vaadinService- theVaadinServiceinstance for hotswapper registration.- Returns:
- the hotswapper instance wrapped into an
Optional, or an empty Optional if Vaadin is running in production mode.
-
forcePageReload
public static void forcePageReload(com.vaadin.flow.server.VaadinService vaadinService, boolean forceReload) Instructs theHotswapperif a full page reload should always be triggered instead of detecting the best UI refresh strategy.- Parameters:
vaadinService- theVaadinServiceinstance.forceReload- true to always force a page reload, false to let theHotswapperdecide the refresh strategy.
-
isForcedPageReload
public static boolean isForcedPageReload(com.vaadin.flow.server.VaadinService vaadinService) Gets whether a forced full page reload is triggered on class changes.- Parameters:
vaadinService- theVaadinServiceinstance.- Returns:
- true if full page reload if forced, otherwise false.
-