Package com.vaadin.flow.hotswap
Class Hotswapper
java.lang.Object
com.vaadin.flow.hotswap.Hotswapper
- All Implemented Interfaces:
ServiceDestroyListener
,SessionDestroyListener
,SessionInitListener
,UIInitListener
,Serializable
public class Hotswapper
extends Object
implements ServiceDestroyListener, SessionInitListener, SessionDestroyListener, UIInitListener
Entry point for application classes hot reloads.
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 String
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. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
forcePageReload
(VaadinService vaadinService, boolean forceReload) Instructs theHotswapper
if a full page reload should always be triggered instead of detecting the best UI refresh strategy.static boolean
isForcedPageReload
(VaadinService vaadinService) Gets whether a forced full page reload is triggered on class changes.void
Called by hotswap tools when one or more application classes have been updated.void
Called by hotswap tools when one or more application resources have been changed.static Optional<Hotswapper>
register
(VaadinService vaadinService) Register the hotwsapper entry point for the givenVaadinService
.void
Invoked when a service is destroyed.void
Called when a Vaadin service session is no longer used.void
sessionInit
(SessionInitEvent event) Invoked when a new Vaadin service session is initialized for that service.void
uiInit
(UIInitEvent event) Notifies when UI is initialized .
-
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.VaadinHotswapper
implementors. invoking firstVaadinHotswapper.onClassLoadEvent(VaadinService, Set, boolean)
and then invokingVaadinHotswapper.onClassLoadEvent(VaadinSession, Set, boolean)
for each activeVaadinSession
.- Parameters:
redefined
- true if the classes have been redefined by hotswap mechanism, false if they have been loaded for time by the ClassLoader.classes
- the set of affected classes.- 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
Description copied from interface:SessionInitListener
Invoked when a new Vaadin service session is initialized for that service.Because of the way different service instances share the same session, the listener is not necessarily notified immediately when the session is created but only when the first request for that session is handled by a specific service.
- Specified by:
sessionInit
in interfaceSessionInitListener
- Parameters:
event
- the initialization event- Throws:
ServiceException
- a problem occurs when processing the event
-
sessionDestroy
Description copied from interface:SessionDestroyListener
Called when a Vaadin service session is no longer used.- Specified by:
sessionDestroy
in interfaceSessionDestroyListener
- Parameters:
event
- the event with details about the destroyed session
-
serviceDestroy
Description copied from interface:ServiceDestroyListener
Invoked when a service is destroyed.- Specified by:
serviceDestroy
in interfaceServiceDestroyListener
- Parameters:
event
- the event
-
uiInit
Description copied from interface:UIInitListener
Notifies when UI is initialized .- Specified by:
uiInit
in interfaceUIInitListener
- Parameters:
event
- event for the initialization
-
register
Register the hotwsapper entry point for the givenVaadinService
.- Parameters:
vaadinService
- theVaadinService
instance for hotswapper registration.- Returns:
- the hotswapper instance wrapped into an
Optional
, or an empty Optional if Vaadin is running in production mode.
-
forcePageReload
Instructs theHotswapper
if a full page reload should always be triggered instead of detecting the best UI refresh strategy.- Parameters:
vaadinService
- theVaadinService
instance.forceReload
- true to always force a page reload, false to let theHotswapper
decide the refresh strategy.
-
isForcedPageReload
Gets whether a forced full page reload is triggered on class changes.- Parameters:
vaadinService
- theVaadinService
instance.- Returns:
- true if full page reload if forced, otherwise false.
-