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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright 2000-2016 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 (200)
  53. *
  54. * @param request
  55. * The heartbeat request
  56. * @param response
  57. * The heartbeat response
  58. */
  59. void heartbeatInvalidStatusCode(Request request, Response response);
  60. /**
  61. * Called when a {@link Heartbeat} request succeeds
  62. */
  63. void heartbeatOk();
  64. /**
  65. * Called when the push connection to the server is closed. This might
  66. * result in the push connection trying a fallback connection method, trying
  67. * to reconnect to the server or might just be an indication that the
  68. * connection was intentionally closed ("unsubscribe"),
  69. *
  70. * @param pushConnection
  71. * The push connection which was closed
  72. * @param response
  73. * An object containing response data
  74. */
  75. void pushClosed(PushConnection pushConnection,
  76. JavaScriptObject responseObject);
  77. /**
  78. * Called when a client side timeout occurs before a push connection to the
  79. * server completes.
  80. *
  81. * The client side timeout causes a disconnection of the push connection and
  82. * no reconnect will be attempted after this method is called,
  83. *
  84. * @param pushConnection
  85. * The push connection which timed out
  86. * @param response
  87. * An object containing response data
  88. */
  89. void pushClientTimeout(PushConnection pushConnection,
  90. JavaScriptObject response);
  91. /**
  92. * Called when a fatal error fatal error occurs in the push connection.
  93. *
  94. * The push connection will not try to recover from this situation itself
  95. * and typically the problem handler should not try to do automatic recovery
  96. * either. The cause can be e.g. maximum number of reconnection attempts
  97. * have been reached, neither the selected transport nor the fallback
  98. * transport can be used or similar.
  99. *
  100. * @param pushConnection
  101. * The push connection where the error occurred
  102. * @param response
  103. * An object containing response data
  104. */
  105. void pushError(PushConnection pushConnection, JavaScriptObject response);
  106. /**
  107. * Called when the push connection has lost the connection to the server and
  108. * will proceed to try to re-establish the connection
  109. *
  110. * @param pushConnection
  111. * The push connection which will be reconnected
  112. */
  113. void pushReconnectPending(PushConnection pushConnection);
  114. /**
  115. * Called when the push connection to the server has been established.
  116. *
  117. * @param pushConnection
  118. * The push connection which was established
  119. */
  120. void pushOk(PushConnection pushConnection);
  121. /**
  122. * Called when the required push script could not be loaded
  123. *
  124. * @param resourceUrl
  125. * The URL which was used for loading the script
  126. */
  127. void pushScriptLoadError(String resourceUrl);
  128. /**
  129. * Called when an exception occurs during an XmlHttpRequest request to the
  130. * server.
  131. *
  132. * @param xhrConnectionError
  133. * An event containing what was being sent to the server and what
  134. * exception occurred
  135. */
  136. void xhrException(XhrConnectionError xhrConnectionError);
  137. /**
  138. * Called when invalid content (not JSON) was returned from the server as
  139. * the result of an XmlHttpRequest request
  140. *
  141. * @param communicationProblemEvent
  142. * An event containing what was being sent to the server and what
  143. * was returned
  144. */
  145. void xhrInvalidContent(XhrConnectionError xhrConnectionError);
  146. /**
  147. * Called when invalid status code (not 200) was returned by the server as
  148. * the result of an XmlHttpRequest.
  149. *
  150. * @param communicationProblemEvent
  151. * An event containing what was being sent to the server and what
  152. * was returned
  153. */
  154. void xhrInvalidStatusCode(XhrConnectionError xhrConnectionError);
  155. /**
  156. * Called whenever a XmlHttpRequest to the server completes successfully
  157. */
  158. void xhrOk();
  159. /**
  160. * Called when a message is to be sent to the server through the push
  161. * channel but the push channel is not connected
  162. *
  163. * @param payload
  164. * The payload to send to the server
  165. */
  166. void pushNotConnected(JsonObject payload);
  167. /**
  168. * Called when invalid content (not JSON) was pushed from the server through
  169. * the push connection
  170. *
  171. * @param communicationProblemEvent
  172. * An event containing what was being sent to the server and what
  173. * was returned
  174. */
  175. void pushInvalidContent(PushConnection pushConnection, String message);
  176. /**
  177. * Called when some part of the reconnect dialog configuration has been
  178. * changed.
  179. */
  180. void configurationUpdated();
  181. }