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 SummaryFields
- 
Method SummaryModifier 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.BinaryWebSocketHandlerhandleTextMessageMethods inherited from class org.springframework.web.socket.handler.AbstractWebSocketHandlerhandleMessage, handlePongMessage, supportsPartialMessages
- 
Field Details- 
PATHThe path that we match in this handler.- See Also:
 
 
- 
- 
Method Details- 
beforeHandshakepublic 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 interface- HandshakeInterceptor
- Returns:
- Whether we found the job and attached it.
 
- 
afterHandshakepublic void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) Empty method to satisfy interface.- Specified by:
- afterHandshakein interface- HandshakeInterceptor
 
- 
afterConnectionEstablishedWebsocket established; connect to the proxy handler.- Specified by:
- afterConnectionEstablishedin interface- WebSocketHandler
- Overrides:
- afterConnectionEstablishedin class- AbstractWebSocketHandler
- Parameters:
- session- The websocket session to connect.
 
- 
afterConnectionClosedWebsocket closed; disconnect the proxy handler.- Specified by:
- afterConnectionClosedin interface- WebSocketHandler
- Overrides:
- afterConnectionClosedin class- AbstractWebSocketHandler
- Parameters:
- session- The websocket session to disconnect.
- status- Why the session closed. (Unimportant for this code)
 
- 
handleBinaryMessageprotected void handleBinaryMessage(WebSocketSession session, BinaryMessage message) throws Exception Websocket message received, dispatch it to the proxy for handling.- Overrides:
- handleBinaryMessagein class- AbstractWebSocketHandler
- Parameters:
- session- The websocket session that the message was received on.
- message- The received message.
- Throws:
- Exception
 
- 
handleTransportErrorLog exceptions from the transport level. Except forEOFExceptionbecause that's just fine and comes up in a normal disconnect.- Specified by:
- handleTransportErrorin interface- WebSocketHandler
- Overrides:
- handleTransportErrorin class- AbstractWebSocketHandler
- Parameters:
- session- The websocket session that had the error.
- exception- What happened.
 
- 
initProxyCoreConnection established and job looked up. Make a proxy.- Parameters:
- session- The Websocket session
- job- The job extracted from the websocket path
- Throws:
- RequestFailedException.NotFound- If the job ID can't be mapped to a job
- RequestFailedException- If the job doesn't have an allocated machine
 
- 
closedConnection closed.- Parameters:
- session- The Websocket session
- proxy- The proxy handler for our custom protocol
- job- What job we are working for
 
- 
delegateToProxyMessage 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
 
 
-