Package com.microsoft.azure.relay
Class HybridConnectionListener
java.lang.Object
com.microsoft.azure.relay.HybridConnectionListener
- All Implemented Interfaces:
RelayTraceSource,AutoCloseable
-
Constructor Summary
ConstructorsConstructorDescriptionHybridConnectionListener(String connectionString) Create a new HybridConnectionListener instance for accepting HybridConnections.HybridConnectionListener(String connectionString, String path) Creates a new instance of HybridConnectionListener from a connection string and the specified HybridConection path.HybridConnectionListener(URI address, TokenProvider tokenProvider) Create a new HybridConnectionListener instance for accepting HybridConnections. -
Method Summary
Modifier and TypeMethodDescriptionAsynchronously wait for a websocket connection from the sender to be connected.voidclose()Disconnects all connections from the cloud servicecloseAsync(Duration timeout) Disconnects all connections from the cloud service within the timeoutThe address on which to listen for HybridConnections.Returns the handler that will be run when the listener disconnects unexpectedly.intReturns the handler which will be run after the listener has become offline.Returns the handler that will be run after the listener has established connection to the cloud service.The TokenProvider for authenticating this HybridConnection listener.The TrackingContext for this listener.booleanisOnline()Opens the HybridConnectionListener and registers it as a listener in ServiceBus.Opens the HybridConnectionListener and registers it as a listener in ServiceBus.voidsetAcceptHandler(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.voidsetConnectingHandler(Consumer<Throwable> onConnecting) Sets the handler that will be run when the listener disconnects unexpectedly.voidsetMaxWebSocketBufferSize(int maxWebSocketBufferSize) voidsetOfflineHandler(Consumer<Throwable> onOffline) Sets the handler which will be run after the listener has become offline.voidsetOnlineHandler(Runnable onOnline) Sets the handler that will be run after the listener has established connection to the cloud service.voidsetRequestHandler(Consumer<RelayedHttpListenerContext> requestHandler) Install a custom handler which will be run upon receiving a HTTP request.toString()
-
Constructor Details
-
HybridConnectionListener
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
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
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
-
setAcceptHandler
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
-
setRequestHandler
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
The address on which to listen for HybridConnections. This address should be of the format "sb://contoso.servicebus.windows.net/yourhybridconnection". -
getTokenProvider
The TokenProvider for authenticating this HybridConnection listener. -
getTrackingContext
The TrackingContext for this listener.- Specified by:
getTrackingContextin interfaceRelayTraceSource
-
getOperationTimeout
-
getMaxWebSocketBufferSize
public int getMaxWebSocketBufferSize() -
setMaxWebSocketBufferSize
public void setMaxWebSocketBufferSize(int maxWebSocketBufferSize) -
getConnectingHandler
Returns the handler that will be run when the listener disconnects unexpectedly. The listener will attempt to reconnect after this handler runs. -
setConnectingHandler
Sets the handler that will be run when the listener disconnects unexpectedly. The listener will attempt to reconnect after this handler runs. -
getOfflineHandler
Returns the handler which will be run after the listener has become offline. Reconnection will not be attempted after this handler. -
setOfflineHandler
Sets the handler which will be run after the listener has become offline. Reconnection will not be attempted after this handler. -
getOnlineHandler
Returns the handler that will be run after the listener has established connection to the cloud service. -
setOnlineHandler
Sets the handler that will be run after the listener has established connection to the cloud service. -
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
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
Disconnects all connections from the cloud service- Returns:
- A CompletableFuture which completes when all connections are disconnected with the cloud service
-
closeAsync
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:
closein interfaceAutoCloseable
-
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
- Specified by:
toStringin interfaceRelayTraceSource- Overrides:
toStringin classObject
-