Class TxrxProcess
java.lang.Object
uk.ac.manchester.spinnaker.transceiver.TxrxProcess
public class TxrxProcess extends Object
A process for talking to SpiNNaker efficiently that uses multiple connections
in communication (if appropriate).
-
Field Summary
Fields Modifier and Type Field Description protected static int
DEFAULT_INTERMEDIATE_CHANNEL_WAITS
The default for the number of instantaneously active channels.protected static int
DEFAULT_INTERMEDIATE_TIMEOUT_WAITS
The default number of outstanding responses to wait for before continuing sending requests.protected static int
DEFAULT_NUM_CHANNELS
The default for the number of parallel channels.protected static int
RETRY_DELAY_MS
How long to wait between retries, in milliseconds.protected static int
SCP_RETRIES
The default number of times to resend any packet for any reason before an error is triggered.protected static int
SCP_TIMEOUT
The default for the timeout (in ms). -
Constructor Summary
Constructors Modifier Constructor Description protected
TxrxProcess(ConnectionSelector<Conn> connectionSelector, int numRetries, int timeout, int numChannels, int intermediateChannelWaits, RetryTracker retryTracker)
protected
TxrxProcess(ConnectionSelector<Conn> connectionSelector, RetryTracker retryTracker)
-
Method Summary
Modifier and Type Method Description protected void
call(SCPRequest<EmptyResponse> request)
Do a synchronous call of an SCP operation, sending the given message and completely processing the interaction before returning its response.protected void
finishBatch()
Wait for all outstanding requests sent by this process to receive replies or time out.protected <T, R extends PayloadedResponse<T, ?>>
Tretrieve(SCPRequest<R> request)
Do a synchronous call of an SCP operation, sending the given message and completely processing the interaction before returning its parsed payload.protected <T, R extends PayloadedResponse<T, ?>>
voidsendGet(SCPRequest<R> request, Consumer<T> callback)
Send a request for a response with a payload.protected void
sendOneWayRequest(SCPRequest<NoResponse> request)
Send a one-way request.protected <Resp extends CheckOKResponse>
voidsendRequest(SCPRequest<Resp> request, Consumer<Resp> callback)
Send a request and handle the response.protected void
sendRequest(SCPRequest<EmptyResponse> request)
Send a request.
-
Field Details
-
DEFAULT_NUM_CHANNELS
protected static final int DEFAULT_NUM_CHANNELSThe default for the number of parallel channels.- See Also:
- Constant Field Values
-
DEFAULT_INTERMEDIATE_CHANNEL_WAITS
protected static final int DEFAULT_INTERMEDIATE_CHANNEL_WAITSThe default for the number of instantaneously active channels.- See Also:
- Constant Field Values
-
DEFAULT_INTERMEDIATE_TIMEOUT_WAITS
protected static final int DEFAULT_INTERMEDIATE_TIMEOUT_WAITSThe default number of outstanding responses to wait for before continuing sending requests.- See Also:
- Constant Field Values
-
SCP_RETRIES
protected static final int SCP_RETRIESThe default number of times to resend any packet for any reason before an error is triggered. -
RETRY_DELAY_MS
protected static final int RETRY_DELAY_MSHow long to wait between retries, in milliseconds.- See Also:
- Constant Field Values
-
SCP_TIMEOUT
protected static final int SCP_TIMEOUTThe default for the timeout (in ms).
-
-
Constructor Details
-
TxrxProcess
- Type Parameters:
Conn
- The type of connection.- Parameters:
connectionSelector
- How to select how to communicate.retryTracker
- Object used to track how many retries were used in an operation. May benull
if no suck tracking is required.
-
TxrxProcess
protected TxrxProcess(ConnectionSelector<Conn> connectionSelector, int numRetries, int timeout, int numChannels, int intermediateChannelWaits, RetryTracker retryTracker)- Type Parameters:
Conn
- The type of connection.- Parameters:
connectionSelector
- How to select how to communicate.numRetries
- The number of times to retry a communication.timeout
- The timeout (in ms) for the communication.numChannels
- The number of parallel communications to supportintermediateChannelWaits
- How many parallel communications to launch at once. (??)retryTracker
- Object used to track how many retries were used in an operation. May benull
if no suck tracking is required.
-
-
Method Details
-
finishBatch
Wait for all outstanding requests sent by this process to receive replies or time out. Then test if an error occurred on the SpiNNaker side, and throw a process exception it if it did.- Throws:
IOException
- If communications fail.ProcessException
- an exception that wraps the original exception that occurred.InterruptedException
- If the communications were interrupted.
-
sendRequest
protected final void sendRequest(SCPRequest<EmptyResponse> request) throws IOException, InterruptedExceptionSend a request. The actual payload of the response to this request is to be considered to be uninteresting provided it doesn't indicate a failure. In particular, the response is aEmptyResponse
.- Parameters:
request
- The request to send.- Throws:
IOException
- If sending fails.InterruptedException
- If communications are interrupted while preparing to send.
-
sendRequest
protected final <Resp extends CheckOKResponse> void sendRequest(SCPRequest<Resp> request, Consumer<Resp> callback) throws IOException, InterruptedExceptionSend a request and handle the response.- Type Parameters:
Resp
- The type of response expected to the request.- Parameters:
request
- The request to send.callback
- The callback that handles the request's response.- Throws:
IOException
- If sending fails.InterruptedException
- If communications are interrupted.
-
sendGet
protected final <T, R extends PayloadedResponse<T, ?>> void sendGet(SCPRequest<R> request, Consumer<T> callback) throws IOException, InterruptedExceptionSend a request for a response with a payload.- Type Parameters:
T
- The type of parsed payload expected.R
- The type of response expected to the request.- Parameters:
request
- The request to send.callback
- The callback that handles the parsed payload.- Throws:
IOException
- If sending fails.InterruptedException
- If communications are interrupted.
-
call
protected final void call(SCPRequest<EmptyResponse> request) throws IOException, ProcessException, InterruptedExceptionDo a synchronous call of an SCP operation, sending the given message and completely processing the interaction before returning its response.- Parameters:
request
- The request to send- Throws:
IOException
- If the communications failProcessException
- If the other side responds with a failure codeInterruptedException
- If the communications were interrupted.
-
retrieve
protected final <T, R extends PayloadedResponse<T, ?>> T retrieve(SCPRequest<R> request) throws IOException, ProcessException, InterruptedExceptionDo a synchronous call of an SCP operation, sending the given message and completely processing the interaction before returning its parsed payload.- Type Parameters:
T
- The type of the payload of the response.R
- The type of the response; implicit in the type of the request.- Parameters:
request
- The request to send- Returns:
- The successful response to the request
- Throws:
IOException
- If the communications failProcessException
- If the other side responds with a failure codeInterruptedException
- If the communications were interrupted.
-
sendOneWayRequest
protected final void sendOneWayRequest(SCPRequest<NoResponse> request) throws IOException, InterruptedExceptionSend a one-way request. One way requests do not need to be finished.- Parameters:
request
- The request to send. Must be a one-way request!- Throws:
IOException
- If sending fails.InterruptedException
- If communications are interrupted while preparing to send.
-