Class SCPConnection

All Implemented Interfaces:
Closeable, AutoCloseable, Connection, SCPSenderReceiver
Direct Known Subclasses:
DelegatingSCPConnection

public class SCPConnection
extends SDPConnection
implements SCPSenderReceiver
An SDP connection to talk SCP (SpiNNaker Control Protocol) to SC&MP on a SpiNNaker system, and to the cores managed by it. In general, an SCPConnection is thread safe when used via a TxrxProcess, but not all operations that can be invoked that way are; flood-fills of binaries are particularly known to be only safe to do strictly one at a time and with no other traffic.
  • Constructor Details

    • SCPConnection

      public SCPConnection​(HasChipLocation chip, InetAddress localHost, Integer localPort, InetAddress remoteHost) throws IOException
      Create a connection to a particular instance of SCAMP.
      Parameters:
      chip - The location of the chip on the board with this remoteHost
      localHost - The optional host of the local interface to listen on; use null to listen on all local interfaces.
      localPort - The optional local port to listen on; use null to pick a random port.
      remoteHost - The remote host to send messages to.
      Throws:
      IOException - If anything goes wrong with socket setup.
    • SCPConnection

      protected SCPConnection​(HasChipLocation chip, InetAddress localHost, Integer localPort, InetAddress remoteHost, int remotePort) throws IOException
      Create a connection to a particular instance of SCAMP. Can use a specified local network interface.
      Parameters:
      chip - The location of the chip on the board with this remoteHost
      localHost - The optional host of the local interface to listen on; use null to listen on all local interfaces.
      localPort - The optional local port to listen on; use null to pick a random port.
      remoteHost - The remote host to send messages to.
      remotePort - The optional remote port number to send messages to. If null, the default remote port is used.
      Throws:
      IOException - If anything goes wrong with socket setup.
  • Method Details

    • receiveSCPResponse

      public final SCPResultMessage receiveSCPResponse​(int timeout) throws IOException, InterruptedException
      Receives an SCP response from this connection. Blocks until a message has been received, or a timeout occurs.

      This is tricky code because there can be multiple threads using a connection at once and we need to direct responses to the threads that originated the requests that the responses match to. A consequence of this is that it is possible for the wait for a message to be longer than the timeout given; that will occur when the current thread keeps receiving messages for other threads.

      Specified by:
      receiveSCPResponse in interface SCPSenderReceiver
      Parameters:
      timeout - The time in milliseconds to wait for the message to arrive, or until the connection is closed.
      Returns:
      The SCP result, the sequence number, and the data of the response. The buffer pointer will be positioned at the point where the payload starts.
      Throws:
      IOException - If there is an error receiving the message
      SocketTimeoutException - If there is a timeout before a message is received
      InterruptedException - If communications are interrupted.
    • closeEventually

      public void closeEventually()
      Close this connection eventually. The close might not happen immediately.
    • closeAndLogNoExcept

      protected final void closeAndLogNoExcept()
      Close this connection, logging failures instead of throwing.

      Core of implementation of closeEventually().

    • send

      public void send​(ByteBuffer requestData, int seq) throws IOException
      Description copied from interface: SCPSenderReceiver
      Send a request that expects a response to be appropriately directed to the thread that is calling this method.
      Specified by:
      send in interface SCPSenderReceiver
      Parameters:
      requestData - The message data to send.
      seq - The sequence number to come in the response.
      Throws:
      IOException - If there is an error sending the message
      See Also:
      Connection.send(ByteBuffer)
    • toString

      public String toString()
      Overrides:
      toString in class UDPConnection<SDPMessage>