Class WebsocketHandlerDecorator
- All Implemented Interfaces:
ParameterResolver<HasMessage>, HandlerDecorator
SocketSession.
This decorator supports @HandleWeb-annotated methods that interact over WebSocket connections, and
transparently manages the lifecycle of SocketSession instances. It implements both HandlerDecorator
and ParameterResolver to provide the following capabilities:
-
Automatically upgrades incoming
WS_HANDSHAKErequests to WebSocket sessions if the handler includes methods annotated withHandleSocketOpenor similar, but does not explicitly handle the handshake itself. This ensures that endpoints which declare websocket handlers still result in a successful connection upgrade even without a dedicated handshake method. -
Delegates
WS_MESSAGErequests to the associatedSocketSessionfor message dispatch and response. -
Performs cleanup on
WS_CLOSErequests, closing the session and invoking any associatedHandleSocketClosehandlers. -
Resolves
SocketSessionmethod parameters in applicable WebSocket handler methods.
This decorator also tracks open WebSocket sessions and ensures that message dispatch is session-aware. It works transparently with the Fluxzero client’s message routing and tracking infrastructure.
-
Nested Class Summary
Nested classes/interfaces inherited from interface HandlerDecorator
HandlerDecorator.MergedDecorator -
Field Summary
Fields inherited from interface HandlerDecorator
noOp -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Handler<DeserializingMessage> cleanUpOnClose(Handler<DeserializingMessage> handler) protected Handler<DeserializingMessage> closeOnError(Handler<DeserializingMessage> handler) protected Handler<DeserializingMessage> enableHandshake(Handler<DeserializingMessage> handler, List<WebPattern> socketPatterns) protected DefaultSocketSessionprotected Handler<DeserializingMessage> handleRequest(Handler<DeserializingMessage> handler) booleanmatches(Parameter parameter, Annotation methodAnnotation, HasMessage value) Determines whether this resolver supports injecting aSocketSessionfor the given method parameter.booleanmayApply(Executable method, Class<?> targetClass) Returnstrueif this resolver might apply to the given method.protected voidonAbort(DefaultSocketSession session, int code) resolve(Parameter p, Annotation methodAnnotation) Resolves aSocketSessionparameter from the currentHasMessagecontext.wrap(Handler<DeserializingMessage> handler) Wraps a websocket-compatible handler with websocket-specific functionality.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HandlerDecorator
andThenMethods inherited from interface ParameterResolver
determinesSpecificity, test
-
Constructor Details
-
WebsocketHandlerDecorator
public WebsocketHandlerDecorator()
-
-
Method Details
-
resolve
Resolves aSocketSessionparameter from the currentHasMessagecontext.The session is tracked per session ID and reused for subsequent requests over the same connection. If no session exists for the current message's session ID, a new one is created.
- Specified by:
resolvein interfaceParameterResolver<HasMessage>- Parameters:
p- the method parameter being resolvedmethodAnnotation- the handler method's annotation (e.g.@HandleWeb)- Returns:
- a function that resolves the
SocketSessionfrom the message
-
getOrCreateSocketSession
-
matches
Determines whether this resolver supports injecting aSocketSessionfor the given method parameter.The parameter must be assignable from
SocketSession, and the method must be annotated withHandleWeb(or a compatible meta-annotation).- Specified by:
matchesin interfaceParameterResolver<HasMessage>- Parameters:
parameter- the parameter being resolvedmethodAnnotation- the annotation present on the handler methodvalue- the current message- Returns:
trueif the parameter should be resolved by this resolver
-
mayApply
Description copied from interface:ParameterResolverReturnstrueif this resolver might apply to the given method. Implementations should perform only inexpensive checks and never throw.- Specified by:
mayApplyin interfaceParameterResolver<HasMessage>- Parameters:
method- the handler method or constructortargetClass- the declaring or target class- Returns:
trueif this resolver could apply,falseotherwise
-
onAbort
-
wrap
Wraps a websocket-compatible handler with websocket-specific functionality.If the target handler supports websocket patterns (e.g.,
WS_HANDSHAKEorWS_MESSAGE), it is wrapped with logic to support automatic handshake negotiation, websocket message dispatch, and session cleanup on close.- Specified by:
wrapin interfaceHandlerDecorator- Parameters:
handler- the original handler- Returns:
- the wrapped handler with websocket support if applicable
-
enableHandshake
protected Handler<DeserializingMessage> enableHandshake(Handler<DeserializingMessage> handler, List<WebPattern> socketPatterns) -
handleRequest
-
closeOnError
-
cleanUpOnClose
-