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 enum 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    protected void
    doReconnect(elemental.json.JsonObject payload)
    Re-sends the payload to the server (if not null) or re-sends a heartbeat request immediately.
    Returns the connection this handler is connected to.
    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
    Called when we should give up trying to reconnect and let the user decide how to continue.
    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(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)
     
    void
    heartbeatException(com.google.gwt.http.client.Request request, Throwable exception)
     
    void
    heartbeatInvalidStatusCode(com.google.gwt.http.client.Request request, com.google.gwt.http.client.Response response)
     
    void
     
    protected void
    Called when the reconnect dialog should be hidden.
    protected boolean
    Checks if the reconnect dialog is visible to the user.
    void
    pushClientTimeout(com.vaadin.client.communication.PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
     
    void
    pushClosed(com.vaadin.client.communication.PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
     
    void
    pushError(com.vaadin.client.communication.PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
     
    void
    pushInvalidContent(com.vaadin.client.communication.PushConnection pushConnection, String message)
     
    void
    pushNotConnected(elemental.json.JsonObject payload)
     
    void
    pushOk(com.vaadin.client.communication.PushConnection pushConnection)
     
    void
    pushReconnectPending(com.vaadin.client.communication.PushConnection pushConnection)
     
    void
     
    protected void
    scheduleReconnect(elemental.json.JsonObject payload)
    Called after a problem occurred.
    void
     
    protected void
    Called when the reconnect dialog should be shown.
    protected void
    Called whenever a reconnect attempt fails to allow updating of dialog contents.
    void
    xhrException(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)
     
    void
    xhrInvalidContent(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)
     
    void
    xhrInvalidStatusCode(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)
     
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultConnectionStateHandler

      public DefaultConnectionStateHandler()
  • Method Details

    • setConnection

      public void setConnection(ApplicationConnection connection)
      Specified by:
      setConnection in interface com.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:
      xhrException in interface com.vaadin.client.communication.ConnectionStateHandler
    • heartbeatException

      public void heartbeatException(com.google.gwt.http.client.Request request, Throwable exception)
      Specified by:
      heartbeatException in interface com.vaadin.client.communication.ConnectionStateHandler
    • heartbeatInvalidStatusCode

      public void heartbeatInvalidStatusCode(com.google.gwt.http.client.Request request, com.google.gwt.http.client.Response response)
      Specified by:
      heartbeatInvalidStatusCode in interface com.vaadin.client.communication.ConnectionStateHandler
    • heartbeatOk

      public void heartbeatOk()
      Specified by:
      heartbeatOk in interface com.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 detected
      payload - 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:
      configurationUpdated in interface com.vaadin.client.communication.ConnectionStateHandler
    • xhrInvalidContent

      public void xhrInvalidContent(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)
      Specified by:
      xhrInvalidContent in interface com.vaadin.client.communication.ConnectionStateHandler
    • pushInvalidContent

      public void pushInvalidContent(com.vaadin.client.communication.PushConnection pushConnection, String message)
      Specified by:
      pushInvalidContent in interface com.vaadin.client.communication.ConnectionStateHandler
    • xhrInvalidStatusCode

      public void xhrInvalidStatusCode(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)
      Specified by:
      xhrInvalidStatusCode in interface com.vaadin.client.communication.ConnectionStateHandler
    • handleUnauthorized

      protected void handleUnauthorized(com.vaadin.client.communication.XhrConnectionError xhrConnectionError)
    • xhrOk

      public void xhrOk()
      Specified by:
      xhrOk in interface com.vaadin.client.communication.ConnectionStateHandler
    • pushOk

      public void pushOk(com.vaadin.client.communication.PushConnection pushConnection)
      Specified by:
      pushOk in interface com.vaadin.client.communication.ConnectionStateHandler
    • pushScriptLoadError

      public void pushScriptLoadError(String resourceUrl)
      Specified by:
      pushScriptLoadError in interface com.vaadin.client.communication.ConnectionStateHandler
    • pushNotConnected

      public void pushNotConnected(elemental.json.JsonObject payload)
      Specified by:
      pushNotConnected in interface com.vaadin.client.communication.ConnectionStateHandler
    • pushReconnectPending

      public void pushReconnectPending(com.vaadin.client.communication.PushConnection pushConnection)
      Specified by:
      pushReconnectPending in interface com.vaadin.client.communication.ConnectionStateHandler
    • pushError

      public void pushError(com.vaadin.client.communication.PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
      Specified by:
      pushError in interface com.vaadin.client.communication.ConnectionStateHandler
    • pushClientTimeout

      public void pushClientTimeout(com.vaadin.client.communication.PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
      Specified by:
      pushClientTimeout in interface com.vaadin.client.communication.ConnectionStateHandler
    • pushClosed

      public void pushClosed(com.vaadin.client.communication.PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
      Specified by:
      pushClosed in interface com.vaadin.client.communication.ConnectionStateHandler