Class DelegatingSCPConnection
java.lang.Object
uk.ac.manchester.spinnaker.connections.UDPConnection<SDPMessage>
uk.ac.manchester.spinnaker.connections.SDPConnection
uk.ac.manchester.spinnaker.connections.SCPConnection
uk.ac.manchester.spinnaker.connections.DelegatingSCPConnection
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Connection
,SCPSenderReceiver
public class DelegatingSCPConnection extends SCPConnection
An SCP connection that actually delegates message sending and receiving to
another connection. Note that closing a delegating connection does nothing;
the socket is only closed when the real underlying connection is closed.
- Author:
- Donal Fellows
-
Nested Class Summary
Nested classes/interfaces inherited from class uk.ac.manchester.spinnaker.connections.UDPConnection
UDPConnection.TrafficClass
-
Constructor Summary
Constructors Constructor Description DelegatingSCPConnection(SDPConnection connection)
Create a connection that delegates actual communications to another connection. -
Method Summary
Modifier and Type Method Description void
close()
When we're delegating, closing is a no-op; the underlying channel has to be closed directly.protected ByteBuffer
doReceive(int timeout)
Receive data from the connection.protected UDPPacket
doReceiveWithAddress(int timeout)
Receive data from the connection along with the address where the data was received from.protected void
doSend(ByteBuffer data)
Send data down this connection.protected void
doSendTo(ByteBuffer data, InetAddress address, int port)
Send data down this connection.protected InetSocketAddress
getLocalAddress()
Get the local socket address.protected InetSocketAddress
getRemoteAddress()
Get the remote socket address.boolean
isClosed()
Determines if the medium is closed at this point in time.boolean
isConnected()
Determines if the medium is connected at this point in time.String
toString()
Methods inherited from class uk.ac.manchester.spinnaker.connections.SCPConnection
closeAndLogNoExcept, closeEventually, receiveSCPResponse, send
Methods inherited from class uk.ac.manchester.spinnaker.connections.SDPConnection
getChip, receiveMessage, send, setChip
Methods inherited from class uk.ac.manchester.spinnaker.connections.UDPConnection
getLocalIPAddress, getLocalPort, getRemoteIPAddress, getRemotePort, 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, receive, receiveWithAddress, send, sendTo
Methods inherited from interface uk.ac.manchester.spinnaker.connections.model.SCPSenderReceiver
getChip, getSCPData, receiveSCPResponse, send
-
Constructor Details
-
DelegatingSCPConnection
Create a connection that delegates actual communications to another connection.- Parameters:
connection
- The connection to delegate to.- Throws:
IOException
- If anything goes wrong. (Unexpected)
-
-
Method Details
-
getLocalAddress
Description copied from class:UDPConnection
Get the local socket address. (Sockets have two ends, one local, one remote.)This operation is delegatable; see
DelegatingSCPConnection
.- Overrides:
getLocalAddress
in classUDPConnection<SDPMessage>
- Returns:
- The socket's local address
- Throws:
IOException
- If the socket is closed.
-
getRemoteAddress
Description copied from class:UDPConnection
Get the remote socket address. (Sockets have two ends, one local, one remote.)This operation is delegatable; see
DelegatingSCPConnection
.- Overrides:
getRemoteAddress
in classUDPConnection<SDPMessage>
- Returns:
- The socket's remote address
-
doReceive
protected ByteBuffer doReceive(int timeout) throws SocketTimeoutException, IOException, InterruptedExceptionDescription copied from class:UDPConnection
Receive data from the connection.This operation is delegatable; see
DelegatingSCPConnection
.- Overrides:
doReceive
in classUDPConnection<SDPMessage>
- Parameters:
timeout
- The timeout in milliseconds- Returns:
- The data received, in a little-endian buffer
- Throws:
SocketTimeoutException
- If a timeout occurs before any data is receivedIOException
- If an error occurs receiving the dataInterruptedException
- If communications are interrupted.
-
doReceiveWithAddress
Description copied from class:UDPConnection
Receive data from the connection along with the address where the data was received from.This operation is delegatable; see
DelegatingSCPConnection
.- Overrides:
doReceiveWithAddress
in classUDPConnection<SDPMessage>
- Parameters:
timeout
- The timeout in milliseconds- Returns:
- The datagram packet received
- Throws:
SocketTimeoutException
- If a timeout occurs before any data is receivedIOException
- If an error occurs receiving the data
-
doSend
Description copied from class:UDPConnection
Send data down this connection.This operation is delegatable; see
DelegatingSCPConnection
.- Overrides:
doSend
in classUDPConnection<SDPMessage>
- Parameters:
data
- The data to be sent; the position in this buffer will not be updated by this method- Throws:
IOException
- If there is an error sending the data
-
doSendTo
Description copied from class:UDPConnection
Send data down this connection.This operation is delegatable; see
DelegatingSCPConnection
.- Overrides:
doSendTo
in classUDPConnection<SDPMessage>
- Parameters:
data
- The data to be sentaddress
- Where to send (must be non-null
)port
- What port to send to (must be non-zero)- Throws:
IOException
- If there is an error sending the data
-
isConnected
public boolean isConnected()Description copied from interface:Connection
Determines if the medium is connected at this point in time. Connected media are not closed. Disconnected media might not be open.- Specified by:
isConnected
in interfaceConnection
- Overrides:
isConnected
in classUDPConnection<SDPMessage>
- Returns:
- true if the medium is connected, false otherwise
-
isClosed
public boolean isClosed()Description copied from interface:Connection
Determines if the medium is closed at this point in time. Closed media are not connected. Open media might not be connected.- Specified by:
isClosed
in interfaceConnection
- Overrides:
isClosed
in classUDPConnection<SDPMessage>
- Returns:
- true if the medium is closed, false otherwise
-
close
When we're delegating, closing is a no-op; the underlying channel has to be closed directly.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classUDPConnection<SDPMessage>
- Throws:
IOException
-
toString
- Overrides:
toString
in classSCPConnection
-