public class VaadinApplication extends Object implements Serializable
At most one instance is associated with each VaadinSession (attempting to create more than one will result in
an exception). This singleton instance is then always accessible from any Vaadin thread via get().
Although this class does not require Spring, the singleton instance can be declared as a bean in the Spring XML
application context created by a SpringVaadinSessionListener, which allows other beans and widgets
in the Vaadin application context to autowire it and have access to the methods provided here:
If your<bean class="org.dellroad.stuff.vaadin7.VaadinApplication"/>
VaadinApplication instance allocates any resources on startup, be sure to configure it so
that it cleans them up on application context shutdown, for example, by specifying destroy-method="...".
If you are in a clustered environment and are subclassing this class, scope="session" is recommended;
without it, there will be one instance per server+session rather than one unique instance per session. Of course,
whether that matters depends on the semantics of the subclass fields. In any case, be aware that no instance will
exist in session until the application context is refreshed.
Note: using scope="session" requires adding a <listener> clause registering Spring's
RequestContextListener in your web.xml.
If this class is subclassed, additional application-specific fields and methods can be supplied to the entire
application via the same mechanism. Subclasses can override init() for any application-specific initialization.
Note: the singleton instance of this class is stored in the Vaadin session and is Serializable. Therefore,
in a clustered environment, subclasses must be prepared to handle (de)serialization. Also, avoid declaring fields
that reference this class in non-session-scope beans; instead, use VaadinApplication.get().
| Constructor and Description |
|---|
VaadinApplication()
Convenience constructor.
|
VaadinApplication(VaadinSession session)
Primary Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addSessionDestroyListener(SessionDestroyListener listener)
Register for a notification when the
VaadinSession is closed, without creating a memory leak. |
void |
close()
Close the
VaadinSession associated with this instance. |
static VaadinApplication |
get()
Get the singleton
VaadinApplication instance associated with the current VaadinSession. |
static <T extends VaadinApplication> |
get(Class<T> clazz)
Get the singleton instance of the specified class associated with the current
VaadinSession. |
static <T extends VaadinApplication> |
get(VaadinSession session,
Class<T> clazz)
Get the singleton instance of the specified class associated with the given session.
|
VaadinSession |
getSession()
Get the
VaadinSession associated with this instance. |
protected void |
init()
Perform any further initialization at construction time.
|
void |
invoke(Runnable action)
Peform some action while holding the lock of the
VaadinSession associated with this instance. |
Future<Void> |
invokeLater(Runnable action)
Peform some action asynchronously while holding the lock of the
VaadinSession associated with this instance. |
void |
removeSessionDestroyListener(SessionDestroyListener listener)
Remove a listener added via
addSessionDestroyListener(). |
protected transient Logger log
public VaadinApplication()
VaadinApplication(VaadinUtil.getCurrentSession())
IllegalStateException - if there is no VaadinSession associated with the current threadIllegalStateException - if there is already a VaadinApplication instance associated with the current sessionpublic VaadinApplication(VaadinSession session)
session - the session with which this instance should be associatedIllegalArgumentException - if session is nullIllegalStateException - if there is already a VaadinApplication instance associated with sessionprotected void init()
The implementation in VaadinApplication does nothing. Subclasses may override as desired.
public VaadinSession getSession()
VaadinSession associated with this instance.public void close()
VaadinSession associated with this instance.
After invoking this method, the caller would normally ensure that no further references to this
instance remain so that it and the associated VaadinSession can be freed.
The implementation in VaadinApplication just delegates to VaadinSession.close().
public static VaadinApplication get()
VaadinApplication instance associated with the current VaadinSession.
This is a convenience method, equivalent to:
VaadinApplication.get(VaadinApplication.class)
IllegalStateException - if there is no VaadinSession associated with the current threadIllegalStateException - if there is no VaadinApplication instance associated with the current sessionpublic static <T extends VaadinApplication> T get(Class<T> clazz)
VaadinSession.
This is a convenience method, equivalent to:
VaadinApplication.get(VaadinUtil.getCurrentSession(), clazz)
Useful for subclasses of VaadinApplication that want to provide their own zero-parameter get() methods.
T - application typeclazz - singleton instance typeclazz in the session, never nullIllegalArgumentException - if clazz is nullIllegalStateException - if there is no VaadinSession associated with the current threadIllegalStateException - if there is no singleton of type clazz associated with the current sessionpublic static <T extends VaadinApplication> T get(VaadinSession session, Class<T> clazz)
T - application typesession - Vaadin sessionclazz - singleton instance typeclazz in the session, never nullIllegalArgumentException - if session is nullIllegalArgumentException - if clazz is nullIllegalStateException - if there is no singleton of type clazz associated with the sessionpublic void invoke(Runnable action)
VaadinSession associated with this instance.
This is a convenience method that in turn invokes VaadinUtil.invoke() using the
VaadinSession associated with this instance.
action - action to performIllegalArgumentException - if action is nullVaadinUtil.invoke(com.vaadin.server.VaadinSession, java.lang.Runnable)public Future<Void> invokeLater(Runnable action)
VaadinSession associated with this instance.
This is a convenience method that in turn invokes VaadinUtil.invokeLater() using the
VaadinSession associated with this instance.
action - action to performIllegalArgumentException - if action is nullVaadinUtil.invokeLater(com.vaadin.server.VaadinSession, java.lang.Runnable)public void addSessionDestroyListener(SessionDestroyListener listener)
VaadinSession is closed, without creating a memory leak.
This is a convenience method that in turn invokes
VaadinUtil.addSessionDestroyListener() using the
VaadinSession associated with this instance.
listener - listener for notificationsIllegalArgumentException - if listener is nullVaadinUtil.addSessionDestroyListener(com.vaadin.server.VaadinSession, com.vaadin.server.SessionDestroyListener)public void removeSessionDestroyListener(SessionDestroyListener listener)
addSessionDestroyListener().
This is a convenience method that in turn invokes
VaadinUtil.removeSessionDestroyListener() using the
VaadinSession associated with this instance.
listener - listener for notificationsIllegalArgumentException - if listener is nullVaadinUtil.removeSessionDestroyListener(com.vaadin.server.VaadinSession, com.vaadin.server.SessionDestroyListener)Copyright © 2017. All rights reserved.