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
-
Method Summary
Modifier and Type Method Description void
afterConnectionClosed(WebSocketSession session, CloseStatus status)
Websocket closed; disconnect the proxy handler.void
afterConnectionEstablished(WebSocketSession session)
Websocket established; connect to the proxy handler.void
afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception)
Empty method to satisfy interface.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.protected void
closed(WebSocketSession session, ProxyCore proxy, SpallocAPI.Job job)
Connection closed.protected void
delegateToProxy(BinaryMessage message, ProxyCore proxy)
Message was sent to us.protected void
handleBinaryMessage(WebSocketSession session, BinaryMessage message)
Websocket message received, dispatch it to the proxy for handling.void
handleTransportError(WebSocketSession session, Throwable exception)
Log exceptions from the transport level.protected void
initProxyCore(WebSocketSession session, SpallocAPI.Job job)
Connection established and job looked up.Methods inherited from class org.springframework.web.socket.handler.BinaryWebSocketHandler
handleTextMessage
Methods 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:
- Constant Field Values
-
-
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:
beforeHandshake
in 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:
afterHandshake
in interfaceHandshakeInterceptor
-
afterConnectionEstablished
Websocket established; connect to the proxy handler.- Specified by:
afterConnectionEstablished
in interfaceWebSocketHandler
- Overrides:
afterConnectionEstablished
in classAbstractWebSocketHandler
- Parameters:
session
- The websocket session to connect.
-
afterConnectionClosed
Websocket closed; disconnect the proxy handler.- Specified by:
afterConnectionClosed
in interfaceWebSocketHandler
- Overrides:
afterConnectionClosed
in 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 ExceptionWebsocket message received, dispatch it to the proxy for handling.- Overrides:
handleBinaryMessage
in 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 forEOFException
because that's just fine and comes up in a normal disconnect.- Specified by:
handleTransportError
in interfaceWebSocketHandler
- Overrides:
handleTransportError
in 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
-