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.3KB

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