Class SpinWSHandler
java.lang.Object
org.springframework.web.socket.handler.AbstractWebSocketHandler
org.springframework.web.socket.handler.BinaryWebSocketHandler
uk.ac.manchester.spinnaker.alloc.proxy.SpinWSHandler
- All Implemented Interfaces:
HandshakeInterceptor,WebSocketHandler
@Component
public class SpinWSHandler
extends BinaryWebSocketHandler
implements HandshakeInterceptor
Initial handler for web sockets. Maps a particular websocket to a
proxy handler that processes messages received and
sends messages the other way.
- Author:
- Donal Fellows
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidafterConnectionClosed(WebSocketSession session, CloseStatus status) Websocket closed; disconnect the proxy handler.voidWebsocket established; connect to the proxy handler.voidafterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) Empty method to satisfy interface.booleanbeforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) Look up the job that websocket is being created for and attach it to the websocket's attributes.protected final voidclosed(WebSocketSession session, ProxyCore proxy, SpallocAPI.Job job) Connection closed.protected final voiddelegateToProxy(BinaryMessage message, ProxyCore proxy) Message was sent to us.protected voidhandleBinaryMessage(WebSocketSession session, BinaryMessage message) Websocket message received, dispatch it to the proxy for handling.voidhandleTransportError(WebSocketSession session, Throwable exception) Log exceptions from the transport level.protected final voidinitProxyCore(WebSocketSession session, SpallocAPI.Job job) Connection established and job looked up.Methods inherited from class org.springframework.web.socket.handler.BinaryWebSocketHandler
handleTextMessageMethods inherited from class org.springframework.web.socket.handler.AbstractWebSocketHandler
handleMessage, handlePongMessage, supportsPartialMessages
-
Field Details
-
PATH
The path that we match in this handler.- See Also:
-
-
Method Details
-
beforeHandshake
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) Look up the job that websocket is being created for and attach it to the websocket's attributes.- Specified by:
beforeHandshakein interfaceHandshakeInterceptor- Returns:
- Whether we found the job and attached it.
-
afterHandshake
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) Empty method to satisfy interface.- Specified by:
afterHandshakein interfaceHandshakeInterceptor
-
afterConnectionEstablished
Websocket established; connect to the proxy handler.- Specified by:
afterConnectionEstablishedin interfaceWebSocketHandler- Overrides:
afterConnectionEstablishedin classAbstractWebSocketHandler- Parameters:
session- The websocket session to connect.
-
afterConnectionClosed
Websocket closed; disconnect the proxy handler.- Specified by:
afterConnectionClosedin interfaceWebSocketHandler- Overrides:
afterConnectionClosedin classAbstractWebSocketHandler- Parameters:
session- The websocket session to disconnect.status- Why the session closed. (Unimportant for this code)
-
handleBinaryMessage
protected void handleBinaryMessage(WebSocketSession session, BinaryMessage message) throws Exception Websocket message received, dispatch it to the proxy for handling.- Overrides:
handleBinaryMessagein classAbstractWebSocketHandler- Parameters:
session- The websocket session that the message was received on.message- The received message.- Throws:
Exception
-
handleTransportError
Log exceptions from the transport level. Except forEOFExceptionbecause that's just fine and comes up in a normal disconnect.- Specified by:
handleTransportErrorin interfaceWebSocketHandler- Overrides:
handleTransportErrorin classAbstractWebSocketHandler- Parameters:
session- The websocket session that had the error.exception- What happened.
-
initProxyCore
Connection established and job looked up. Make a proxy.- Parameters:
session- The Websocket sessionjob- The job extracted from the websocket path- Throws:
RequestFailedException.NotFound- If the job ID can't be mapped to a jobRequestFailedException- If the job doesn't have an allocated machine
-
closed
Connection closed.- Parameters:
session- The Websocket sessionproxy- The proxy handler for our custom protocoljob- What job we are working for
-
delegateToProxy
Message was sent to us.- Parameters:
message- The body of the message.proxy- The socket proxy will be handling the message- Throws:
IOException- If the proxy fails to handle the message in a bad way
-