Package com.vaadin.flow.internal
Class CurrentInstance
java.lang.Object
com.vaadin.flow.internal.CurrentInstance
- All Implemented Interfaces:
Serializable
Keeps track of various current instances for the current thread. All the
instances are automatically cleared after handling a request from the client
to avoid leaking memory.
Please note that the instances are stored using WeakReference. This
means that the a current instance value may suddenly disappear if there a no
other references to the object.
Currently the framework uses the following instances:
VaadinRequest, VaadinResponse, UI,
VaadinService, VaadinSession.
For internal use only. May be renamed or removed in a future release.
- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidclearAll()Clears all current instances.static <T> TGets the current instance of a specific type if available.static Map<Class<?>, CurrentInstance> Gets the currently set instances so that they can later be restored usingrestoreInstances(Map).static voidrestoreInstances(Map<Class<?>, CurrentInstance> old) Restores the given instances to the given values.static <T> voidSets the current instance of the given type.static Map<Class<?>, CurrentInstance> setCurrent(UI ui) Sets current instances for the UI and all related classes.static Map<Class<?>, CurrentInstance> setCurrent(VaadinSession session) Sets current instances for theVaadinSessionand all related classes.
-
Method Details
-
get
Gets the current instance of a specific type if available.- Type Parameters:
T- the instance type- Parameters:
type- the class to get an instance of- Returns:
- the current instance or the provided type, or
nullif there is no current instance.
-
set
Sets the current instance of the given type.- Type Parameters:
T- the instance type- Parameters:
type- the class that should be used when getting the current instance backinstance- the actual instance- See Also:
-
clearAll
public static void clearAll()Clears all current instances. -
restoreInstances
Restores the given instances to the given values. Note that this should only be used internally to restore Vaadin classes.- Parameters:
old- A Class -< CurrentInstance map to set as current instances
-
getInstances
Gets the currently set instances so that they can later be restored usingrestoreInstances(Map).- Returns:
- a map containing the current instances
-
setCurrent
Sets current instances for the UI and all related classes. The previously defined values can be restored by passing the returned map torestoreInstances(Map).- Parameters:
ui- The UI- Returns:
- A map containing the old values of the instances that this method updated.
-
setCurrent
Sets current instances for theVaadinSessionand all related classes. The previously defined values can be restored by passing the returned map torestoreInstances(Map).- Parameters:
session- The VaadinSession- Returns:
- A map containing the old values of the instances this method updated.
-