Class VaadinUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaccessCurrentSession(Runnable action) InvokeaccessSession()using theVaadinSessionassociated with the current thread.static voidaccessSession(VaadinSession session, Runnable action) InvokeVaadinSession.access().static voidaccessSessionSynchronously(VaadinSession session, Runnable action) static booleanInvokeUI.access()but catch and discard any thrownUIDetachedException's.static booleanInvokeaccessUI()using theUIassociated with the current thread, but catch and discard any thrownUIDetachedException's.static booleanaccessUISynchronously(UI ui, Runnable action) InvokeUI.accessSynchronously()but catch and discard any thrownUIDetachedException's.static voidVerify that there is a current and lockedVaadinSessionassociated with the current thread.static voidassertCurrentSession(VaadinSession session) Verify that we are running in the context of the given session and holding the session's lock.static voidVerify that there is no current and lockedVaadinSessionassociated with the current thread.static voidassertNotSession(VaadinSession session) Verify that aVaadinSessionis not associated with the current thread and locked.static Pagestatic VaadinRequestGet theVaadinRequestassociated with the current thread and require that it be found.static VaadinSessionGet theVaadinSessionassociated with the current thread and require that it be found and locked.static UIGet theUIassociated with the current thread and require that it be found.
-
Method Details
-
assertCurrentSession
public static void assertCurrentSession()Verify that there is a current and lockedVaadinSessionassociated with the current thread.This method is equivalent to
getCurrentSession()but doesn't actually return the session.- Throws:
IllegalStateException- if there is noVaadinSessionassociated with the current threadIllegalStateException- if theVaadinSessionassociated with the current thread is not locked
-
assertCurrentSession
Verify that we are running in the context of the given session and holding the session's lock.This method can be used by any code that manipulates Vaadin state to assert that the proper Vaadin locking has been performed on the expected session.
- Parameters:
session- session we are supposed to be running with- Throws:
IllegalArgumentException- ifsessionis nullIllegalStateException- if there is noVaadinSessionassociated with the current threadIllegalStateException- if theVaadinSessionassociated with the current thread is notsessionIllegalStateException- if theVaadinSessionassociated with the current thread is not locked
-
getCurrentSession
Get theVaadinSessionassociated with the current thread and require that it be found and locked.This is a wrapper around
VaadinSession.getCurrent()that (a) throws an exception instead of returning null when there is no session associated with the current thread and (b) verifies the session is locked.- Returns:
- current
VaadinSession, never null - Throws:
IllegalStateException- if there is noVaadinSessionassociated with the current threadIllegalStateException- if theVaadinSessionassociated with the current thread is not locked
-
accessCurrentSession
InvokeaccessSession()using theVaadinSessionassociated with the current thread.- Parameters:
action- action to perform- Throws:
IllegalArgumentException- ifactionis nullIllegalStateException- if there is noVaadinSessionassociated with the current threadIllegalStateException- if theVaadinSessionassociated with the current thread is not locked
-
accessSession
InvokeVaadinSession.access().- Parameters:
session- the session to accessaction- action to perform- Throws:
IllegalArgumentException- ifsessionoractionis null
-
accessSessionSynchronously
- Parameters:
session- the session to access, or nullaction- action to perform- Throws:
IllegalArgumentException- ifsessionis nullIllegalArgumentException- ifactionis null
-
assertNoSession
public static void assertNoSession()Verify that there is no current and lockedVaadinSessionassociated with the current thread.- Throws:
IllegalStateException- if there is a current and locked Vaadin session associated with the current thread
-
assertNotSession
Verify that aVaadinSessionis not associated with the current thread and locked.To verify this only for one specific
VaadinSession, pass thatVaadinSessionas the parameter.To verify this for any
VaadinSessionwhatsoever, pass null as the parameter.- Parameters:
session- someVaadinSession, or null for anyVaadinSession- Throws:
IllegalStateException- if a/theVaadinSessionassociated with the current thread and locked by it
-
getCurrentRequest
Get theVaadinRequestassociated with the current thread and require that it be found.This is just a wrapper around
VaadinRequest.getCurrent()that throws an exception instead of returning null when there is no request associated with the current thread.- Returns:
- current
VaadinRequest, never null - Throws:
IllegalStateException- if there is noVaadinRequestassociated with the current thread
-
getCurrentUI
Get theUIassociated with the current thread and require that it be found.This is just a wrapper around
UI.getCurrent()that throws an exception instead of returning null when there is no request associated with the current thread.- Returns:
- current
UI, never null - Throws:
IllegalStateException- if there is noUIassociated with the current thread
-
accessUI
InvokeaccessUI()using theUIassociated with the current thread, but catch and discard any thrownUIDetachedException's.Does nothing (and returns false) if the current
UIis not attached.- Parameters:
action- action to perform- Returns:
- true if successfully invoked, false if the current
UIis detached - Throws:
IllegalArgumentException- ifactionis nullIllegalStateException- if there is noUIassociated with the current thread
-
accessUI
InvokeUI.access()but catch and discard any thrownUIDetachedException's.Does nothing (and returns false) if
uiis null or not attached.- Parameters:
ui- theUIto access, or nullaction- action to perform- Returns:
- true if successfully invoked, false if
uiis null or detached - Throws:
IllegalArgumentException- ifactionis null
-
accessUISynchronously
InvokeUI.accessSynchronously()but catch and discard any thrownUIDetachedException's.Does nothing (and returns false) if
uiis null or not attached to aVaadinSession.- Parameters:
ui- theUIto access, or nullaction- action to perform- Returns:
- true if successfully invoked, otherwise false
- Throws:
IllegalArgumentException- ifactionis null
-
getCurrentPage
- Returns:
- current
Page, never null - Throws:
IllegalStateException- if there is noUIassociated with the current threadIllegalStateException- if there is noPageassociated with theUIassociated with the current thread
-