Package io.grpc.servlet.web.websocket
Class MultiplexedWebSocketServerStream
java.lang.Object
jakarta.websocket.Endpoint
io.grpc.servlet.web.websocket.AbstractWebSocketServerStream
io.grpc.servlet.web.websocket.MultiplexedWebSocketServerStream
Each instance of this type represents a single active websocket, which can allow several concurrent/overlapping gRPC
streams. This is in contrast to the
WebSocketServerStream type, which supports one websocket per gRPC stream.
To achieve this, each grpc message starts with a 32 bit integer indicating the ID of the stream. If the MSB of that int is 1, then the request must be closed by this message, and that MSB is set to zero to read the ID of the stream. On the initial request, an extra header is sent from the client, indicating the path to the service method. Technically, this makes it possible for a grpc message to split across several websocket frames, but at this time each grpc message is exactly one websocket frame.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback to initiate a graceful shutdown of this websocket instance, as an alternative to just closing the websocket. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final io.grpc.Metadata.Key<String> Custom metadata to hold the path requested by the incoming streamFields inherited from class io.grpc.servlet.web.websocket.AbstractWebSocketServerStream
attributes, maxInboundMessageSize, streamTracerFactories, transportListener, websocketSession -
Constructor Summary
ConstructorsConstructorDescriptionMultiplexedWebSocketServerStream(io.grpc.internal.ServerTransportListener transportListener, List<? extends io.grpc.ServerStreamTracer.Factory> streamTracerFactories, int maxInboundMessageSize, io.grpc.Attributes attributes) -
Method Summary
Modifier and TypeMethodDescriptionvoidonClose(jakarta.websocket.Session session, jakarta.websocket.CloseReason closeReason) voidvoidvoidonMessage(ByteBuffer message) voidonOpen(jakarta.websocket.Session websocketSession, jakarta.websocket.EndpointConfig config) Methods inherited from class io.grpc.servlet.web.websocket.AbstractWebSocketServerStream
readHeaders
-
Field Details
-
GRACEFUL_CLOSE
-
PATH
Custom metadata to hold the path requested by the incoming stream -
GRPC_WEBSOCKETS_MULTIPLEX_PROTOCOL
- See Also:
-
-
Constructor Details
-
MultiplexedWebSocketServerStream
public MultiplexedWebSocketServerStream(io.grpc.internal.ServerTransportListener transportListener, List<? extends io.grpc.ServerStreamTracer.Factory> streamTracerFactories, int maxInboundMessageSize, io.grpc.Attributes attributes)
-
-
Method Details
-
onOpen
public void onOpen(jakarta.websocket.Session websocketSession, jakarta.websocket.EndpointConfig config) - Overrides:
onOpenin classAbstractWebSocketServerStream
-
onClose
public void onClose(jakarta.websocket.Session session, jakarta.websocket.CloseReason closeReason) - Overrides:
onClosein classjakarta.websocket.Endpoint
-
onMessage
- Specified by:
onMessagein classAbstractWebSocketServerStream
-
onMessage
- Specified by:
onMessagein classAbstractWebSocketServerStream- Throws:
IOException
-
onError
- Overrides:
onErrorin classjakarta.websocket.Endpoint
-