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.

PushConnection.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright 2000-2021 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.user.client.Command;
  18. import com.vaadin.client.ApplicationConnection;
  19. import com.vaadin.shared.ui.ui.UIState.PushConfigurationState;
  20. import elemental.json.JsonObject;
  21. /**
  22. * Represents the client-side endpoint of a bidirectional ("push") communication
  23. * channel. Can be used to send UIDL request messages to the server and to
  24. * receive UIDL messages from the server (either asynchronously or as a response
  25. * to a UIDL request.) Delegates the UIDL handling to the
  26. * {@link ApplicationConnection}.
  27. *
  28. * @author Vaadin Ltd
  29. * @since 7.1
  30. */
  31. public interface PushConnection {
  32. /**
  33. * Two-phase construction to allow using GWT.create().
  34. *
  35. * @param connection
  36. * The ApplicationConnection
  37. */
  38. public void init(ApplicationConnection connection,
  39. PushConfigurationState pushConfigurationState);
  40. /**
  41. * Pushes a message to the server. Will throw an exception if the connection
  42. * is not active (see {@link #isActive()}).
  43. * <p>
  44. * Implementation detail: If the push connection is not connected and the
  45. * message can thus not be sent, the implementation must call
  46. * {@link ConnectionStateHandler#pushNotConnected(JsonObject)}, which will
  47. * retry the send later.
  48. * <p>
  49. * This method must not be called if the push connection is not
  50. * bidirectional (if {@link #isBidirectional()} returns false)
  51. *
  52. * @param payload
  53. * the payload to push
  54. * @throws IllegalStateException
  55. * if this connection is not active
  56. *
  57. * @see #isActive()
  58. */
  59. public void push(JsonObject payload);
  60. /**
  61. * Checks whether this push connection is in a state where it can push
  62. * messages to the server. A connection is active until
  63. * {@link #disconnect(Command)} has been called.
  64. *
  65. * @return <code>true</code> if this connection can accept new messages;
  66. * <code>false</code> if this connection is disconnected or
  67. * disconnecting.
  68. */
  69. public boolean isActive();
  70. /**
  71. * Closes the push connection. To ensure correct message delivery order, new
  72. * messages should not be sent using any other channel until it has been
  73. * confirmed that all messages pending for this connection have been
  74. * delivered. The provided command callback is invoked when messages can be
  75. * passed using some other communication channel.
  76. * <p>
  77. * After this method has been called, {@link #isActive()} returns
  78. * <code>false</code>. Calling this method for a connection that is no
  79. * longer active will throw an exception.
  80. *
  81. * @param command
  82. * callback command invoked when the connection has been properly
  83. * disconnected
  84. * @throws IllegalStateException
  85. * if this connection is not active
  86. */
  87. public void disconnect(Command command);
  88. /**
  89. * Returns a human readable string representation of the transport type used
  90. * to communicate with the server.
  91. *
  92. * @since 7.1
  93. * @return A human readable string representation of the transport type
  94. */
  95. public String getTransportType();
  96. /**
  97. * Checks whether this push connection should be used for communication in
  98. * both directions or if an XHR should be used for client to server
  99. * communication.
  100. *
  101. * A bidirectional push connection must be able to reliably inform about its
  102. * connection state.
  103. *
  104. * @since 7.6
  105. * @return true if the push connection should be used for messages in both
  106. * directions, false if it should only be used for server to client
  107. * messages
  108. */
  109. public boolean isBidirectional();
  110. }