Class ProxyCore
java.lang.Object
uk.ac.manchester.spinnaker.alloc.proxy.ProxyCore
- All Implemented Interfaces:
AutoCloseable
public class ProxyCore extends Object implements AutoCloseable
The main proxy class for a particular web socket session. It's bound to a
job, which should be running at the time that the web socket is opened.
- Author:
- Donal Fellows
-
Method Summary
Modifier and Type Method Description void
close()
protected ByteBuffer
closeChannel(ByteBuffer message)
Close a channel in response to aProxyOp.CLOSE
message.void
handleClientMessage(ByteBuffer message)
Handle a message sent to this service on the web socket associated with this object.protected ByteBuffer
openConnectedChannel(ByteBuffer message)
Open a connected channel in response to aProxyOp.OPEN
message.protected ByteBuffer
openUnconnectedChannel(ByteBuffer message)
Open an unconnected channel in response to aProxyOp.OPEN_UNCONNECTED
message.protected ByteBuffer
sendMessage(ByteBuffer message)
Send a message on a channel in response to aProxyOp.MESSAGE
message.protected ByteBuffer
sendMessageTo(ByteBuffer message)
Send a message to a particular destination on a channel in response to aProxyOp.MESSAGE_TO
message.
-
Method Details
-
handleClientMessage
Handle a message sent to this service on the web socket associated with this object.- Parameters:
message
- The content of the message.- Throws:
IOException
- Not expected; implementations don't actually throw
-
openConnectedChannel
Open a connected channel in response to aProxyOp.OPEN
message. Note that no control over the local (to the service) port number or address is provided, nor is a mechanism given to easily make available what address is used (though it can be obtained from the IPTag).- Parameters:
message
- The message received. The initial 4-byte type code will have been already read out of the buffer.- Returns:
- The response message to send, in the bytes leading up to the
position. The caller will flip the
message. Underlying failures that are not due to outright
protocol abuse will be reported to users as a
ProxyOp.ERROR
message. - Throws:
IllegalArgumentException
- If insufficient or too many arguments are supplied.
-
openUnconnectedChannel
Open an unconnected channel in response to aProxyOp.OPEN_UNCONNECTED
message. Note that no control over the local (to the service) port number or address is provided, but the IP address and port opened are in the return message.- Parameters:
message
- The message received. The initial 4-byte type code will have been already read out of the buffer.- Returns:
- The response message to send, in the bytes leading up to the
position. The caller will flip the
message. Underlying failures that are not due to outright
protocol abuse will be reported to users as a
ProxyOp.ERROR
message. - Throws:
IllegalArgumentException
- If insufficient or too many arguments are supplied.
-
closeChannel
Close a channel in response to aProxyOp.CLOSE
message. It's not an error to close a channel twice- Parameters:
message
- The message received. The initial 4-byte type code will have been already read out of the buffer.- Returns:
- The response message to send, in the bytes leading up to the
position. The caller will flip the
message. Underlying failures that are not due to outright
protocol abuse will be reported to users as a
ProxyOp.ERROR
message. - Throws:
IllegalArgumentException
- If insufficient or too many arguments are supplied.
-
sendMessage
Send a message on a channel in response to aProxyOp.MESSAGE
message. It's not an error to send on a non-existant or closed channel.- Parameters:
message
- The message received. The initial 4-byte type code will have been already read out of the buffer.- Returns:
- The response message to send, in the bytes leading up to the
position. The caller will flip the
message. If
null
, no response will be sent (expected case for this operation!) - Throws:
IOException
- If the proxy connection can't be used.
-
sendMessageTo
Send a message to a particular destination on a channel in response to aProxyOp.MESSAGE_TO
message. It's not an error to send on a non-existent or closed channel. It is an error to use this operation on a channel that has a bound remote host address.- Parameters:
message
- The message received. The initial 4-byte type code will have been already read out of the buffer.- Returns:
- The response message to send, in the bytes leading up to the
position. The caller will flip the
message. If
null
, no response will be sent (expected case for this operation!) - Throws:
IOException
- If the proxy connection can't be used.IllegalArgumentException
- If the target doesn't exist in the job, the port number is out of range, or the channel has a bound address.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-