Package io.muserver

Class WebSocketHandlerBuilder

    • Constructor Detail

      • WebSocketHandlerBuilder

        public WebSocketHandlerBuilder()
    • Method Detail

      • withWebSocketFactory

        public WebSocketHandlerBuilder withWebSocketFactory​(MuWebSocketFactory factory)

        Sets the factory that decides whether to create a websocket connection for a request.

        Note that the factory will only be called if the request is a websocket upgrade request.

        Parameters:
        factory - A factory that creates websockets, or returns null if the websocket connection shouldn't be created.
        Returns:
        This builder
      • withPath

        public WebSocketHandlerBuilder withPath​(java.lang.String path)
        Sets the path to listen on for this handler. Note that an alternative to setting a path is to look at MuRequest.uri() in the MuWebSocketFactory and decide whether to handle the request or not.

        Note: if this handler is nested within a ContextHandler, then this is the relative path.

        Parameters:
        path - The path of this web socket endpoint.
        Returns:
        This builder
      • withIdleReadTimeout

        public WebSocketHandlerBuilder withIdleReadTimeout​(long duration,
                                                           java.util.concurrent.TimeUnit unit)
        Sets the idle timeout. If no messages are received within this time then the connection is closed.

        The default is 5 minutes.

        Parameters:
        duration - The allowed timeout duration, or 0 to disable timeouts.
        unit - The unit of the duration.
        Returns:
        This builder
      • withPingSentAfterNoWritesFor

        public WebSocketHandlerBuilder withPingSentAfterNoWritesFor​(int duration,
                                                                    java.util.concurrent.TimeUnit unit)
        Sets the amount of time to wait before sending a ping message if no messages having been sent.

        The default is 30 seconds.

        Parameters:
        duration - The allowed timeout duration, or 0 to disable timeouts.
        unit - The unit of the duration.
        Returns:
        This builder
      • withMaxFramePayloadLength

        public WebSocketHandlerBuilder withMaxFramePayloadLength​(int maxFramePayloadLength)
        Sets the maximum size in bytes that a frame can be. Defaults to 65536
        Parameters:
        maxFramePayloadLength - The maximum allowed size in bytes of websocket frames.
        Returns:
        This builder
      • webSocketHandler

        public static WebSocketHandlerBuilder webSocketHandler()
        Creates a new handler builder.
        Returns:
        A new handler builder
      • webSocketHandler

        public static WebSocketHandlerBuilder webSocketHandler​(MuWebSocketFactory factory)
        Creates a new handler builder with the given factory.
        Parameters:
        factory - The factory to use.
        Returns:
        A new handler builder.