Package org.dellroad.stuff.vaadin8
Class VaadinUtil
- java.lang.Object
-
- org.dellroad.stuff.vaadin8.VaadinUtil
-
public final class VaadinUtil extends Object
Miscellaneous utility methods.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RegistrationaddSessionDestroyListener(VaadinSession session, SessionDestroyListener listener)Register for a notification when theVaadinSessionis closed, without creating a memory leak.static voidassertSession(VaadinSession session)Verify that we are running in the context of the given session and holding the session's lock.static VaadinRequestgetCurrentRequest()Get theVaadinRequestassociated with the current thread.static VaadinSessiongetCurrentSession()Get theVaadinSessionassociated with the current thread.
-
-
-
Method Detail
-
assertSession
public static void assertSession(VaadinSession session)
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.- 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 lockedIllegalStateException- if theVaadinSessionassociated with the current thread is locked by another thread
-
getCurrentSession
public static VaadinSession getCurrentSession()
Get theVaadinSessionassociated with the current thread. This is just a wrapper aroundVaadinSession.getCurrent()that throws an exception instead of returning null when there is no session associated with the current thread.- Returns:
- current
VaadinSession, never null - Throws:
IllegalStateException- if there is noVaadinSessionassociated with the current thread
-
getCurrentRequest
public static VaadinRequest getCurrentRequest()
Get theVaadinRequestassociated with the current thread. This is just a wrapper aroundVaadinService.getCurrentRequest()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
-
addSessionDestroyListener
public static Registration addSessionDestroyListener(VaadinSession session, SessionDestroyListener listener)
Register for a notification when theVaadinSessionis closed, without creating a memory leak. This method is intended to be used by listeners that are themselves part of a Vaadin application.Explanation: the
VaadinSessionclass does not provide a listener API directly; instead, you must use theVaadinServiceclass. However, registering as a listener on theVaadinServicewhen you are part of a Vaadin application sets you up for a memory leak if you forget to unregister yourself when the notification arrives, because theVaadinServicelifetime is longer than theVaadinSessionlifetime. This method handles that de-registration for you automatically.- Parameters:
session- Vaadin sessionlistener- listener for notifications- Returns:
- listener registration
- Throws:
IllegalArgumentException- if either parameter is null
-
-