S - The type of the event sourcepublic abstract class VaadinExternalListener<S> extends Object
Listeners that are part of a Vaadin application should use this superclass if they are going to be registered
with non-Vaadin event sources, and use the methods register() and unregister() to control listener
registration. Subclasses implement register(S) and register(S)
to perform the actual listener registration/unregister operations.
Use of this class will ensure two things:
Important: subclass listener methods must use handleEvent() when handling events.
This will ensure proper locking to avoid race conditions.
Note: when listening to event sources that are scoped to specific Vaadin application instances and already originate events within the proper Vaadin application context (i.e., event sources that are not external to the Vaadin application), then the use of this superclass is not necessary (however, it also doesn't hurt to use it anyway).
| Modifier | Constructor and Description |
|---|---|
protected |
VaadinExternalListener(S eventSource)
Convenience constructor.
|
protected |
VaadinExternalListener(S eventSource,
VaadinApplication application)
Convenience constructor.
|
protected |
VaadinExternalListener(S eventSource,
VaadinSession session)
Primary constructor.
|
| Modifier and Type | Method and Description |
|---|---|
S |
getEventSource()
Get the event source with which this instance is (or was) registered as a listener.
|
VaadinSession |
getSession()
Get the
VaadinSession (aka Vaadin application) with which this instance is associated. |
protected void |
handleEvent(Runnable action)
Execute the given listener action using the
VaadinSession with which this instance is associated. |
boolean |
isAsynchronous()
Determine whether this instance is configured for asynchronous notification.
|
void |
register()
Register as a listener on configured event source.
|
protected abstract void |
register(S eventSource)
Register as a listener on the given event source.
|
void |
setAsynchronous(boolean asynchronous)
Set whether to notify asynchronously.
|
void |
unregister()
Un-register as a listener on configured event source.
|
protected abstract void |
unregister(S eventSource)
Register as a listener from the given event source.
|
protected VaadinExternalListener(S eventSource)
VaadinExternalListener(eventSource, VaadinUtil.getCurrentSession())
eventSource - the event source on which this listener will registerIllegalArgumentException - if eventSource is nullIllegalStateException - if there is no VaadinSession associated with the current threadprotected VaadinExternalListener(S eventSource, VaadinApplication application)
VaadinExternalListener(eventSource, application.getSession())
eventSource - the event source on which this listener will registerapplication - the VaadinApplication that this listener is part ofIllegalArgumentException - if eventSource is nullNullPointerException - if application is nullprotected VaadinExternalListener(S eventSource, VaadinSession session)
eventSource - the event source on which this listener will register when register() is invokedsession - the associated Vaadin application's sessionIllegalArgumentException - if either parameter is nullpublic boolean isAsynchronous()
public void setAsynchronous(boolean asynchronous)
VaadinUtil.invokeLater() will
be used for notifications, so that these occur on a different thread from the original notifying thread.asynchronous - true to notify asynchronously, false for synchronous notificationshandleEvent()public void register()
This also registers a SessionDestroyListener on the configured Vaadin application,
so that when the application closes we can unregister this instance from the event source to avoid a memory leak.
public void unregister()
This also unregisters the SessionDestroyListener registered by register().
public final VaadinSession getSession()
VaadinSession (aka Vaadin application) with which this instance is associated.public final S getEventSource()
protected void handleEvent(Runnable action)
VaadinSession with which this instance is associated.
Subclass listener methods should handle events by invoking this method to ensure proper locking to avoid race conditions.
This method delegates to VaadinUtil.invoke(), or
VaadinUtil.invokeLater() if this instance is configured to be
asynchronous.
action - action to performVaadinUtil.invoke(com.vaadin.server.VaadinSession, java.lang.Runnable)protected abstract void register(S eventSource)
Subclass must implement this to perform the actual listener registration.
eventSource - event source, never null; will be same as provided to the constructorprotected abstract void unregister(S eventSource)
Subclass must implement this to perform the actual listener registration.
eventSource - event source, never null; will be same as provided to the constructorCopyright © 2017. All rights reserved.