Class VaadinSessionContainer<T extends VaadinSessionInfo>
- java.lang.Object
-
- com.vaadin.data.util.AbstractContainer
-
- com.vaadin.data.util.AbstractInMemoryContainer<I,String,BackedItem<T>>
-
- org.dellroad.stuff.vaadin7.AbstractSimpleContainer<I,T>
-
- org.dellroad.stuff.vaadin7.SimpleKeyedContainer<T,T>
-
- org.dellroad.stuff.vaadin7.SelfKeyedContainer<T>
-
- org.dellroad.stuff.vaadin7.VaadinSessionContainer<T>
-
- Type Parameters:
T- the type of the Java objects that back eachItemin the container
- All Implemented Interfaces:
Container,Container.Filterable,Container.Indexed,Container.ItemSetChangeNotifier,Container.Ordered,Container.SimpleFilterable,Container.Sortable,Serializable,Connectable,PropertyExtractor<T>
public abstract class VaadinSessionContainer<T extends VaadinSessionInfo> extends SelfKeyedContainer<T>
Container containing activeVaadinSessions.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
VaadinSessionhas 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-safeupdate()andreload()methods. Information about activeVaadinSessions comes from the session tracking feature of theSpringVaadinServlet.By subclassing this class and
VaadinSessionInfo, additional session-related properties, such as logged-in user, can be added to the container by annotating theVaadinSessionInfosubclass with@ProvidesPropertyannotations.Note the following:
- This class only works with configurations where Vaadin sessions are stored in memory,
and the
SpringVaadinServletmust be used and configured with init parameterSpringVaadinServlet.SESSION_TRACKING_PARAMETERset totrue. - The
connect()anddisconnect()methods must be invoked before and after (respectively) this container is used; typically these would be invoked in theComponent.attach()andClientConnector.detach()methods of a corresponding widget. - Connected instances retain a strong reference to each
VaadinSessiontherein. Therefore, to avoid leaking closed sessions, instances should be periodically reloaded.
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.data.util.AbstractInMemoryContainer
AbstractInMemoryContainer.BaseItemAddEvent, AbstractInMemoryContainer.BaseItemRemoveEvent
-
Nested classes/interfaces inherited from class com.vaadin.data.util.AbstractContainer
AbstractContainer.BaseItemSetChangeEvent, AbstractContainer.BasePropertySetChangeEvent
-
Nested classes/interfaces inherited from interface com.vaadin.data.Container
Container.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.Viewer
-
Nested classes/interfaces inherited from interface com.vaadin.data.Container.Indexed
Container.Indexed.ItemAddEvent, Container.Indexed.ItemRemoveEvent
-
-
Field Summary
Fields Modifier and Type Field Description protected VaadinSessionsessionTheVaadinSessionthat this container instance is associated with.
-
Constructor Summary
Constructors Modifier Constructor Description protectedVaadinSessionContainer(Class<T> type)Constructor.protectedVaadinSessionContainer(PropertyExtractor<? super T> propertyExtractor, Collection<? extends PropertyDef<?>> propertyDefs)Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidconnect()Connect this container and start tracking sessions.protected abstract TcreateVaadinSessionInfo()Create aVaadinSessionInfobacking object for theVaadinSessionassociated with the current thread.voiddisconnect()Disconnect this container and stop tracking sessions.protected voiddoReload()Reload this container.protected voiddoUpdate()Update eachVaadinSessionInfoinstance in this container.voidreload()Asynchronously reload this container.voidupdate()Asynchronously update this container's items.-
Methods inherited from class org.dellroad.stuff.vaadin7.SelfKeyedContainer
getKeyFor
-
Methods inherited from class org.dellroad.stuff.vaadin7.SimpleKeyedContainer
generateItemId, getItemIdFor, getItemIdForSame, getJavaObject, resetItemIds
-
Methods inherited from class org.dellroad.stuff.vaadin7.AbstractSimpleContainer
addContainerFilter, addContainerFilter, afterReload, createBackedItem, getContainerFilters, getContainerProperty, getContainerPropertyIds, getItemIds, getPropertyExtractor, getPropertyValue, getSortableContainerPropertyIds, getType, getUnfilteredItem, internalRemoveAllItems, load, load, removeAllContainerFilters, removeContainerFilter, removeContainerFilters, setProperties, setProperty, setPropertyExtractor, sort
-
Methods inherited from class com.vaadin.data.util.AbstractInMemoryContainer
addContainerProperty, 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, sortContainer
-
Methods inherited from class com.vaadin.data.util.AbstractContainer
addListener, addPropertySetChangeListener, fireContainerPropertySetChange, fireContainerPropertySetChange, fireItemSetChange, fireItemSetChange, getItemSetChangeListeners, getListeners, getPropertySetChangeListeners, removeListener, removePropertySetChangeListener, setItemSetChangeListeners, setPropertySetChangeListeners
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.data.Container
addContainerProperty, addItem, addItem, containsId, getItem, removeAllItems, removeContainerProperty, removeItem, size
-
Methods inherited from interface com.vaadin.data.Container.Ordered
addItemAfter, addItemAfter, firstItemId, isFirstId, isLastId, lastItemId, nextItemId, prevItemId
-
-
-
-
Field Detail
-
session
protected final VaadinSession session
TheVaadinSessionthat this container instance is associated with. Determined by whateverVaadinSessionis associated with the current thread at construction time.
-
-
Constructor Detail
-
VaadinSessionContainer
protected VaadinSessionContainer(Class<T> type)
Constructor.Properties will be determined by the
@ProvidesPropertyand@ProvidesPropertySortannotated methods in the given class.- Parameters:
type- class to introspect for annotated methods- Throws:
IllegalArgumentException- iftypeis nullIllegalArgumentException- iftypehas two@ProvidesPropertyor@ProvidesPropertySortannotated 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 noVaadinSessionassociated with the current threadIllegalStateException- if there is noSpringVaadinServletassociated with the current thread'sVaadinSession- See Also:
ProvidesProperty,ProvidesPropertySort,ProvidesPropertyScanner
-
VaadinSessionContainer
protected VaadinSessionContainer(PropertyExtractor<? super T> propertyExtractor, Collection<? extends PropertyDef<?>> propertyDefs)
Constructor.- Parameters:
propertyExtractor- used to extract properties from the underlying Java objects; may be null but then container is not usable until one is configured viasetPropertyExtractor()propertyDefs- container property definitions; null is treated like the empty set
-
-
Method Detail
-
connect
public void connect()
Connect this container and start tracking sessions.- Specified by:
connectin interfaceConnectable- Overrides:
connectin classAbstractSimpleContainer<T extends VaadinSessionInfo,T extends VaadinSessionInfo>
-
disconnect
public void disconnect()
Disconnect this container and stop tracking sessions.- Specified by:
disconnectin interfaceConnectable- Overrides:
disconnectin classAbstractSimpleContainer<T extends VaadinSessionInfo,T extends VaadinSessionInfo>
-
reload
public void reload()
Asynchronously reload this container.This method can be invoked from any thread. It creates a new thread to do the actual reloading via
doReload()to avoid potential deadlocks.
-
update
public void update()
Asynchronously update this container's items.This method can be invoked from any thread. It creates a new thread to do the actual updating via
doUpdate()to avoid potential deadlocks.
-
doUpdate
protected void doUpdate()
Update eachVaadinSessionInfoinstance 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 theVaadinSessioncorresponding to thatVaadinSessionInfoinstance is locked, so that information from that session can be safely gathered; then,VaadinSessionInfo.makeUpdatesVisible()is invoked while theVaadinSessionassociated with this container is locked, so item properties can be safely updated, etc.This method must not be invoked while any
VaadinSessionis locked. For example, it may be invoked by a regular timer (only while this container is connected).- Throws:
IllegalStateException- if there is a lockedVaadinSessionassociated with the current thread
-
doReload
protected void doReload()
Reload this container. Reloads this container withVaadinSessionInfoinstances for eachVaadinSession(created viacreateVaadinSessionInfo()), and then invokesdoUpdate().This method must not be invoked while any
VaadinSessionis locked.- Throws:
IllegalStateException- if there is a lockedVaadinSessionassociated with the current thread
-
createVaadinSessionInfo
protected abstract T createVaadinSessionInfo()
Create aVaadinSessionInfobacking object for theVaadinSessionassociated with the current thread. TheVaadinSessionwill be already locked.- Returns:
VaadinSessionInfobacking object for the current session
-
-