public class DefaultConnectionStateHandler extends Object implements ConnectionStateHandler
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
| Modifier and Type | Class and Description |
|---|---|
protected static class |
DefaultConnectionStateHandler.Type |
UIDL_REFRESH_TOKEN| Constructor and Description |
|---|
DefaultConnectionStateHandler(Registry registry)
Creates a new instance connected to the given registry.
|
| Modifier and Type | Method and Description |
|---|---|
void |
configurationUpdated()
Called when some part of the reconnect dialog configuration has been
changed.
|
protected void |
doReconnect(elemental.json.JsonObject payload)
Re-sends the payload to the server (if not null) or re-sends a heartbeat
request immediately.
|
protected String |
getDialogText(int reconnectAttempt)
Gets the text to show in the reconnect dialog.
|
protected 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 continue.
|
protected void |
handleCommunicationError(String details,
int statusCode)
Called when a communication error occurs and we cannot recover from it.
|
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.
|
protected void |
handleUnauthorized(XhrConnectionError xhrConnectionError) |
void |
heartbeatException(com.google.gwt.xhr.client.XMLHttpRequest request,
Exception exception)
Called when an exception occurs during a
Heartbeat request. |
void |
heartbeatInvalidStatusCode(com.google.gwt.xhr.client.XMLHttpRequest xhr)
Called when a heartbeat request returns a status code other than OK
(200).
|
void |
heartbeatOk()
Called when a
Heartbeat request succeeds. |
protected void |
hideDialog()
Called when the reconnect dialog should be hidden.
|
protected boolean |
isDialogVisible()
Checks if the reconnect dialog is visible to the user.
|
void |
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 connection.
|
void |
pushNotConnected(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.
|
void |
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 connection.
|
void |
pushScriptLoadError(String resourceUrl)
Called when the required push script could not be loaded.
|
protected void |
scheduleReconnect(elemental.json.JsonObject payload)
Called after a problem occurred.
|
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
contents.
|
void |
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 request.
|
void |
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.
|
public DefaultConnectionStateHandler(Registry registry)
registry - the global registrypublic void xhrException(XhrConnectionError xhrConnectionError)
ConnectionStateHandlerxhrException in interface ConnectionStateHandlerxhrConnectionError - An event containing what was being sent to the server and what
exception occurredpublic void heartbeatException(com.google.gwt.xhr.client.XMLHttpRequest request,
Exception exception)
ConnectionStateHandlerHeartbeat request.heartbeatException in interface ConnectionStateHandlerrequest - The heartbeat requestexception - The exception which occurredpublic void heartbeatInvalidStatusCode(com.google.gwt.xhr.client.XMLHttpRequest xhr)
ConnectionStateHandlerheartbeatInvalidStatusCode in interface ConnectionStateHandlerxhr - the heartbeat requestpublic void heartbeatOk()
ConnectionStateHandlerHeartbeat request succeeds.heartbeatOk in interface ConnectionStateHandlerprotected void handleRecoverableError(DefaultConnectionStateHandler.Type type, elemental.json.JsonObject payload)
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)protected void scheduleReconnect(elemental.json.JsonObject payload)
payload - the payload that did not reach the server, null if the problem
was detected by a heartbeatprotected void doReconnect(elemental.json.JsonObject payload)
payload - the payload that did not reach the server, null if the problem
was detected by a heartbeatprotected void updateDialog()
protected final void giveUp()
protected boolean isDialogVisible()
protected void showDialog()
protected void hideDialog()
protected String getDialogTextGaveUp(int reconnectAttempt)
reconnectAttempt - The number of the current reconnection attemptprotected String getDialogText(int reconnectAttempt)
reconnectAttempt - The number of the current reconnection attemptpublic void configurationUpdated()
ConnectionStateHandlerconfigurationUpdated in interface ConnectionStateHandlerpublic void xhrInvalidContent(XhrConnectionError xhrConnectionError)
ConnectionStateHandlerxhrInvalidContent in interface ConnectionStateHandlerxhrConnectionError - An event containing what was being sent to the server and what
was returnedpublic void pushInvalidContent(PushConnection pushConnection, String message)
ConnectionStateHandlerpushInvalidContent in interface ConnectionStateHandlerpushConnection - the push connection which was usedmessage - the received messagepublic void xhrInvalidStatusCode(XhrConnectionError xhrConnectionError)
ConnectionStateHandlerxhrInvalidStatusCode in interface ConnectionStateHandlerxhrConnectionError - An event containing what was being sent to the server and what
was returnedprotected void handleUnauthorized(XhrConnectionError xhrConnectionError)
protected void handleCommunicationError(String details, int statusCode)
details - message details or null if there are no detailsstatusCode - the status codepublic void xhrOk()
ConnectionStateHandlerxhrOk in interface ConnectionStateHandlerpublic void pushOk(PushConnection pushConnection)
ConnectionStateHandlerpushOk in interface ConnectionStateHandlerpushConnection - The push connection which was establishedpublic void pushScriptLoadError(String resourceUrl)
ConnectionStateHandlerpushScriptLoadError in interface ConnectionStateHandlerresourceUrl - The URL which was used for loading the scriptpublic void pushNotConnected(elemental.json.JsonObject payload)
ConnectionStateHandlerpushNotConnected in interface ConnectionStateHandlerpayload - The payload to send to the serverpublic void pushReconnectPending(PushConnection pushConnection)
ConnectionStateHandlerpushReconnectPending in interface ConnectionStateHandlerpushConnection - The push connection which will be reconnectedpublic void pushError(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
ConnectionStateHandlerpushError in interface ConnectionStateHandlerpushConnection - The push connection where the error occurredresponse - An object containing response datapublic void pushClientTimeout(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
ConnectionStateHandlerpushClientTimeout in interface ConnectionStateHandlerpushConnection - The push connection which timed outresponse - An object containing response datapublic void pushClosed(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
ConnectionStateHandlerpushClosed in interface ConnectionStateHandlerpushConnection - The push connection which was closedresponse - An object containing response dataCopyright © 2000–2018 Vaadin Ltd. All rights reserved.