Package com.vaadin.client.communication
Class DefaultConnectionStateHandler
- java.lang.Object
-
- com.vaadin.client.communication.DefaultConnectionStateHandler
-
- All Implemented Interfaces:
ConnectionStateHandler
public class DefaultConnectionStateHandler extends Object implements ConnectionStateHandler
Default implementation of the connection state handler.Handles temporary errors by showing a reconnect dialog to the user while trying to re-establish the connection to the server and re-send the pending message.
Handles permanent errors by showing a critical system notification to the user
- Since:
- 7.6
- Author:
- Vaadin Ltd
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
DefaultConnectionStateHandler.Type
-
Constructor Summary
Constructors Constructor Description DefaultConnectionStateHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configurationUpdated()
Called when some part of the reconnect dialog configuration has been changed.protected void
doReconnect(JsonObject payload)
Re-sends the payload to the server (if not null) or re-sends a heartbeat request immediatelyprotected ApplicationConnection
getConnection()
Returns the connection this handler is connected toprotected String
getDialogText(int reconnectAttempt)
Gets the text to show in the reconnect dialogprotected String
getDialogTextGaveUp(int reconnectAttempt)
Gets the text to show in the reconnect dialog after giving up (reconnect limit reached)protected void
giveUp()
Called when we should give up trying to reconnect and let the user decide how to continueprotected void
handleRecoverableError(DefaultConnectionStateHandler.Type type, JsonObject payload)
Called whenever an error occurs in communication which should be handled by showing the reconnect dialog and retrying communication until successful againprotected void
handleUnauthorized(XhrConnectionError xhrConnectionError)
void
heartbeatException(com.google.gwt.http.client.Request request, Throwable exception)
Called when an exception occurs during aHeartbeat
requestvoid
heartbeatInvalidStatusCode(com.google.gwt.http.client.Request request, com.google.gwt.http.client.Response response)
Called when a heartbeat request returns a status code other than OK (200)void
heartbeatOk()
Called when aHeartbeat
request succeedsprotected void
hideDialog()
Called when the reconnect dialog should be hidden.protected boolean
isDialogVisible()
Checks if the reconnect dialog is visible to the uservoid
pushClientTimeout(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
Called when a client side timeout occurs before a push connection to the server completes.void
pushClosed(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
Called when the push connection to the server is closed.void
pushError(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
Called when a fatal error fatal error occurs in the push connection.void
pushInvalidContent(PushConnection pushConnection, String message)
Called when invalid content (not JSON) was pushed from the server through the push connectionvoid
pushNotConnected(JsonObject payload)
Called when a message is to be sent to the server through the push channel but the push channel is not connectedvoid
pushOk(PushConnection pushConnection)
Called when the push connection to the server has been established.void
pushReconnectPending(PushConnection pushConnection)
Called when the push connection has lost the connection to the server and will proceed to try to re-establish the connectionvoid
pushScriptLoadError(String resourceUrl)
Called when the required push script could not be loadedprotected void
scheduleReconnect(JsonObject payload)
Called after a problem occurred.void
setConnection(ApplicationConnection connection)
Sets the application connection this instance is connected to.protected void
showDialog()
Called when the reconnect dialog should be shown.protected void
updateDialog()
Called whenever a reconnect attempt fails to allow updating of dialog contentsvoid
xhrException(XhrConnectionError xhrConnectionError)
Called when an exception occurs during an XmlHttpRequest request to the server.void
xhrInvalidContent(XhrConnectionError xhrConnectionError)
Called when invalid content (not JSON) was returned from the server as the result of an XmlHttpRequest requestvoid
xhrInvalidStatusCode(XhrConnectionError xhrConnectionError)
Called when invalid status code (not 200) was returned by the server as the result of an XmlHttpRequest.void
xhrOk()
Called whenever a XmlHttpRequest to the server completes successfully
-
-
-
Method Detail
-
setConnection
public void setConnection(ApplicationConnection connection)
Description copied from interface:ConnectionStateHandler
Sets the application connection this instance is connected to. Called internally by the framework.- Specified by:
setConnection
in interfaceConnectionStateHandler
- Parameters:
connection
- the application connection this instance is connected to
-
getConnection
protected ApplicationConnection getConnection()
Returns the connection this handler is connected to- Returns:
- the connection for this handler
-
xhrException
public void xhrException(XhrConnectionError xhrConnectionError)
Description copied from interface:ConnectionStateHandler
Called when an exception occurs during an XmlHttpRequest request to the server.- Specified by:
xhrException
in interfaceConnectionStateHandler
- Parameters:
xhrConnectionError
- An event containing what was being sent to the server and what exception occurred
-
heartbeatException
public void heartbeatException(com.google.gwt.http.client.Request request, Throwable exception)
Description copied from interface:ConnectionStateHandler
Called when an exception occurs during aHeartbeat
request- Specified by:
heartbeatException
in interfaceConnectionStateHandler
- Parameters:
request
- The heartbeat requestexception
- The exception which occurred
-
heartbeatInvalidStatusCode
public void heartbeatInvalidStatusCode(com.google.gwt.http.client.Request request, com.google.gwt.http.client.Response response)
Description copied from interface:ConnectionStateHandler
Called when a heartbeat request returns a status code other than OK (200)- Specified by:
heartbeatInvalidStatusCode
in interfaceConnectionStateHandler
- Parameters:
request
- The heartbeat requestresponse
- The heartbeat response
-
heartbeatOk
public void heartbeatOk()
Description copied from interface:ConnectionStateHandler
Called when aHeartbeat
request succeeds- Specified by:
heartbeatOk
in interfaceConnectionStateHandler
-
handleRecoverableError
protected void handleRecoverableError(DefaultConnectionStateHandler.Type type, JsonObject payload)
Called whenever an error occurs in communication which should be handled by showing the reconnect dialog and retrying communication until successful again- Parameters:
type
- The type of failure detectedpayload
- The message which did not reach the server, or null if no message was involved (heartbeat or push connection failed)
-
scheduleReconnect
protected void scheduleReconnect(JsonObject payload)
Called after a problem occurred. This method is responsible for re-sending the payload to the server (if not null) or re-send a heartbeat request at some point- Parameters:
payload
- the payload that did not reach the server, null if the problem was detected by a heartbeat
-
doReconnect
protected void doReconnect(JsonObject payload)
Re-sends the payload to the server (if not null) or re-sends a heartbeat request immediately- Parameters:
payload
- the payload that did not reach the server, null if the problem was detected by a heartbeat
-
updateDialog
protected void updateDialog()
Called whenever a reconnect attempt fails to allow updating of dialog contents
-
giveUp
protected void giveUp()
Called when we should give up trying to reconnect and let the user decide how to continue
-
isDialogVisible
protected boolean isDialogVisible()
Checks if the reconnect dialog is visible to the user- Returns:
- true if the user can see the dialog, false otherwise
-
showDialog
protected void showDialog()
Called when the reconnect dialog should be shown. This is typically when N seconds has passed since a problem with the connection has been detected
-
hideDialog
protected void hideDialog()
Called when the reconnect dialog should be hidden.
-
getDialogTextGaveUp
protected String getDialogTextGaveUp(int reconnectAttempt)
Gets the text to show in the reconnect dialog after giving up (reconnect limit reached)- Parameters:
reconnectAttempt
- The number of the current reconnection attempt- Returns:
- The text to show in the reconnect dialog after giving up
-
getDialogText
protected String getDialogText(int reconnectAttempt)
Gets the text to show in the reconnect dialog- Parameters:
reconnectAttempt
- The number of the current reconnection attempt- Returns:
- The text to show in the reconnect dialog
-
configurationUpdated
public void configurationUpdated()
Description copied from interface:ConnectionStateHandler
Called when some part of the reconnect dialog configuration has been changed.- Specified by:
configurationUpdated
in interfaceConnectionStateHandler
-
xhrInvalidContent
public void xhrInvalidContent(XhrConnectionError xhrConnectionError)
Description copied from interface:ConnectionStateHandler
Called when invalid content (not JSON) was returned from the server as the result of an XmlHttpRequest request- Specified by:
xhrInvalidContent
in interfaceConnectionStateHandler
-
pushInvalidContent
public void pushInvalidContent(PushConnection pushConnection, String message)
Description copied from interface:ConnectionStateHandler
Called when invalid content (not JSON) was pushed from the server through the push connection- Specified by:
pushInvalidContent
in interfaceConnectionStateHandler
-
xhrInvalidStatusCode
public void xhrInvalidStatusCode(XhrConnectionError xhrConnectionError)
Description copied from interface:ConnectionStateHandler
Called when invalid status code (not 200) was returned by the server as the result of an XmlHttpRequest.- Specified by:
xhrInvalidStatusCode
in interfaceConnectionStateHandler
-
handleUnauthorized
protected void handleUnauthorized(XhrConnectionError xhrConnectionError)
-
xhrOk
public void xhrOk()
Description copied from interface:ConnectionStateHandler
Called whenever a XmlHttpRequest to the server completes successfully- Specified by:
xhrOk
in interfaceConnectionStateHandler
-
pushOk
public void pushOk(PushConnection pushConnection)
Description copied from interface:ConnectionStateHandler
Called when the push connection to the server has been established.- Specified by:
pushOk
in interfaceConnectionStateHandler
- Parameters:
pushConnection
- The push connection which was established
-
pushScriptLoadError
public void pushScriptLoadError(String resourceUrl)
Description copied from interface:ConnectionStateHandler
Called when the required push script could not be loaded- Specified by:
pushScriptLoadError
in interfaceConnectionStateHandler
- Parameters:
resourceUrl
- The URL which was used for loading the script
-
pushNotConnected
public void pushNotConnected(JsonObject payload)
Description copied from interface:ConnectionStateHandler
Called when a message is to be sent to the server through the push channel but the push channel is not connected- Specified by:
pushNotConnected
in interfaceConnectionStateHandler
- Parameters:
payload
- The payload to send to the server
-
pushReconnectPending
public void pushReconnectPending(PushConnection pushConnection)
Description copied from interface:ConnectionStateHandler
Called when the push connection has lost the connection to the server and will proceed to try to re-establish the connection- Specified by:
pushReconnectPending
in interfaceConnectionStateHandler
- Parameters:
pushConnection
- The push connection which will be reconnected
-
pushError
public void pushError(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
Description copied from interface:ConnectionStateHandler
Called when a fatal error fatal error occurs in the push connection. The push connection will not try to recover from this situation itself and typically the problem handler should not try to do automatic recovery either. The cause can be e.g. maximum number of reconnection attempts have been reached, neither the selected transport nor the fallback transport can be used or similar.- Specified by:
pushError
in interfaceConnectionStateHandler
- Parameters:
pushConnection
- The push connection where the error occurredresponse
- An object containing response data
-
pushClientTimeout
public void pushClientTimeout(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
Description copied from interface:ConnectionStateHandler
Called when a client side timeout occurs before a push connection to the server completes. The client side timeout causes a disconnection of the push connection and no reconnect will be attempted after this method is called,- Specified by:
pushClientTimeout
in interfaceConnectionStateHandler
- Parameters:
pushConnection
- The push connection which timed outresponse
- An object containing response data
-
pushClosed
public void pushClosed(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
Description copied from interface:ConnectionStateHandler
Called when the push connection to the server is closed. This might result in the push connection trying a fallback connection method, trying to reconnect to the server or might just be an indication that the connection was intentionally closed ("unsubscribe"),- Specified by:
pushClosed
in interfaceConnectionStateHandler
- Parameters:
pushConnection
- The push connection which was closed
-
-