|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.vaadin.util.CurrentInstance
public class CurrentInstance
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. The inheritable values are also maintained when
execution is moved to another thread, both when a new thread is created and
when VaadinSession.access(Runnable) or UI.access(Runnable) is
used.
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:
Inheritable: UI, VaadinService, VaadinSession.
Non-inheritable: VaadinRequest, VaadinResponse.
| Method Summary | ||
|---|---|---|
static void |
clearAll()
Clears all current instances. |
|
static
|
get(java.lang.Class<T> type)
Gets the current instance of a specific type if available. |
|
static java.util.Map<java.lang.Class<?>,CurrentInstance> |
getInstances(boolean onlyInheritable)
Gets the currently set instances so that they can later be restored using restoreInstances(Map). |
|
static void |
restoreInstances(java.util.Map<java.lang.Class<?>,CurrentInstance> old)
Restores the given instances to the given values. |
|
static
|
set(java.lang.Class<T> type,
T instance)
Sets the current instance of the given type. |
|
static java.util.Map<java.lang.Class<?>,CurrentInstance> |
setCurrent(UI ui)
Sets current instances for the UI and all related classes. |
|
static java.util.Map<java.lang.Class<?>,CurrentInstance> |
setCurrent(VaadinSession session)
Sets current instances for the VaadinSession and all related
classes. |
|
static
|
setInheritable(java.lang.Class<T> type,
T instance)
Sets the current inheritable instance of the given type. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <T> T get(java.lang.Class<T> type)
type - the class to get an instance of
null
if there is no current instance.
public static <T> void set(java.lang.Class<T> type,
T instance)
type - the class that should be used when getting the current
instance backinstance - the actual instancesetInheritable(Class, Object),
ThreadLocal
public static <T> void setInheritable(java.lang.Class<T> type,
T instance)
VaadinSession.access(Runnable) and
UI.access(Runnable).
type - the class that should be used when getting the current
instance backinstance - the actual instanceset(Class, Object),
InheritableThreadLocalpublic static void clearAll()
public static void restoreInstances(java.util.Map<java.lang.Class<?>,CurrentInstance> old)
old - A Class -> CurrentInstance map to set as current instancespublic static java.util.Map<java.lang.Class<?>,CurrentInstance> getInstances(boolean onlyInheritable)
restoreInstances(Map).
onlyInheritable - true if only the inheritable instances should be
included; false to get all instances.
public static java.util.Map<java.lang.Class<?>,CurrentInstance> setCurrent(UI ui)
restoreInstances(Map).
ui - The UI
public static java.util.Map<java.lang.Class<?>,CurrentInstance> setCurrent(VaadinSession session)
VaadinSession and all related
classes. The previously defined values can be restored by passing the
returned map to restoreInstances(Map).
session - The VaadinSession
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||