You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConnectionStateHandler.java 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.communication;
  17. import com.google.gwt.core.client.JavaScriptObject;
  18. import com.google.gwt.http.client.Request;
  19. import com.google.gwt.http.client.Response;
  20. import com.vaadin.client.ApplicationConnection;
  21. import elemental.json.JsonObject;
  22. /**
  23. * Interface for handling problems and other events which occur during
  24. * communication with the server.
  25. *
  26. * The handler is responsible for handling any problem in XHR, heartbeat and
  27. * push connections in a way it sees fit. The default implementation is
  28. * {@link DefaultConnectionStateHandler}.
  29. *
  30. * @since 7.6
  31. * @author Vaadin Ltd
  32. */
  33. public interface ConnectionStateHandler {
  34. /**
  35. * Sets the application connection this instance is connected to. Called
  36. * internally by the framework.
  37. *
  38. * @param connection
  39. * the application connection this instance is connected to
  40. */
  41. void setConnection(ApplicationConnection connection);
  42. /**
  43. * Called when an exception occurs during a {@link Heartbeat} request.
  44. *
  45. * @param request
  46. * The heartbeat request
  47. * @param exception
  48. * The exception which occurred
  49. */
  50. void heartbeatException(Request request, Throwable exception);
  51. /**
  52. * Called when a heartbeat request returns a status code other than OK
  53. * (200).
  54. *
  55. * @param request
  56. * The heartbeat request
  57. * @param response
  58. * The heartbeat response
  59. */
  60. void heartbeatInvalidStatusCode(Request request, Response response);
  61. /**
  62. * Called when a {@link Heartbeat} request succeeds.
  63. */
  64. void heartbeatOk();
  65. /**
  66. * Called when the push connection to the server is closed. This might
  67. * result in the push connection trying a fallback connection method, trying
  68. * to reconnect to the server or might just be an indication that the
  69. * connection was intentionally closed ("unsubscribe"),
  70. *
  71. * @param pushConnection
  72. * The push connection which was closed
  73. * @param responseObject
  74. * An object containing response data
  75. */
  76. void pushClosed(PushConnection pushConnection,
  77. JavaScriptObject responseObject);
  78. /**
  79. * Called when a client side timeout occurs before a push connection to the
  80. * server completes.
  81. *
  82. * The client side timeout causes a disconnection of the push connection and
  83. * no reconnect will be attempted after this method is called,
  84. *
  85. * @param pushConnection
  86. * The push connection which timed out
  87. * @param response
  88. * An object containing response data
  89. */
  90. void pushClientTimeout(PushConnection pushConnection,
  91. JavaScriptObject response);
  92. /**
  93. * Called when a fatal error fatal error occurs in the push connection.
  94. *
  95. * The push connection will not try to recover from this situation itself
  96. * and typically the problem handler should not try to do automatic recovery
  97. * either. The cause can be e.g. maximum number of reconnection attempts
  98. * have been reached, neither the selected transport nor the fallback
  99. * transport can be used or similar.
  100. *
  101. * @param pushConnection
  102. * The push connection where the error occurred
  103. * @param response
  104. * An object containing response data
  105. */
  106. void pushError(PushConnection pushConnection, JavaScriptObject response);
  107. /**
  108. * Called when the push connection has lost the connection to the server and
  109. * will proceed to try to re-establish the connection.
  110. *
  111. * @param pushConnection
  112. * The push connection which will be reconnected
  113. */
  114. void pushReconnectPending(PushConnection pushConnection);
  115. /**
  116. * Called when the push connection to the server has been established.
  117. *
  118. * @param pushConnection
  119. * The push connection which was established
  120. */
  121. void pushOk(PushConnection pushConnection);
  122. /**
  123. * Called when the required push script could not be loaded.
  124. *
  125. * @param resourceUrl
  126. * The URL which was used for loading the script
  127. */
  128. void pushScriptLoadError(String resourceUrl);
  129. /**
  130. * Called when an exception occurs during an XmlHttpRequest request to the
  131. * server.
  132. *
  133. * @param xhrConnectionError
  134. * An event containing what was being sent to the server and what
  135. * exception occurred
  136. */
  137. void xhrException(XhrConnectionError xhrConnectionError);
  138. /**
  139. * Called when invalid content (not JSON) was returned from the server as
  140. * the result of an XmlHttpRequest request.
  141. *
  142. * @param xhrConnectionError
  143. * The error containing what was being sent to the server and
  144. * what was returned
  145. */
  146. void xhrInvalidContent(XhrConnectionError xhrConnectionError);
  147. /**
  148. * Called when invalid status code (not 200) was returned by the server as
  149. * the result of an XmlHttpRequest.
  150. *
  151. * @param xhrConnectionError
  152. * The error containing what was being sent to the server and
  153. * what was returned
  154. */
  155. void xhrInvalidStatusCode(XhrConnectionError xhrConnectionError);
  156. /**
  157. * Called whenever a XmlHttpRequest to the server completes successfully.
  158. */
  159. void xhrOk();
  160. /**
  161. * Called when a message is to be sent to the server through the push
  162. * channel but the push channel is not connected.
  163. *
  164. * @param payload
  165. * The payload to send to the server
  166. */
  167. void pushNotConnected(JsonObject payload);
  168. /**
  169. * Called when invalid content (not JSON) was pushed from the server through
  170. * the push connection.
  171. *
  172. * @param pushConnection
  173. * The push connection used
  174. * @param message
  175. * The message which was sent to the server
  176. */
  177. void pushInvalidContent(PushConnection pushConnection, String message);
  178. /**
  179. * Called when some part of the reconnect dialog configuration has been
  180. * changed.
  181. */
  182. void configurationUpdated();
  183. }