Class HybridConnectionListener

java.lang.Object
com.microsoft.azure.relay.HybridConnectionListener
All Implemented Interfaces:
RelayTraceSource, AutoCloseable

public class HybridConnectionListener extends Object implements RelayTraceSource, AutoCloseable
  • Constructor Details

    • HybridConnectionListener

      public HybridConnectionListener(URI address, TokenProvider tokenProvider)
      Create a new HybridConnectionListener instance for accepting HybridConnections.
      Parameters:
      address - The address on which to listen for HybridConnections. This address should be of the format "sb://contoso.servicebus.windows.net/yourhybridconnection".
      tokenProvider - The TokenProvider for connecting this listener to ServiceBus.
    • HybridConnectionListener

      public HybridConnectionListener(String connectionString) throws URISyntaxException
      Create a new HybridConnectionListener instance for accepting HybridConnections.
      Parameters:
      connectionString - The connection string to use. This connection string must include the EntityPath property.
      Throws:
      URISyntaxException - Thrown when the format of the connectionSring is incorrect
    • HybridConnectionListener

      public HybridConnectionListener(String connectionString, String path) throws URISyntaxException
      Creates a new instance of HybridConnectionListener from a connection string and the specified HybridConection path. Use this overload only when the connection string does not use the RelayConnectionStringBuilder.EntityPath property.
      Parameters:
      connectionString - The connection string to use. This connection string must not include the EntityPath property.
      path - The path to the HybridConnection.
      Throws:
      URISyntaxException - Thrown when the format of the connectionSring is incorrect
  • Method Details

    • isOnline

      public boolean isOnline()
    • getAcceptHandler

      public Function<RelayedHttpListenerContext,Boolean> getAcceptHandler()
    • setAcceptHandler

      public void setAcceptHandler(Function<RelayedHttpListenerContext,Boolean> acceptHandler)
      Installing a custom handler which can inspect request headers, control response headers, decide whether to accept or reject a websocket upgrade request, and control the status code/description if rejecting. If choosing to reject the websocket connection request, the response code and description can be set through the response object of the RelayedHttpListenerContext instance provided.
      Parameters:
      acceptHandler - A Function which takes in the websocket connection request context and returns true/false if the request should be accepted/rejected
    • getRequestHandler

      public Consumer<RelayedHttpListenerContext> getRequestHandler()
    • setRequestHandler

      public void setRequestHandler(Consumer<RelayedHttpListenerContext> requestHandler)
      Install a custom handler which will be run upon receiving a HTTP request. The corresponding HTTP response can be set through the response object of the given context instance.
      Parameters:
      requestHandler - A Consumer which takes in the incoming HTTP request context
    • getAddress

      public URI getAddress()
      The address on which to listen for HybridConnections. This address should be of the format "sb://contoso.servicebus.windows.net/yourhybridconnection".
    • getTokenProvider

      public TokenProvider getTokenProvider()
      The TokenProvider for authenticating this HybridConnection listener.
    • getTrackingContext

      public TrackingContext getTrackingContext()
      The TrackingContext for this listener.
      Specified by:
      getTrackingContext in interface RelayTraceSource
    • getOperationTimeout

      public Duration getOperationTimeout()
    • getMaxWebSocketBufferSize

      public int getMaxWebSocketBufferSize()
    • setMaxWebSocketBufferSize

      public void setMaxWebSocketBufferSize(int maxWebSocketBufferSize)
    • getConnectingHandler

      public Consumer<Throwable> getConnectingHandler()
      Returns the handler that will be run when the listener disconnects unexpectedly. The listener will attempt to reconnect after this handler runs.
    • setConnectingHandler

      public void setConnectingHandler(Consumer<Throwable> onConnecting)
      Sets the handler that will be run when the listener disconnects unexpectedly. The listener will attempt to reconnect after this handler runs.
    • getOfflineHandler

      public Consumer<Throwable> getOfflineHandler()
      Returns the handler which will be run after the listener has become offline. Reconnection will not be attempted after this handler.
    • setOfflineHandler

      public void setOfflineHandler(Consumer<Throwable> onOffline)
      Sets the handler which will be run after the listener has become offline. Reconnection will not be attempted after this handler.
    • getOnlineHandler

      public Runnable getOnlineHandler()
      Returns the handler that will be run after the listener has established connection to the cloud service.
    • setOnlineHandler

      public void setOnlineHandler(Runnable onOnline)
      Sets the handler that will be run after the listener has established connection to the cloud service.
    • openAsync

      public CompletableFuture<Void> openAsync()
      Opens the HybridConnectionListener and registers it as a listener in ServiceBus.
      Returns:
      A CompletableFuture which completes when the control connection is established with the cloud service
    • openAsync

      public CompletableFuture<Void> openAsync(Duration timeout)
      Opens the HybridConnectionListener and registers it as a listener in ServiceBus.
      Parameters:
      timeout - The timeout duration for this openAsync operation
      Returns:
      A CompletableFuture which completes when the control connection is established with the cloud service
    • closeAsync

      public CompletableFuture<Void> closeAsync()
      Disconnects all connections from the cloud service
      Returns:
      A CompletableFuture which completes when all connections are disconnected with the cloud service
    • closeAsync

      public CompletableFuture<Void> closeAsync(Duration timeout)
      Disconnects all connections from the cloud service within the timeout
      Parameters:
      timeout - The timeout duration for this closeAsync operation
      Returns:
      A CompletableFuture which completes when all connections are disconnected with the cloud service
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • acceptConnectionAsync

      public CompletableFuture<HybridConnectionChannel> acceptConnectionAsync()
      Asynchronously wait for a websocket connection from the sender to be connected. When the listener closes, all pending CompletableFutures that are still waiting to accept a connection will complete with null.
      Returns:
      A CompletableFuture which completes when a websocket connection from the sender is established.
    • toString

      public String toString()
      Specified by:
      toString in interface RelayTraceSource
      Overrides:
      toString in class Object