T - the type of the Java objects that back each Item in the containerpublic abstract class VaadinSessionContainer<T extends VaadinSessionInfo> extends SelfKeyedContainer<T>
VaadinSessions.
This class is useful when you need to display sessions in your GUI, for example, a table showing all logged-in users.
Due to the fact that each VaadinSession has its own lock, building such a container without race conditions
and deadlocks is somewhat tricky. This class performs the locking required during updates and provides thread-safe
update() and reload() methods. Information about active VaadinSessions comes from the session
tracking feature of the SpringVaadinServlet.
By subclassing this class and VaadinSessionInfo, additional session-related properties,
such as logged-in user, can be added to the container by annotating the VaadinSessionInfo
subclass with @ProvidesProperty annotations.
Note the following:
SpringVaadinServlet must be used and configured with init parameter
SpringVaadinServlet.SESSION_TRACKING_PARAMETER set to true.connect() and disconnect() methods must be invoked before and after (respectively)
this container is used; typically these would be invoked in the Component.attach()
and ClientConnector.detach() methods of a corresponding widget.
AbstractInMemoryContainer.BaseItemAddEvent, AbstractInMemoryContainer.BaseItemRemoveEventAbstractContainer.BaseItemSetChangeEvent, AbstractContainer.BasePropertySetChangeEventContainer.Editor, Container.Filter, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeEvent, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.SimpleFilterable, Container.Sortable, Container.ViewerContainer.Indexed.ItemAddEvent, Container.Indexed.ItemRemoveEvent| Modifier and Type | Field and Description |
|---|---|
protected VaadinSession |
session
The
VaadinSession that this container instance is associated with. |
| Modifier | Constructor and Description |
|---|---|
protected |
VaadinSessionContainer(Class<T> type)
Constructor.
|
protected |
VaadinSessionContainer(PropertyExtractor<? super T> propertyExtractor,
Collection<? extends PropertyDef<?>> propertyDefs)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
connect()
Connect this container and start tracking sessions.
|
protected abstract T |
createVaadinSessionInfo()
Create a
VaadinSessionInfo backing object for the VaadinSession associated with the current thread. |
void |
disconnect()
Disconnect this container and stop tracking sessions.
|
protected void |
doReload()
Reload this container.
|
protected void |
doUpdate()
Update each
VaadinSessionInfo instance in this container. |
void |
reload()
Asynchronously reload this container.
|
void |
update()
Asynchronously update this container's items.
|
getKeyForgenerateItemId, getItemIdFor, getItemIdForSame, getJavaObject, resetItemIdsaddContainerFilter, addContainerFilter, afterReload, createBackedItem, getContainerFilters, getContainerProperty, getContainerPropertyIds, getItemIds, getPropertyExtractor, getPropertyValue, getSortableContainerPropertyIds, getType, getUnfilteredItem, internalRemoveAllItems, load, load, removeAllContainerFilters, removeContainerFilter, removeContainerFilters, setProperties, setProperty, setPropertyExtractor, sortaddContainerProperty, addFilter, addItem, addItem, addItemAfter, addItemAfter, addItemAt, addItemAt, addItemSetChangeListener, addListener, containsId, doFilterContainer, doSort, filterAll, fireItemAdded, fireItemRemoved, fireItemsAdded, fireItemsRemoved, firstItemId, getAllItemIds, getFilteredItemIds, getFilters, getFirstVisibleItem, getIdByIndex, getItem, getItemIds, getItemSorter, getSortablePropertyIds, getVisibleItemIds, hasContainerFilters, indexOfId, internalAddItemAfter, internalAddItemAt, internalAddItemAtEnd, internalRemoveItem, isFiltered, isFirstId, isLastId, isPropertyFiltered, lastItemId, nextItemId, passesFilters, prevItemId, registerNewItem, removeAllFilters, removeAllItems, removeContainerProperty, removeFilter, removeFilters, removeItem, removeItemSetChangeListener, removeListener, setAllItemIds, setFilteredItemIds, setFilters, setItemSorter, size, sortContaineraddListener, addPropertySetChangeListener, fireContainerPropertySetChange, fireContainerPropertySetChange, fireItemSetChange, fireItemSetChange, getItemSetChangeListeners, getListeners, getPropertySetChangeListeners, removeListener, removePropertySetChangeListener, setItemSetChangeListeners, setPropertySetChangeListenersclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddItemAfter, addItemAfter, firstItemId, isFirstId, isLastId, lastItemId, nextItemId, prevItemIdaddContainerProperty, addItem, addItem, containsId, getItem, removeAllItems, removeContainerProperty, removeItem, sizeprotected final VaadinSession session
VaadinSession that this container instance is associated with.
Determined by whatever VaadinSession is associated with the current thread at construction time.protected VaadinSessionContainer(Class<T> type)
Properties will be determined by the @ProvidesProperty and
@ProvidesPropertySort annotated methods in the given class.
type - class to introspect for annotated methodsIllegalArgumentException - if type is nullIllegalArgumentException - if type has two @ProvidesProperty
or @ProvidesPropertySort annotated methods for the same propertyIllegalArgumentException - if a @ProvidesProperty-annotated method with no
property name specified has a name which cannot be interpreted as a bean
property "getter" methodIllegalStateException - if there is no VaadinSession associated with the current threadIllegalStateException - if there is no SpringVaadinServlet associated
with the current thread's VaadinSessionProvidesProperty,
ProvidesPropertySort,
ProvidesPropertyScannerprotected VaadinSessionContainer(PropertyExtractor<? super T> propertyExtractor, Collection<? extends PropertyDef<?>> propertyDefs)
propertyExtractor - used to extract properties from the underlying Java objects;
may be null but then container is not usable until one is configured via
setPropertyExtractor()propertyDefs - container property definitions; null is treated like the empty setpublic void connect()
connect in interface Connectableconnect in class AbstractSimpleContainer<T extends VaadinSessionInfo,T extends VaadinSessionInfo>public void disconnect()
disconnect in interface Connectabledisconnect in class AbstractSimpleContainer<T extends VaadinSessionInfo,T extends VaadinSessionInfo>public void reload()
This method can be invoked from any thread. It creates a new thread to do the actual
reloading via doReload() to avoid potential deadlocks.
public void update()
This method can be invoked from any thread. It creates a new thread to do the actual
updating via doUpdate() to avoid potential deadlocks.
protected void doUpdate()
VaadinSessionInfo instance in this container.
Using this method is more efficient than reloading the entire container.
This method handles the complicated locking required to avoid deadlocks: first, for each VaadinSessionInfo,
VaadinSessionInfo.updateInformation() is invoked while the VaadinSession
corresponding to that VaadinSessionInfo instance is locked, so that information from that session
can be safely gathered; then, VaadinSessionInfo.makeUpdatesVisible() is invoked while the VaadinSession
associated with this container is locked, so item properties can be safely updated, etc.
This method must not be invoked while any VaadinSession is locked.
For example, it may be invoked by a regular timer (only while this container is connected).
IllegalStateException - if there is a locked VaadinSession associated with the current threadprotected void doReload()
VaadinSessionInfo instances for each VaadinSession
(created via createVaadinSessionInfo()), and then invokes doUpdate().
This method must not be invoked while any VaadinSession is locked.
IllegalStateException - if there is a locked VaadinSession associated with the current threadprotected abstract T createVaadinSessionInfo()
VaadinSessionInfo backing object for the VaadinSession associated with the current thread.
The VaadinSession will be already locked.VaadinSessionInfo backing object for the current sessionCopyright © 2017. All rights reserved.