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.

CommunicationProblemHandler.java 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 which occur during communications with the
  23. * 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 used is
  27. * {@link DefaultCommunicationProblemHandler}, which considers all problems
  28. * terminal
  29. *
  30. * @since 7.6
  31. * @author Vaadin Ltd
  32. */
  33. public interface CommunicationProblemHandler {
  34. /**
  35. * Sets the application connection this handler is connected to. Called
  36. * internally by the framework.
  37. *
  38. * @param connection
  39. * the application connection this handler 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. * @return true if a new heartbeat should be sent, false if no further
  50. * heartbeats should be sent
  51. */
  52. boolean heartbeatException(Request request, Throwable exception);
  53. /**
  54. * Called when a heartbeat request returns a status code other than OK (200)
  55. *
  56. * @param request
  57. * The heartbeat request
  58. * @param response
  59. * The heartbeat response
  60. * @return true if a new heartbeat should be sent, false if no further
  61. * heartbeats should be sent
  62. */
  63. boolean heartbeatInvalidStatusCode(Request request, Response response);
  64. /**
  65. * Called when a {@link Heartbeat} request succeeds
  66. */
  67. void heartbeatOk();
  68. /**
  69. * Called when the push connection to the server is closed. This might
  70. * result in the push connection trying a fallback connection method, trying
  71. * to reconnect to the server or might just be an indication that the
  72. * connection was intentionally closed ("unsubscribe"),
  73. *
  74. * @param pushConnection
  75. * The push connection which was closed
  76. */
  77. void pushClosed(PushConnection pushConnection);
  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. */
  88. void pushClientTimeout(PushConnection pushConnection);
  89. /**
  90. * Called when a fatal error fatal error occurs in the push connection.
  91. *
  92. * The push connection will not try to recover from this situation itself
  93. * and typically the problem handler should not try to do automatic recovery
  94. * either. The cause can be e.g. maximum number of reconnection attempts
  95. * have been reached, neither the selected transport nor the fallback
  96. * transport can be used or similar.
  97. *
  98. * @param pushConnection
  99. * The push connection where the error occurred
  100. */
  101. void pushError(PushConnection pushConnection);
  102. /**
  103. * Called when the push connection has lost the connection to the server and
  104. * will proceed to try to re-establish the connection
  105. *
  106. * @param pushConnection
  107. * The push connection which will be reconnected
  108. */
  109. void pushReconnectPending(PushConnection pushConnection);
  110. /**
  111. * Called when the push connection to the server has been established.
  112. *
  113. * @param pushConnection
  114. * The push connection which was established
  115. */
  116. void pushOk(PushConnection pushConnection);
  117. /**
  118. * Called when the required push script could not be loaded
  119. *
  120. * @param resourceUrl
  121. * The URL which was used for loading the script
  122. */
  123. void pushScriptLoadError(String resourceUrl);
  124. /**
  125. * Called when an exception occurs during an XmlHttpRequest request to the
  126. * server.
  127. *
  128. * @param communicationProblemEvent
  129. * An event containing what was being sent to the server and what
  130. * exception occurred
  131. */
  132. void xhrException(CommunicationProblemEvent communicationProblemEvent);
  133. /**
  134. * Called when invalid content (not JSON) was returned from the server as
  135. * the result of an XmlHttpRequest request
  136. *
  137. * @param communicationProblemEvent
  138. * An event containing what was being sent to the server and what
  139. * was returned
  140. */
  141. void xhrInvalidContent(CommunicationProblemEvent communicationProblemEvent);
  142. /**
  143. * Called when invalid status code (not 200) was returned by the server as
  144. * the result of an XmlHttpRequest.
  145. *
  146. * @param communicationProblemEvent
  147. * An event containing what was being sent to the server and what
  148. * was returned
  149. */
  150. void xhrInvalidStatusCode(CommunicationProblemEvent problemEvent);
  151. /**
  152. * Called whenever a XmlHttpRequest to the server completes successfully
  153. */
  154. void xhrOk();
  155. /**
  156. * Called when a message is to be sent to the server through the push
  157. * channel but the push channel is not connected
  158. *
  159. * @param payload
  160. * The payload to send to the server
  161. */
  162. void pushNotConnected(JsonObject payload);
  163. /**
  164. * Called when invalid content (not JSON) was pushed from the server through
  165. * the push connection
  166. *
  167. * @param communicationProblemEvent
  168. * An event containing what was being sent to the server and what
  169. * was returned
  170. */
  171. void pushInvalidContent(PushConnection pushConnection, String message);
  172. }