Package com.vaadin.client.communication
Class DefaultConnectionStateHandler
- java.lang.Object
-
- com.vaadin.client.communication.DefaultConnectionStateHandler
-
- All Implemented Interfaces:
com.vaadin.client.communication.ConnectionStateHandler
public class DefaultConnectionStateHandler extends Object implements com.vaadin.client.communication.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 classDefaultConnectionStateHandler.Type
-
Constructor Summary
Constructors Constructor Description DefaultConnectionStateHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigurationUpdated()protected voiddoReconnect(elemental.json.JsonObject payload)Re-sends the payload to the server (if not null) or re-sends a heartbeat request immediately.protected ApplicationConnectiongetConnection()Returns the connection this handler is connected to.protected StringgetDialogText(int reconnectAttempt)Gets the text to show in the reconnect dialog.protected StringgetDialogTextGaveUp(int reconnectAttempt)Gets the text to show in the reconnect dialog after giving up (reconnect limit reached).protected voidgiveUp()Called when we should give up trying to reconnect and let the user decide how to continue.protected voidhandleRecoverableError(DefaultConnectionStateHandler.Type type, elemental.json.JsonObject payload)Called whenever an error occurs in communication which should be handled by showing the reconnect dialog and retrying communication until successful again.protected voidhandleUnauthorized(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)voidheartbeatException(com.google.gwt.http.client.Request request, Throwable exception)voidheartbeatInvalidStatusCode(com.google.gwt.http.client.Request request, com.google.gwt.http.client.Response response)voidheartbeatOk()protected voidhideDialog()Called when the reconnect dialog should be hidden.protected booleanisDialogVisible()Checks if the reconnect dialog is visible to the user.voidpushClientTimeout(com.vaadin.client.communication.PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)voidpushClosed(com.vaadin.client.communication.PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)voidpushError(com.vaadin.client.communication.PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)voidpushInvalidContent(com.vaadin.client.communication.PushConnection pushConnection, String message)voidpushNotConnected(elemental.json.JsonObject payload)voidpushOk(com.vaadin.client.communication.PushConnection pushConnection)voidpushReconnectPending(com.vaadin.client.communication.PushConnection pushConnection)voidpushScriptLoadError(String resourceUrl)protected voidscheduleReconnect(elemental.json.JsonObject payload)Called after a problem occurred.voidsetConnection(ApplicationConnection connection)protected voidshowDialog()Called when the reconnect dialog should be shown.protected voidupdateDialog()Called whenever a reconnect attempt fails to allow updating of dialog contents.voidxhrException(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)voidxhrInvalidContent(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)voidxhrInvalidStatusCode(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)voidxhrOk()
-
-
-
Method Detail
-
setConnection
public void setConnection(ApplicationConnection connection)
- Specified by:
setConnectionin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
getConnection
protected ApplicationConnection getConnection()
Returns the connection this handler is connected to.- Returns:
- the connection for this handler
-
xhrException
public void xhrException(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)
- Specified by:
xhrExceptionin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
heartbeatException
public void heartbeatException(com.google.gwt.http.client.Request request, Throwable exception)- Specified by:
heartbeatExceptionin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
heartbeatInvalidStatusCode
public void heartbeatInvalidStatusCode(com.google.gwt.http.client.Request request, com.google.gwt.http.client.Response response)- Specified by:
heartbeatInvalidStatusCodein interfacecom.vaadin.client.communication.ConnectionStateHandler
-
heartbeatOk
public void heartbeatOk()
- Specified by:
heartbeatOkin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
handleRecoverableError
protected void handleRecoverableError(DefaultConnectionStateHandler.Type type, elemental.json.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(elemental.json.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(elemental.json.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()
- Specified by:
configurationUpdatedin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
xhrInvalidContent
public void xhrInvalidContent(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)
- Specified by:
xhrInvalidContentin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
pushInvalidContent
public void pushInvalidContent(com.vaadin.client.communication.PushConnection pushConnection, String message)- Specified by:
pushInvalidContentin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
xhrInvalidStatusCode
public void xhrInvalidStatusCode(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)
- Specified by:
xhrInvalidStatusCodein interfacecom.vaadin.client.communication.ConnectionStateHandler
-
handleUnauthorized
protected void handleUnauthorized(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)
-
xhrOk
public void xhrOk()
- Specified by:
xhrOkin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
pushOk
public void pushOk(com.vaadin.client.communication.PushConnection pushConnection)
- Specified by:
pushOkin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
pushScriptLoadError
public void pushScriptLoadError(String resourceUrl)
- Specified by:
pushScriptLoadErrorin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
pushNotConnected
public void pushNotConnected(elemental.json.JsonObject payload)
- Specified by:
pushNotConnectedin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
pushReconnectPending
public void pushReconnectPending(com.vaadin.client.communication.PushConnection pushConnection)
- Specified by:
pushReconnectPendingin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
pushError
public void pushError(com.vaadin.client.communication.PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)- Specified by:
pushErrorin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
pushClientTimeout
public void pushClientTimeout(com.vaadin.client.communication.PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)- Specified by:
pushClientTimeoutin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
pushClosed
public void pushClosed(com.vaadin.client.communication.PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)- Specified by:
pushClosedin interfacecom.vaadin.client.communication.ConnectionStateHandler
-
-