|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.vaadin.server.VaadinSession
public class VaadinSession
Contains everything that Vaadin needs to store for a specific user. This is
typically stored in a HttpSession
or PortletSession
, but
others storage mechanisms might also be used.
Everything inside a VaadinSession
should be serializable to ensure
compatibility with schemes using serialization for persisting the session
data.
Field Summary | |
---|---|
protected WebBrowser |
browser
|
static java.lang.String |
UI_PARAMETER
The name of the parameter that is by default used in e.g. |
Constructor Summary | |
---|---|
VaadinSession(VaadinService service)
Create a new service session tied to a Vaadin service |
Method Summary | ||
---|---|---|
void |
addBootstrapListener(BootstrapListener listener)
Adds a listener that will be invoked when the bootstrap HTML is about to be generated. |
|
void |
addRequestHandler(RequestHandler handler)
Adds a request handler to this session. |
|
void |
addUI(UI ui)
Adds an initialized UI to this session. |
|
void |
addUIProvider(UIProvider uiProvider)
Adds a UI provider to this session. |
|
void |
close()
Sets this session to be closed and all UI state to be discarded at the end of the current request, or at the end of the next request if there is no ongoing one. |
|
java.lang.String |
createConnectorId(ClientConnector connector)
Deprecated. As of 7.0. Will likely change or be removed in a future version |
|
|
getAttribute(java.lang.Class<T> type)
Gets a stored attribute value. |
|
java.lang.Object |
getAttribute(java.lang.String name)
Gets a stored attribute value. |
|
WebBrowser |
getBrowser()
Deprecated. As of 7.0. Will likely change or be removed in a future version |
|
AbstractCommunicationManager |
getCommunicationManager()
Deprecated. As of 7.0. Will likely change or be removed in a future version |
|
DeploymentConfiguration |
getConfiguration()
Gets the configuration for this session |
|
ConverterFactory |
getConverterFactory()
Gets the ConverterFactory used to locate a suitable
Converter for fields in the session. |
|
long |
getCumulativeRequestDuration()
|
|
static VaadinSession |
getCurrent()
Gets the currently used session. |
|
ErrorHandler |
getErrorHandler()
Gets the session's error handler. |
|
static VaadinSession |
getForSession(VaadinService service,
WrappedSession underlyingSession)
Deprecated. As of 7.0. Will likely change or be removed in a future version |
|
GlobalResourceHandler |
getGlobalResourceHandler(boolean createOnDemand)
Gets this session's global resource handler that takes care of serving connector resources that are not served by any single connector because e.g. |
|
long |
getLastRequestDuration()
|
|
long |
getLastRequestTimestamp()
Returns the time when the last request was serviced in this session. |
|
java.util.Locale |
getLocale()
Gets the default locale for this session. |
|
java.util.concurrent.locks.Lock |
getLockInstance()
Gets the Lock instance that is used for protecting the data of
this session from concurrent access. |
|
int |
getNextUIid()
Creates a new unique id for a UI. |
|
java.util.Map<java.lang.String,java.lang.Integer> |
getPreserveOnRefreshUIs()
Gets the mapping from window.name to UI id for UIs that are
should be retained on refresh. |
|
java.util.Collection<RequestHandler> |
getRequestHandlers()
Gets the request handlers that are registered to the session. |
|
VaadinService |
getService()
|
|
WrappedSession |
getSession()
Gets the underlying session to which this service session is currently associated. |
|
UI |
getUIById(int uiId)
Returns a UI with the given id. |
|
java.util.List<UIProvider> |
getUIProviders()
Gets the UI providers configured for this session. |
|
java.util.Collection<UI> |
getUIs()
Gets all the UIs of this session. |
|
boolean |
isClosing()
Returns whether this session is marked to be closed. |
|
void |
lock()
Locks this session to protect its data from concurrent access. |
|
void |
modifyBootstrapResponse(BootstrapResponse response)
Deprecated. As of 7.0. Will likely change or be removed in a future version |
|
void |
removeBootstrapListener(BootstrapListener listener)
Remove a bootstrap listener that was previously added. |
|
void |
removeFromSession(VaadinService service)
Deprecated. As of 7.0. Will likely change or be removed in a future version |
|
void |
removeRequestHandler(RequestHandler handler)
Removes a request handler from the session. |
|
void |
removeUI(UI ui)
Called by the framework to remove an UI instance from the session because it has been closed. |
|
void |
removeUIProvider(UIProvider uiProvider)
Removes a UI provider association from this session. |
|
|
setAttribute(java.lang.Class<T> type,
T value)
Stores a value in this service session. |
|
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Stores a value in this service session. |
|
void |
setCommunicationManager(AbstractCommunicationManager communicationManager)
|
|
void |
setConfiguration(DeploymentConfiguration configuration)
|
|
void |
setConverterFactory(ConverterFactory converterFactory)
Sets the ConverterFactory used to locate a suitable
Converter for fields in the session. |
|
static void |
setCurrent(VaadinSession session)
Sets the thread local for the current session. |
|
void |
setErrorHandler(ErrorHandler errorHandler)
Sets the session error handler. |
|
void |
setLastRequestDuration(long time)
Sets the time spent servicing the last request in the session and updates the total time spent servicing requests in this session. |
|
void |
setLastRequestTimestamp(long timestamp)
Sets the time when the last UIDL request was serviced in this session. |
|
void |
setLocale(java.util.Locale locale)
Sets the default locale for this session. |
|
void |
storeInSession(VaadinService service,
WrappedSession session)
Deprecated. As of 7.0. Will likely change or be removed in a future version |
|
void |
unlock()
Unlocks this session. |
|
void |
valueBound(javax.servlet.http.HttpSessionBindingEvent arg0)
|
|
void |
valueUnbound(javax.servlet.http.HttpSessionBindingEvent event)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String UI_PARAMETER
UI
class.
protected WebBrowser browser
Constructor Detail |
---|
public VaadinSession(VaadinService service)
service
- the Vaadin service for the new sessionMethod Detail |
---|
public void valueBound(javax.servlet.http.HttpSessionBindingEvent arg0)
valueBound
in interface javax.servlet.http.HttpSessionBindingListener
HttpSessionBindingListener.valueBound(HttpSessionBindingEvent)
public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent event)
valueUnbound
in interface javax.servlet.http.HttpSessionBindingListener
HttpSessionBindingListener.valueUnbound(HttpSessionBindingEvent)
@Deprecated public WebBrowser getBrowser()
public long getCumulativeRequestDuration()
public void setLastRequestDuration(long time)
time
- The time spent in the last request, in milliseconds.public long getLastRequestDuration()
public void setLastRequestTimestamp(long timestamp)
timestamp
- The time when the last request was handled, in milliseconds
since the epoch.public long getLastRequestTimestamp()
public WrappedSession getSession()
@Deprecated public AbstractCommunicationManager getCommunicationManager()
@Deprecated public static VaadinSession getForSession(VaadinService service, WrappedSession underlyingSession)
service
- TODOunderlyingSession
-
@Deprecated public void removeFromSession(VaadinService service)
service
- TODO@Deprecated public void storeInSession(VaadinService service, WrappedSession session)
session
- public void setCommunicationManager(AbstractCommunicationManager communicationManager)
public void setConfiguration(DeploymentConfiguration configuration)
public DeploymentConfiguration getConfiguration()
public java.util.Locale getLocale()
public void setLocale(java.util.Locale locale)
locale
- the Locale object.public ErrorHandler getErrorHandler()
public void setErrorHandler(ErrorHandler errorHandler)
errorHandler
- public ConverterFactory getConverterFactory()
ConverterFactory
used to locate a suitable
Converter
for fields in the session.
See setConverterFactory(ConverterFactory)
for more details
public void setConverterFactory(ConverterFactory converterFactory)
ConverterFactory
used to locate a suitable
Converter
for fields in the session.
The ConverterFactory
is used to find a suitable converter when
binding data to a UI component and the data type does not match the UI
component type, e.g. binding a Double to a TextField (which is based on a
String).
The Converter
for an individual field can be overridden using
AbstractField.setConverter(Converter)
and for individual property
ids in a Table
using
Table.setConverter(Object, Converter)
.
The converter factory must never be set to null.
converterFactory
- The converter factory used in the sessionpublic void addRequestHandler(RequestHandler handler)
Handlers are called in reverse order of addition, so the most recently added handler will be called first.
handler
- the request handler to addremoveRequestHandler(RequestHandler)
public void removeRequestHandler(RequestHandler handler)
handler
- the request handler to removepublic java.util.Collection<RequestHandler> getRequestHandlers()
addRequestHandler(RequestHandler)
,
removeRequestHandler(RequestHandler)
public static VaadinSession getCurrent()
InheritableThreadLocal
). In other cases, (e.g. from background
threads started in some other way), the current session is not
automatically defined.
null
setCurrent(VaadinSession)
public static void setCurrent(VaadinSession session)
The application developer can also use this method to define the current session outside the normal request handling and treads started from request handling threads, e.g. when initiating custom background threads.
session
- getCurrent()
,
ThreadLocal
public java.util.Collection<UI> getUIs()
@Deprecated public java.lang.String createConnectorId(ClientConnector connector)
connector
- A connector that has not yet been assigned an id.
public UI getUIById(int uiId)
This is meant for framework internal use.
uiId
- The UI id
public void addBootstrapListener(BootstrapListener listener)
listener
- the bootstrap listener to addBootstrapListener.modifyBootstrapFragment(BootstrapFragmentResponse)
,
BootstrapListener.modifyBootstrapPage(BootstrapPageResponse)
public void removeBootstrapListener(BootstrapListener listener)
listener
- the bootstrap listener to removeaddBootstrapListener(BootstrapListener)
@Deprecated public void modifyBootstrapResponse(BootstrapResponse response)
BootstrapResponse
:
BootstrapFragmentResponse
and BootstrapPageResponse
.
response
- the bootstrap response event for which listeners should be
firedpublic void removeUI(UI ui)
ui
- the UI to removepublic GlobalResourceHandler getGlobalResourceHandler(boolean createOnDemand)
createOnDemand
- true
if a resource handler should be initialized
if there is no handler associated with this application.
false if null should be returned
if there is no registered handler.
null
if
there is no handler and the createOnDemand parameter is
false
.public java.util.concurrent.locks.Lock getLockInstance()
Lock
instance that is used for protecting the data of
this session from concurrent access.
The Lock
can be used to gain more control than what is
available only using lock()
and unlock()
. The returned
instance is not guaranteed to support any other features of the
Lock
interface than Lock.lock()
and
Lock.unlock()
.
Lock
that is used for synchronization, never
null
lock()
,
Lock
public void lock()
try
block
and unlock the session in finally
:
session.lock(); try { doSomething(); } finally { session.unlock(); }
This method will block until the lock can be retrieved.
getLockInstance()
can be used if more control over the locking
is required.
unlock()
,
getLockInstance()
public void unlock()
lock()
to ensure that the lock is always released.
unlock()
public void setAttribute(java.lang.String name, java.lang.Object value)
null
clears the stored value.
name
- the name to associate the value with, can not be
null
value
- the value to associate with the name, or null
to
remove a previous association.getAttribute(String)
public <T> void setAttribute(java.lang.Class<T> type, T value)
null
clears the stored value.
The fully qualified name of the type is used as the name when storing the
value. The outcome of calling this method is thus the same as if calling
setAttribute(type.getName(), value);
type
- the type that the stored value represents, can not be nullvalue
- the value to associate with the type, or null
to
remove a previous association.getAttribute(Class)
,
setAttribute(String, Object)
public java.lang.Object getAttribute(java.lang.String name)
null
is returned.
name
- the name of the value to get, can not be null
.
null
if no value has been stored or if
it has been set to null.setAttribute(String, Object)
public <T> T getAttribute(java.lang.Class<T> type)
null
is returned.
The fully qualified name of the type is used as the name when getting the
value. The outcome of calling this method is thus the same as if calling
getAttribute(type.getName());
type
- the type of the value to get, can not be null
.
null
if no value has been stored or if
it has been set to null.setAttribute(Class, Object)
,
getAttribute(String)
public int getNextUIid()
public java.util.Map<java.lang.String,java.lang.Integer> getPreserveOnRefreshUIs()
window.name
to UI id for UIs that are
should be retained on refresh.
VaadinService#preserveUIOnRefresh(VaadinRequest, UI, UIProvider)
,
PreserveOnRefresh
public void addUI(UI ui)
ui
- the initialized UI to add.public void addUIProvider(UIProvider uiProvider)
uiProvider
- the UI provider that should be addedpublic void removeUIProvider(UIProvider uiProvider)
uiProvider
- the UI provider that should be removedpublic java.util.List<UIProvider> getUIProviders()
public VaadinService getService()
public void close()
After the session has been discarded, any UIs that have been left open will give a Session Expired error and a new session will be created for serving new UIs.
To avoid causing out of sync errors, you should typically redirect to
some other page using Page.setLocation(String)
to make the
browser unload the invalidated UI.
SystemMessages.getSessionExpiredCaption()
public boolean isClosing()
close()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |