Interface WebSocketListener
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A listener which can be registered to a web socket channel.
- Since:
- 4.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidhandle(@NonNull WebSocketChannel channel, @NonNull WebSocketFrameType type, byte[] bytes) Handles each received web socket frame.default voidhandleClose(@NonNull WebSocketChannel channel, @NonNull AtomicInteger statusCode, @NonNull AtomicReference<String> reasonText) Handles the close frame either send to the component or sent by the component.
-
Method Details
-
handle
void handle(@NonNull @NonNull WebSocketChannel channel, @NonNull @NonNull WebSocketFrameType type, byte[] bytes) throws Exception Handles each received web socket frame. For each frame each registered listener to a web socket channel is called. A response can be sent through the methods provided for that purpose in the given web socket channel.This method is not called when a client indicates that the connection to will be closed. For that purpose listen to the
handleClose(WebSocketChannel, AtomicInteger, AtomicReference)method instead.- Parameters:
channel- the channel to which the frame was sent.type- the type of frame sent by the client.bytes- the frame content which was transferred.- Throws:
Exception- if any exception occurs during handling of the frame.NullPointerException- if either the given channel or type is null.
-
handleClose
default void handleClose(@NonNull @NonNull WebSocketChannel channel, @NonNull @NonNull AtomicInteger statusCode, @NonNull @NonNull AtomicReference<String> reasonText) Handles the close frame either send to the component or sent by the component. Changes to the status code and status text reference will be reflected to all following listeners and the final close frame sent to the client.If this method changes the status code of the close, the new status code must be a valid code as defined in RFC 6455, else sending the frame to the recipient will result in an exception.
- Parameters:
channel- the channel from which the frame came / to which the frame will be sent.statusCode- a reference to the status code of the frame, must be set to valid one when changing.reasonText- the reason text of the close, might evaluate to null (no reason).- Throws:
NullPointerException- if either the given channel, status code or reason text reference is null.
-