Package com.vaadin.client.communication
Class DefaultConnectionStateHandler
java.lang.Object
com.vaadin.client.communication.DefaultConnectionStateHandler
- All Implemented Interfaces:
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:
- 1.0
- Author:
- Vaadin Ltd
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from interface com.vaadin.client.communication.ConnectionStateHandler
UIDL_REFRESH_TOKEN -
Constructor Summary
ConstructorsConstructorDescriptionDefaultConnectionStateHandler(Registry registry) Creates a new instance connected to the given registry. -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled when some part of the reconnect dialog configuration has been changed.protected voiddoReconnect(elemental.json.JsonObject payload) Re-sends the payload to the server (if not null) or re-sends a heartbeat request immediately.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 final voidgiveUp()Called when we should give up trying to reconnect and inform the user that the application is in CONNECTION_LOST state.protected voidhandleCommunicationError(String details, int statusCode) Called when a communication error occurs and we cannot recover from it.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(XhrConnectionError xhrConnectionError) voidheartbeatException(com.google.gwt.xhr.client.XMLHttpRequest request, Exception exception) Called when an exception occurs during aHeartbeatrequest.voidheartbeatInvalidStatusCode(com.google.gwt.xhr.client.XMLHttpRequest xhr) Called when a heartbeat request returns a status code other than OK (200).voidCalled when aHeartbeatrequest succeeds.voidpushClientTimeout(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response) Called when a client side timeout occurs before a push connection to the server completes.voidpushClosed(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response) Called when the push connection to the server is closed.voidpushError(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response) Called when a fatal error fatal error occurs in the push connection.voidpushInvalidContent(PushConnection pushConnection, String message) Called when invalid content (not JSON) was pushed from the server through the push connection.voidpushNotConnected(elemental.json.JsonObject payload) Called when a message is to be sent to the server through the push channel but the push channel is not connected.voidpushOk(PushConnection pushConnection) Called when the push connection to the server has been established.voidpushReconnectPending(PushConnection pushConnection) Called when the push connection has lost the connection to the server and will proceed to try to re-establish the connection.voidpushScriptLoadError(String resourceUrl) Called when the required push script could not be loaded.protected voidscheduleReconnect(elemental.json.JsonObject payload) Called after a problem occurred.voidxhrException(XhrConnectionError xhrConnectionError) Called when an exception occurs during an XmlHttpRequest request to the server.voidxhrInvalidContent(XhrConnectionError xhrConnectionError) Called when invalid content (not JSON) was returned from the server as the result of an XmlHttpRequest request.voidxhrInvalidStatusCode(XhrConnectionError xhrConnectionError) Called when invalid status code (not 200) was returned by the server as the result of an XmlHttpRequest.voidxhrOk()Called whenever a XmlHttpRequest to the server completes successfully.
-
Constructor Details
-
DefaultConnectionStateHandler
Creates a new instance connected to the given registry.- Parameters:
registry- the global registry
-
-
Method Details
-
xhrException
Description copied from interface:ConnectionStateHandlerCalled when an exception occurs during an XmlHttpRequest request to the server.- Specified by:
xhrExceptionin interfaceConnectionStateHandler- Parameters:
xhrConnectionError- An event containing what was being sent to the server and what exception occurred
-
heartbeatException
public void heartbeatException(com.google.gwt.xhr.client.XMLHttpRequest request, Exception exception) Description copied from interface:ConnectionStateHandlerCalled when an exception occurs during aHeartbeatrequest.- Specified by:
heartbeatExceptionin interfaceConnectionStateHandler- Parameters:
request- The heartbeat requestexception- The exception which occurred
-
heartbeatInvalidStatusCode
public void heartbeatInvalidStatusCode(com.google.gwt.xhr.client.XMLHttpRequest xhr) Description copied from interface:ConnectionStateHandlerCalled when a heartbeat request returns a status code other than OK (200).- Specified by:
heartbeatInvalidStatusCodein interfaceConnectionStateHandler- Parameters:
xhr- the heartbeat request
-
heartbeatOk
public void heartbeatOk()Description copied from interface:ConnectionStateHandlerCalled when aHeartbeatrequest succeeds.- Specified by:
heartbeatOkin interfaceConnectionStateHandler
-
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
-
giveUp
protected final void giveUp()Called when we should give up trying to reconnect and inform the user that the application is in CONNECTION_LOST state. -
getDialogTextGaveUp
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
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:ConnectionStateHandlerCalled when some part of the reconnect dialog configuration has been changed.- Specified by:
configurationUpdatedin interfaceConnectionStateHandler
-
xhrInvalidContent
Description copied from interface:ConnectionStateHandlerCalled when invalid content (not JSON) was returned from the server as the result of an XmlHttpRequest request.- Specified by:
xhrInvalidContentin interfaceConnectionStateHandler- Parameters:
xhrConnectionError- An event containing what was being sent to the server and what was returned
-
pushInvalidContent
Description copied from interface:ConnectionStateHandlerCalled when invalid content (not JSON) was pushed from the server through the push connection.- Specified by:
pushInvalidContentin interfaceConnectionStateHandler- Parameters:
pushConnection- the push connection which was usedmessage- the received message
-
xhrInvalidStatusCode
Description copied from interface:ConnectionStateHandlerCalled when invalid status code (not 200) was returned by the server as the result of an XmlHttpRequest.- Specified by:
xhrInvalidStatusCodein interfaceConnectionStateHandler- Parameters:
xhrConnectionError- An event containing what was being sent to the server and what was returned
-
handleUnauthorized
-
handleCommunicationError
Called when a communication error occurs and we cannot recover from it.- Parameters:
details- message details ornullif there are no detailsstatusCode- the status code
-
xhrOk
public void xhrOk()Description copied from interface:ConnectionStateHandlerCalled whenever a XmlHttpRequest to the server completes successfully.- Specified by:
xhrOkin interfaceConnectionStateHandler
-
pushOk
Description copied from interface:ConnectionStateHandlerCalled when the push connection to the server has been established.- Specified by:
pushOkin interfaceConnectionStateHandler- Parameters:
pushConnection- The push connection which was established
-
pushScriptLoadError
Description copied from interface:ConnectionStateHandlerCalled when the required push script could not be loaded.- Specified by:
pushScriptLoadErrorin interfaceConnectionStateHandler- Parameters:
resourceUrl- The URL which was used for loading the script
-
pushNotConnected
public void pushNotConnected(elemental.json.JsonObject payload) Description copied from interface:ConnectionStateHandlerCalled when a message is to be sent to the server through the push channel but the push channel is not connected.- Specified by:
pushNotConnectedin interfaceConnectionStateHandler- Parameters:
payload- The payload to send to the server
-
pushReconnectPending
Description copied from interface:ConnectionStateHandlerCalled when the push connection has lost the connection to the server and will proceed to try to re-establish the connection.- Specified by:
pushReconnectPendingin 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:ConnectionStateHandlerCalled 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:
pushErrorin 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:ConnectionStateHandlerCalled 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:
pushClientTimeoutin 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:ConnectionStateHandlerCalled 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:
pushClosedin interfaceConnectionStateHandler- Parameters:
pushConnection- The push connection which was closedresponse- An object containing response data
-