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
Modifier and TypeClassDescriptionstatic interface
Callback to initiate a graceful shutdown of this websocket instance, as an alternative to just closing the websocket. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static 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
ConstructorDescriptionMultiplexedWebSocketServerStream
(io.grpc.internal.ServerTransportListener transportListener, List<? extends io.grpc.ServerStreamTracer.Factory> streamTracerFactories, int maxInboundMessageSize, io.grpc.Attributes attributes) -
Method Summary
Modifier and TypeMethodDescriptionvoid
onClose
(jakarta.websocket.Session session, jakarta.websocket.CloseReason closeReason) void
void
void
onMessage
(ByteBuffer message) void
onOpen
(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:
onOpen
in classAbstractWebSocketServerStream
-
onClose
public void onClose(jakarta.websocket.Session session, jakarta.websocket.CloseReason closeReason) - Overrides:
onClose
in classjakarta.websocket.Endpoint
-
onMessage
- Specified by:
onMessage
in classAbstractWebSocketServerStream
-
onMessage
- Specified by:
onMessage
in classAbstractWebSocketServerStream
- Throws:
IOException
-
onError
- Overrides:
onError
in classjakarta.websocket.Endpoint
-