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 Details

    • handleClientMessage

      public final void handleClientMessage​(ByteBuffer message) throws IOException
      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

      protected ByteBuffer openConnectedChannel​(ByteBuffer message)
      Open a connected channel in response to a ProxyOp.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

      protected ByteBuffer openUnconnectedChannel​(ByteBuffer message)
      Open an unconnected channel in response to a ProxyOp.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

      protected ByteBuffer closeChannel​(ByteBuffer message)
      Close a channel in response to a ProxyOp.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

      protected ByteBuffer sendMessage​(ByteBuffer message) throws IOException
      Send a message on a channel in response to a ProxyOp.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

      protected ByteBuffer sendMessageTo​(ByteBuffer message) throws IOException
      Send a message to a particular destination on a channel in response to a ProxyOp.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 interface AutoCloseable