Class VaadinUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
accessCurrentSession
(Runnable action) InvokeaccessSession()
using theVaadinSession
associated with the current thread.static void
accessSession
(VaadinSession session, Runnable action) InvokeVaadinSession.access()
.static void
accessSessionSynchronously
(VaadinSession session, Runnable action) static boolean
InvokeUI.access()
but catch and discard any thrownUIDetachedException
's.static boolean
InvokeaccessUI()
using theUI
associated with the current thread, but catch and discard any thrownUIDetachedException
's.static boolean
accessUISynchronously
(UI ui, Runnable action) InvokeUI.accessSynchronously()
but catch and discard any thrownUIDetachedException
's.static void
Verify that there is a current and lockedVaadinSession
associated with the current thread.static void
assertCurrentSession
(VaadinSession session) Verify that we are running in the context of the given session and holding the session's lock.static void
Verify that there is no current and lockedVaadinSession
associated with the current thread.static void
assertNotSession
(VaadinSession session) Verify that aVaadinSession
is not associated with the current thread and locked.static Page
static VaadinRequest
Get theVaadinRequest
associated with the current thread and require that it be found.static VaadinSession
Get theVaadinSession
associated with the current thread and require that it be found and locked.static UI
Get theUI
associated with the current thread and require that it be found.
-
Method Details
-
assertCurrentSession
public static void assertCurrentSession()Verify that there is a current and lockedVaadinSession
associated with the current thread.This method is equivalent to
getCurrentSession()
but doesn't actually return the session.- Throws:
IllegalStateException
- if there is noVaadinSession
associated with the current threadIllegalStateException
- if theVaadinSession
associated 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
- ifsession
is nullIllegalStateException
- if there is noVaadinSession
associated with the current threadIllegalStateException
- if theVaadinSession
associated with the current thread is notsession
IllegalStateException
- if theVaadinSession
associated with the current thread is not locked
-
getCurrentSession
Get theVaadinSession
associated 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 noVaadinSession
associated with the current threadIllegalStateException
- if theVaadinSession
associated with the current thread is not locked
-
accessCurrentSession
InvokeaccessSession()
using theVaadinSession
associated with the current thread.- Parameters:
action
- action to perform- Throws:
IllegalArgumentException
- ifaction
is nullIllegalStateException
- if there is noVaadinSession
associated with the current threadIllegalStateException
- if theVaadinSession
associated with the current thread is not locked
-
accessSession
InvokeVaadinSession.access()
.- Parameters:
session
- the session to accessaction
- action to perform- Throws:
IllegalArgumentException
- ifsession
oraction
is null
-
accessSessionSynchronously
- Parameters:
session
- the session to access, or nullaction
- action to perform- Throws:
IllegalArgumentException
- ifsession
is nullIllegalArgumentException
- ifaction
is null
-
assertNoSession
public static void assertNoSession()Verify that there is no current and lockedVaadinSession
associated with the current thread.- Throws:
IllegalStateException
- if there is a current and locked Vaadin session associated with the current thread
-
assertNotSession
Verify that aVaadinSession
is not associated with the current thread and locked.To verify this only for one specific
VaadinSession
, pass thatVaadinSession
as the parameter.To verify this for any
VaadinSession
whatsoever, pass null as the parameter.- Parameters:
session
- someVaadinSession
, or null for anyVaadinSession
- Throws:
IllegalStateException
- if a/theVaadinSession
associated with the current thread and locked by it
-
getCurrentRequest
Get theVaadinRequest
associated 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 noVaadinRequest
associated with the current thread
-
getCurrentUI
Get theUI
associated 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 noUI
associated with the current thread
-
accessUI
InvokeaccessUI()
using theUI
associated with the current thread, but catch and discard any thrownUIDetachedException
's.Does nothing (and returns false) if the current
UI
is not attached.- Parameters:
action
- action to perform- Returns:
- true if successfully invoked, false if the current
UI
is detached - Throws:
IllegalArgumentException
- ifaction
is nullIllegalStateException
- if there is noUI
associated with the current thread
-
accessUI
InvokeUI.access()
but catch and discard any thrownUIDetachedException
's.Does nothing (and returns false) if
ui
is null or not attached.- Parameters:
ui
- theUI
to access, or nullaction
- action to perform- Returns:
- true if successfully invoked, false if
ui
is null or detached - Throws:
IllegalArgumentException
- ifaction
is null
-
accessUISynchronously
InvokeUI.accessSynchronously()
but catch and discard any thrownUIDetachedException
's.Does nothing (and returns false) if
ui
is null or not attached to aVaadinSession
.- Parameters:
ui
- theUI
to access, or nullaction
- action to perform- Returns:
- true if successfully invoked, otherwise false
- Throws:
IllegalArgumentException
- ifaction
is null
-
getCurrentPage
- Returns:
- current
Page
, never null - Throws:
IllegalStateException
- if there is noUI
associated with the current threadIllegalStateException
- if there is noPage
associated with theUI
associated with the current thread
-