Class SCPConnection
java.lang.Object
uk.ac.manchester.spinnaker.connections.UDPConnection<SDPMessage>
uk.ac.manchester.spinnaker.connections.SDPConnection
uk.ac.manchester.spinnaker.connections.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.-
Nested Class Summary
Nested classes/interfaces inherited from class uk.ac.manchester.spinnaker.connections.UDPConnection
UDPConnection.TrafficClass
-
Constructor Summary
Constructors Modifier Constructor Description SCPConnection(HasChipLocation chip, InetAddress localHost, Integer localPort, InetAddress remoteHost)
Create a connection to a particular instance of SCAMP.protected
SCPConnection(HasChipLocation chip, InetAddress localHost, Integer localPort, InetAddress remoteHost, int remotePort)
Create a connection to a particular instance of SCAMP. -
Method Summary
Modifier and Type Method Description protected void
closeAndLogNoExcept()
Close this connection, logging failures instead of throwing.void
closeEventually()
Close this connection eventually.SCPResultMessage
receiveSCPResponse(int timeout)
Receives an SCP response from this connection.void
send(ByteBuffer requestData, int seq)
Send a request that expects a response to be appropriately directed to the thread that is calling this method.String
toString()
Methods inherited from class uk.ac.manchester.spinnaker.connections.SDPConnection
getChip, receiveMessage, send, setChip
Methods inherited from class uk.ac.manchester.spinnaker.connections.UDPConnection
close, doReceive, doReceiveWithAddress, doSend, doSendTo, getLocalAddress, getLocalIPAddress, getLocalPort, getRemoteAddress, getRemoteIPAddress, getRemotePort, isClosed, isConnected, receive, receive, receiveMessage, receiveWithAddress, send, send, sendPortTriggerMessage, sendTo, sendTo, sendTo, setReceivePacketSize
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface uk.ac.manchester.spinnaker.connections.model.Connection
convertTimeout, getLocalIPAddress, getLocalPort, getRemoteIPAddress, getRemotePort, isClosed, isConnected, receive, receiveWithAddress, send, sendTo
Methods inherited from interface uk.ac.manchester.spinnaker.connections.model.SCPSenderReceiver
getChip, getSCPData, receiveSCPResponse, send
-
Constructor Details
-
SCPConnection
public SCPConnection(HasChipLocation chip, InetAddress localHost, Integer localPort, InetAddress remoteHost) throws IOExceptionCreate a connection to a particular instance of SCAMP.- Parameters:
chip
- The location of the chip on the board with this remoteHostlocalHost
- The optional host of the local interface to listen on; usenull
to listen on all local interfaces.localPort
- The optional local port to listen on; usenull
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 IOExceptionCreate 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 remoteHostlocalHost
- The optional host of the local interface to listen on; usenull
to listen on all local interfaces.localPort
- The optional local port to listen on; usenull
to pick a random port.remoteHost
- The remote host to send messages to.remotePort
- The optional remote port number to send messages to. Ifnull
, 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, InterruptedExceptionReceives 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 interfaceSCPSenderReceiver
- 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 messageSocketTimeoutException
- If there is a timeout before a message is receivedInterruptedException
- 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
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 interfaceSCPSenderReceiver
- 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
- Overrides:
toString
in classUDPConnection<SDPMessage>
-