|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.vaadin.Application
org.dellroad.stuff.vaadin.ContextApplication
public abstract class ContextApplication
Application subclass that provides some basic infrastructure for Vaadin applications:
get())invoke(java.lang.Runnable))Logger to use
| Nested Class Summary | |
|---|---|
static class |
ContextApplication.CloseEvent
Event delivered to listeners when a ContextApplication is closed. |
static interface |
ContextApplication.CloseListener
Implemented by listeners that wish to be notified when a ContextApplication is closed. |
| Nested classes/interfaces inherited from class com.vaadin.Application |
|---|
Application.ApplicationError, Application.CustomizedSystemMessages, Application.SystemMessages, Application.UserChangeEvent, Application.UserChangeListener, Application.WindowAttachEvent, Application.WindowAttachListener, Application.WindowDetachEvent, Application.WindowDetachListener |
| Nested classes/interfaces inherited from interface com.vaadin.terminal.URIHandler |
|---|
URIHandler.ErrorEvent |
| Field Summary | |
|---|---|
static int |
DEFAULT_NOTIFICATION_DELAY
Default notification linger time for error notifications (in milliseconds): Value is 30000ms. |
protected Logger |
log
|
| Constructor Summary | |
|---|---|
ContextApplication()
|
|
| Method Summary | ||
|---|---|---|
void |
addListener(ContextApplication.CloseListener listener)
Add a ContextApplication.CloseListener to be notified when this instance is closed. |
|
void |
close()
Close this instance. |
|
static ContextApplication |
currentApplication()
Get the ContextApplication instance associated with the current thread. |
|
static
|
currentApplication(Class<A> type)
Get the ContextApplication associated with the current thread, cast to the desired type. |
|
static HttpServletRequest |
currentRequest()
Get the HttpServletRequest associated with the current thread. |
|
static HttpServletResponse |
currentResponse()
Get the HttpServletResponse associated with the current thread. |
|
protected void |
doOnRequestEnd(HttpServletRequest request,
HttpServletResponse response)
Sub-class hook for handling the end of a request. |
|
protected void |
doOnRequestStart(HttpServletRequest request,
HttpServletResponse response)
Sub-class hook for handling the start of a request. |
|
static ContextApplication |
get()
Get the ContextApplication instance associated with the current thread or throw an exception if there is none. |
|
static
|
get(Class<A> type)
Get the ContextApplication instance associated with the current thread, cast to the desired type,
or throw an exception if there is none. |
|
protected String |
getErrorMessage(Throwable t)
Convert an exception into a displayable error message. |
|
protected int |
getNotificationDelay()
Get the notification linger time for error notifications (in milliseconds). |
|
void |
init()
Initialize the application. |
|
protected abstract void |
initApplication()
Initialize the application. |
|
void |
invoke(Runnable action)
Set this instance as the "current application" (if not set already) while invoking the given callback. |
|
Future<?> |
invokeLater(Runnable action)
Set this instance as the "current application" and invoke the given callback from within another thread. |
|
void |
onRequestEnd(HttpServletRequest request,
HttpServletResponse response)
Handle the end of a request. |
|
void |
onRequestStart(HttpServletRequest request,
HttpServletResponse response)
Handle the start of a request. |
|
void |
removeListener(ContextApplication.CloseListener listener)
Remove a ContextApplication.CloseListener. |
|
void |
showError(String title,
String description)
Display an error message to the user. |
|
void |
showError(String title,
Throwable t)
Display an error message to the user caused by an exception. |
|
void |
terminalError(Terminal.ErrorEvent event)
Handle an uncaugt exception thrown by a Vaadin HTTP request. |
|
| Methods inherited from class com.vaadin.Application |
|---|
addListener, addListener, addListener, addResource, addWindow, getContext, getErrorHandler, getLocale, getLogoutURL, getMainWindow, getProperty, getPropertyNames, getRelativeLocation, getSystemMessages, getTheme, getURL, getUser, getVersion, getWindow, getWindows, handleURI, isRunning, removeListener, removeListener, removeListener, removeResource, removeWindow, setErrorHandler, setLocale, setLogoutURL, setMainWindow, setTheme, setUser, start |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_NOTIFICATION_DELAY
protected final Logger log
| Constructor Detail |
|---|
public ContextApplication()
| Method Detail |
|---|
public final void init()
The implementation in ContextApplication delegates to initApplication().
init in class Applicationprotected abstract void initApplication()
ContextApplication must implement this method.
public void terminalError(Terminal.ErrorEvent event)
The implementation in ContextApplication logs the error and displays in on the
user's screen via showError(String, Throwable).
terminalError in interface Terminal.ErrorListenerterminalError in class Application
public void showError(String title,
String description)
public void showError(String title,
Throwable t)
protected int getNotificationDelay()
The implementation in ContextApplication returns DEFAULT_NOTIFICATION_DELAY.
protected String getErrorMessage(Throwable t)
public void invoke(Runnable action)
This method is useful for situations in which non-Vaadin threads need to call into Vaadin code
that expects to successfully retrieve the current application via currentApplication().
This method also synchronizes on this ContextApplication instance as required by Vaadin for thread safety.
action - action to perform
IllegalStateException - if a different ContextApplication is already set as the current application
associated with the current threadinvokeLater()public Future<?> invokeLater(Runnable action)
This method functions like invoke() except that action will be invoked from within
a separate thread dedicated to this application instance. This is useful to reduce Vaadin application lock
contention, by performing Vaadin-related actions in a separate, dedicated thread. Actions are executed
in the order they are given to this method.
The returned Future's get() method will return null upon successful completion.
This method itself always returns immediately.
action - action to perform
Future representing the pending results of action
IllegalStateException - if this instance is not initialized or has been closedinvoke()
public final void onRequestStart(HttpServletRequest request,
HttpServletResponse response)
The implementation in ContextApplication delegates to doOnRequestStart(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse).
onRequestStart in interface HttpServletRequestListener
public final void onRequestEnd(HttpServletRequest request,
HttpServletResponse response)
The implementation in ContextApplication delegates to doOnRequestEnd(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse).
onRequestEnd in interface HttpServletRequestListener
protected void doOnRequestStart(HttpServletRequest request,
HttpServletResponse response)
onRequestStart(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse).
The implementation in ContextApplication does nothing. Subclasses should override as necessary.
protected void doOnRequestEnd(HttpServletRequest request,
HttpServletResponse response)
onRequestEnd(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse).
The implementation in ContextApplication does nothing. Subclasses should override as necessary.
public static ContextApplication currentApplication()
ContextApplication instance associated with the current thread.
If the current thread is handling a Vaadin HTTP request that is executing within an ContextApplication instance,
or is executing within invoke(java.lang.Runnable), then this method will return the associated ContextApplication.
ContextApplication associated with the current thread, or null if the current thread
is not servicing a Vaadin web request or the current Vaadin Application is not an ContextApplicationinvoke(java.lang.Runnable)public static <A extends ContextApplication> A currentApplication(Class<A> type)
ContextApplication associated with the current thread, cast to the desired type.
type - expected application type
ContextApplication associated with the current thread
ClassCastException - if the current application is not assignable to typecurrentApplication()public static ContextApplication get()
ContextApplication instance associated with the current thread or throw an exception if there is none.
If the current thread is handling a Vaadin web request that is executing within an ContextApplication instance,
or is executing within invoke(java.lang.Runnable), then this method will return the associated ContextApplication.
Otherwise, an exception is thrown.
ContextApplication associated with the current thread
IllegalStateException - if the current thread is not servicing a Vaadin web request
or the current Vaadin Application is not an ContextApplicationpublic static <A extends ContextApplication> A get(Class<A> type)
ContextApplication instance associated with the current thread, cast to the desired type,
or throw an exception if there is none.
type - expected application type
ContextApplication associated with the current thread
IllegalStateException - if the current ContextApplication is not found
ClassCastException - if the current application is not assignable to typeget()public static HttpServletRequest currentRequest()
HttpServletRequest associated with the current thread.
If the current thread is handling a Vaadin web request for an instance of this class,
this method will return the associated HttpServletRequest.
HttpServletRequest associated with the current thread, or null if the current thread
is not servicing a Vaadin web request or the current Vaadin Application is not an instance of this classpublic static HttpServletResponse currentResponse()
HttpServletResponse associated with the current thread.
If the current thread is handling a Vaadin web request for an instance of this class,
this method will return the associated HttpServletResponse.
HttpServletResponse associated with the current thread, or null if the current thread
is not servicing a Vaadin web request or the current Vaadin Application is not an instance of this classpublic void close()
The implementation in ContextApplication first delegates to the superclass and then
notifies any registered ContextApplication.CloseListeners.
close in class Applicationpublic void addListener(ContextApplication.CloseListener listener)
ContextApplication.CloseListener to be notified when this instance is closed.
public void removeListener(ContextApplication.CloseListener listener)
ContextApplication.CloseListener.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||