Class WebsocketsDemoEchoAllController
- All Implemented Interfaces:
WebsocketController<AppRequestContext,
DefaultWebsocketContext>
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected String
protected WebsocketEndpointManager
protected void
init()
void
onEndpointClosed
(String endpointId) The endpoint is now closed.void
onEndpointReady
(WebsocketEndpointManager endpointManager) This method is called when a new endpoint is created and its manager is ready.void
onPeerClosed
(DefaultWebsocketContext context) A peer closed the WebSocket connection.void
onPeerConnected
(DefaultWebsocketContext context) A peer is connected on the WebSocket endpoint.void
onPeerMessage
(DefaultWebsocketContext context, byte[] message) A peer sent a bytes[] message.void
onPeerMessage
(DefaultWebsocketContext context, String message) A Peer sent a String message.onPeerPreConnect
(AppRequestContext context) Called before the HTTP request is converted to a WebSocket connection.
-
Field Details
-
logger
protected static final org.slf4j.Logger logger
-
-
Constructor Details
-
WebsocketsDemoEchoAllController
public WebsocketsDemoEchoAllController()
-
-
Method Details
-
init
@Inject protected void init() -
getPeerNamesAll
-
getEndpointManager
-
onPeerPreConnect
Description copied from interface:WebsocketController
Called before the HTTP request is converted to a WebSocket connection.Allows you to decide which endpoint and which peer id to use for the WebSocket connection. You still have access to the request parameters, the cookies, so you can make a decision based on those.
- Specified by:
onPeerPreConnect
in interfaceWebsocketController<AppRequestContext,
DefaultWebsocketContext> - Returns:
- the WebSocket configuration to used for this peer
or, if
null
is returned, the WebSocket connection won't be established.
-
generatePeerId
-
onEndpointReady
Description copied from interface:WebsocketController
This method is called when a new endpoint is created and its manager is ready. This occures when the controller returns a endpoint id to be used for the first time. Save this manager and use it to send messages, to echo received messages from a peer to multiple peers, to close peers, or to close the endpoint itself.IMPORTANT: To make sure you receive this manager before the connection with the very first peer is established, to prevent any concurrency issues, this method is actually called synchronously in the same thread handling the connection with that first peer. This means this method should not block! If you use this method to start a loop and send messages, for example, then the WebSocket connection with the first peer will fail...
To use this method as a starting point to send events to the peers, start a new Thread in it and return immediately.
- Specified by:
onEndpointReady
in interfaceWebsocketController<AppRequestContext,
DefaultWebsocketContext>
-
onPeerConnected
Description copied from interface:WebsocketController
A peer is connected on the WebSocket endpoint. You may want to wait for the first call to this method before strating to send messages.- Specified by:
onPeerConnected
in interfaceWebsocketController<AppRequestContext,
DefaultWebsocketContext>
-
onPeerMessage
Description copied from interface:WebsocketController
A Peer sent a String message.- Specified by:
onPeerMessage
in interfaceWebsocketController<AppRequestContext,
DefaultWebsocketContext>
-
onPeerMessage
Description copied from interface:WebsocketController
A peer sent a bytes[] message.- Specified by:
onPeerMessage
in interfaceWebsocketController<AppRequestContext,
DefaultWebsocketContext>
-
onPeerClosed
Description copied from interface:WebsocketController
A peer closed the WebSocket connection.- Specified by:
onPeerClosed
in interfaceWebsocketController<AppRequestContext,
DefaultWebsocketContext>
-
onEndpointClosed
Description copied from interface:WebsocketController
The endpoint is now closed.- Specified by:
onEndpointClosed
in interfaceWebsocketController<AppRequestContext,
DefaultWebsocketContext>
-