public class WebSocketHandlerBuilder extends Object implements MuHandlerBuilder<WebSocketHandler>
Used to create handlers for web sockets.
Constructor and Description |
---|
WebSocketHandlerBuilder() |
Modifier and Type | Method and Description |
---|---|
WebSocketHandler |
build()
Creates the websocket handler.
|
static WebSocketHandlerBuilder |
webSocketHandler()
Creates a new handler builder.
|
static WebSocketHandlerBuilder |
webSocketHandler(MuWebSocketFactory factory)
Creates a new handler builder with the given factory.
|
WebSocketHandlerBuilder |
withIdleReadTimeout(long duration,
TimeUnit unit)
Sets the idle timeout.
|
WebSocketHandlerBuilder |
withMaxFramePayloadLength(int maxFramePayloadLength)
Sets the maximum size in bytes that a frame can be.
|
WebSocketHandlerBuilder |
withPath(String path)
Sets the path to listen on for this handler.
|
WebSocketHandlerBuilder |
withPingSentAfterNoWritesFor(int duration,
TimeUnit unit)
Sets the amount of time to wait before sending a ping message if no messages having been sent.
|
WebSocketHandlerBuilder |
withWebSocketFactory(MuWebSocketFactory factory)
Sets the factory that decides whether to create a websocket connection for a request.
|
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.
factory
- A factory that creates websockets, or returns null if the websocket connection shouldn't
be created.public WebSocketHandlerBuilder withPath(String path)
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.
path
- The path of this web socket endpoint.public WebSocketHandlerBuilder withIdleReadTimeout(long duration, TimeUnit unit)
The default is 5 minutes.
duration
- The allowed timeout duration, or 0 to disable timeouts.unit
- The unit of the duration.public WebSocketHandlerBuilder withPingSentAfterNoWritesFor(int duration, TimeUnit unit)
The default is 30 seconds.
duration
- The allowed timeout duration, or 0 to disable timeouts.unit
- The unit of the duration.public WebSocketHandlerBuilder withMaxFramePayloadLength(int maxFramePayloadLength)
65536
maxFramePayloadLength
- The maximum allowed size in bytes of websocket frames.public WebSocketHandler build()
build
in interface MuHandlerBuilder<WebSocketHandler>
public static WebSocketHandlerBuilder webSocketHandler()
public static WebSocketHandlerBuilder webSocketHandler(MuWebSocketFactory factory)
factory
- The factory to use.Copyright © 2017–2019. All rights reserved.