Class WebSocketChannel

java.lang.Object
com.microsoft.azure.relay.WebSocketChannel
All Implemented Interfaces:
HybridConnectionChannel, Closeable, AutoCloseable, Channel

public class WebSocketChannel extends Object implements HybridConnectionChannel
  • Method Details

    • getTrackingContext

      public TrackingContext getTrackingContext()
      Specified by:
      getTrackingContext in interface HybridConnectionChannel
    • isOpen

      public boolean isOpen()
      Checks whether the websocket connection is still open.
      Specified by:
      isOpen in interface Channel
    • close

      public void close() throws IOException
      Closes the websocket connection. Blocks until the connection is completely closed.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Channel
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • closeAsync

      public CompletableFuture<Void> closeAsync()
      Closes the connection with the remote websocket
      Specified by:
      closeAsync in interface HybridConnectionChannel
      Returns:
      Returns a CompletableFuture which completes when the connection is completely closed.
    • closeAsync

      public CompletableFuture<Void> closeAsync(javax.websocket.CloseReason reason)
      Closes the connection with the remote websocket with a given CloseReason
      Specified by:
      closeAsync in interface HybridConnectionChannel
      Parameters:
      reason - The CloseReason to be given for this operation. For details please see javax.websocket.CloseReason.
      Returns:
      Returns a CompletableFuture which completes when the connection is completely closed.
    • readTextAsync

      public CompletableFuture<String> readTextAsync()
      Receives text messages asynchronously.
      Returns:
      Returns a CompletableFuture which completes when websocket receives text messages.
    • readAsync

      public CompletableFuture<ByteBuffer> readAsync()
      Receives byte messages from the remote sender asynchronously.
      Specified by:
      readAsync in interface HybridConnectionChannel
      Returns:
      Returns a CompletableFuture of the bytes which completes when websocket receives the entire message.
    • readAsync

      public CompletableFuture<ByteBuffer> readAsync(Duration timeout)
      Receives byte messages from the remote sender asynchronously within a given timeout.
      Specified by:
      readAsync in interface HybridConnectionChannel
      Parameters:
      timeout - The timeout duration for this operation.
      Returns:
      Returns a CompletableFuture of the bytes which completes when websocket receives the entire message.
    • writeAsync

      public CompletableFuture<Void> writeAsync(ByteBuffer data)
      Sends the data to the remote endpoint as binary.
      Specified by:
      writeAsync in interface HybridConnectionChannel
      Parameters:
      data - Message to be sent.
      Returns:
      A CompletableFuture which completes when websocket finishes sending the bytes.
    • writeAsync

      public CompletableFuture<Void> writeAsync(ByteBuffer data, Duration timeout)
      Sends the data to the remote endpoint within a timeout as binary.
      Specified by:
      writeAsync in interface HybridConnectionChannel
      Parameters:
      data - Message to be sent.
      timeout - The timeout to connect to send the data within. May be null to indicate no timeout limit.
      Returns:
      A CompletableFuture which completes when websocket finishes sending the bytes.
    • writeTextAsync

      public CompletableFuture<Void> writeTextAsync(String textData, Duration timeout)
      Sends the text data to the remote endpoint within a timeout in one of the WriteModes.
      Parameters:
      textData - Text message to be sent.
      timeout - The timeout to connect to send the data within. May be null to indicate no timeout limit.
      Returns:
      A CompletableFuture which completes when websocket finishes sending the data.