• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / JavaSpiNNaker / 6233274834

19 Sep 2023 08:46AM UTC coverage: 36.409% (-0.6%) from 36.982%
6233274834

Pull #658

github

dkfellows
Merge branch 'master' into java-17
Pull Request #658: Update Java version to 17

1656 of 1656 new or added lines in 260 files covered. (100.0%)

8373 of 22997 relevant lines covered (36.41%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/ProcessException.java
1
/*
2
 * Copyright (c) 2018 The University of Manchester
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package uk.ac.manchester.spinnaker.transceiver;
17

18
import static java.lang.String.format;
19
import static java.util.Objects.requireNonNull;
20

21
import java.io.Serial;
22

23
import uk.ac.manchester.spinnaker.messages.model.UnexpectedResponseCodeException;
24
import uk.ac.manchester.spinnaker.messages.scp.SCPResult;
25
import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation;
26

27
/**
28
 * Encapsulates exceptions from processes which communicate with some core/chip.
29
 */
30
public class ProcessException extends SpinnmanException {
31
        @Serial
32
        private static final long serialVersionUID = 5198868033333540659L;
33

34
        private static final String S = "     "; // five spaces
35

36
        private static final String MSG_TEMPLATE =
37
                        "when sending to %d:%d:%d, received exception: %s\n" + S
38
                                        + "with message: %s";
39

40
        /** Where does the code believe this exception originated? */
41
        public final SDPLocation source;
42

43
        /**
44
         * The response that cause this exception to be thrown, if known. Never
45
         * {@link SCPResult#RC_OK RC_OK}; that doesn't cause exceptions! May be
46
         * {@code null} if the cause was not identified as an error from SpiNNaker.
47
         */
48
        public final SCPResult responseCode;
49

50
        private ProcessException(SDPLocation source, Throwable cause,
51
                        SCPResult responseCode) {
52
                super(format(MSG_TEMPLATE, source.getX(), source.getY(), source.getP(),
×
53
                                cause.getClass().getName(), cause.getMessage()), cause);
×
54
                this.source = source;
×
55
                this.responseCode = responseCode;
×
56
        }
×
57

58
        private ProcessException(SDPLocation source,
59
                        UnexpectedResponseCodeException cause) {
60
                this(source, cause, cause.response);
×
61
        }
×
62

63
        /**
64
         * Create an exception.
65
         *
66
         * @param source
67
         *            What core were we talking to.
68
         * @param cause
69
         *            What exception caused problems.
70
         * @return A process exception, or a subclass of it.
71
         * @throws InterruptedException
72
         *             If the cause was an interrupt, it is immediately rethrown.
73
         */
74
        static ProcessException makeInstance(SDPLocation source,
75
                        Throwable cause) throws InterruptedException {
76
                if (cause instanceof UnexpectedResponseCodeException urc) {
×
77
                        if (urc.response == null) {
×
78
                                return new ProcessException(source, cause, null);
×
79
                        }
80
                        switch (urc.response) {
×
81
                        case RC_LEN:
82
                                return new BadPacketLength(source, urc);
×
83
                        case RC_SUM:
84
                                return new BadChecksum(source, urc);
×
85
                        case RC_CMD:
86
                                return new BadCommand(source, urc);
×
87
                        case RC_ARG:
88
                                return new InvalidArguments(source, urc);
×
89
                        case RC_PORT:
90
                                return new BadSCPPort(source, urc);
×
91
                        case RC_TIMEOUT:
92
                                return new TimedOut(source, urc);
×
93
                        case RC_ROUTE:
94
                                return new NoP2PRoute(source, urc);
×
95
                        case RC_CPU:
96
                                return new BadCPUNumber(source, urc);
×
97
                        case RC_DEAD:
98
                                return new DeadDestination(source, urc);
×
99
                        case RC_BUF:
100
                                return new NoBufferAvailable(source, urc);
×
101
                        case RC_P2P_NOREPLY:
102
                                return new P2PNoReply(source, urc);
×
103
                        case RC_P2P_REJECT:
104
                                return new P2PReject(source, urc);
×
105
                        case RC_P2P_BUSY:
106
                                return new P2PBusy(source, urc);
×
107
                        case RC_P2P_TIMEOUT:
108
                                return new P2PTimedOut(source, urc);
×
109
                        case RC_PKT_TX:
110
                                return new PacketTransmissionFailed(source, urc);
×
111
                        default:
112
                                // Fall through
113
                        }
114
                }
115
                if (cause instanceof InterruptedException interrupt) {
×
116
                        throw interrupt;
×
117
                }
118
                return new ProcessException(source, requireNonNull(cause), null);
×
119
        }
120

121
        /**
122
         * Marks an exception for errors in the message by the caller. Suggested
123
         * recovery strategy: don't send bad messages.
124
         */
125
        public abstract static class CallerProcessException
126
                        extends ProcessException {
127
                private static final long serialVersionUID = 1L;
128

129
                private CallerProcessException(SDPLocation source,
130
                                UnexpectedResponseCodeException cause) {
131
                        super(source, cause);
×
132
                }
×
133
        }
134

135
        /**
136
         * Marks an exception for a transient condition. Suggested recovery
137
         * strategy: try again in a few moments.
138
         */
139
        public abstract static class TransientProcessException
140
                        extends ProcessException {
141
                private static final long serialVersionUID = 1L;
142

143
                private TransientProcessException(SDPLocation source,
144
                                UnexpectedResponseCodeException cause) {
145
                        super(source, cause);
×
146
                }
×
147
        }
148

149
        /**
150
         * Marks an exception for a permanent condition. Suggested recovery
151
         * strategy: don't try! (Recovery may involve rebooting some hardware or
152
         * even physically reattaching hardware; it's not going to just get better
153
         * by itself.)
154
         */
155
        public abstract static class PermanentProcessException
156
                        extends ProcessException {
157
                private static final long serialVersionUID = 1L;
158

159
                private PermanentProcessException(SDPLocation source,
160
                                UnexpectedResponseCodeException cause) {
161
                        super(source, cause);
×
162
                }
×
163
        }
164

165
        /**
166
         * A process exception cause by the receipt of a {@link SCPResult#RC_LEN}
167
         * message, indicating that the packet length was wrong.
168
         */
169
        public static final class BadPacketLength extends CallerProcessException {
170
                @Serial
171
                private static final long serialVersionUID = 4329836896716525422L;
172

173
                private BadPacketLength(SDPLocation source,
174
                                UnexpectedResponseCodeException cause) {
175
                        super(source, cause);
×
176
                }
×
177
        }
178

179
        /**
180
         * A process exception cause by the receipt of a {@link SCPResult#RC_SUM}
181
         * message, indicating that the checksum was wrong.
182
         */
183
        public static final class BadChecksum extends CallerProcessException {
184
                @Serial
185
                private static final long serialVersionUID = -5660270018252119601L;
186

187
                private BadChecksum(SDPLocation source,
188
                                UnexpectedResponseCodeException cause) {
189
                        super(source, cause);
×
190
                }
×
191
        }
192

193
        /**
194
         * A process exception cause by the receipt of a {@link SCPResult#RC_CMD}
195
         * message, indicating that the command was not supported by the
196
         * destination.
197
         */
198
        public static final class BadCommand extends CallerProcessException {
199
                @Serial
200
                private static final long serialVersionUID = 2446636059917726286L;
201

202
                private BadCommand(SDPLocation source,
203
                                UnexpectedResponseCodeException cause) {
204
                        super(source, cause);
×
205
                }
×
206
        }
207

208
        /**
209
         * A process exception cause by the receipt of a {@link SCPResult#RC_ARG}
210
         * message, indicating that the arguments to the command are wrong.
211
         */
212
        public static final class InvalidArguments extends CallerProcessException {
213
                @Serial
214
                private static final long serialVersionUID = 3907517289211998444L;
215

216
                private InvalidArguments(SDPLocation source,
217
                                UnexpectedResponseCodeException cause) {
218
                        super(source, cause);
×
219
                }
×
220
        }
221

222
        /**
223
         * A process exception cause by the receipt of a {@link SCPResult#RC_PORT}
224
         * message, indicating that the SCP port was out of range.
225
         */
226
        public static final class BadSCPPort extends CallerProcessException {
227
                @Serial
228
                private static final long serialVersionUID = -5171910962257032626L;
229

230
                private BadSCPPort(SDPLocation source,
231
                                UnexpectedResponseCodeException cause) {
232
                        super(source, cause);
×
233
                }
×
234
        }
235

236
        /**
237
         * A process exception cause by the receipt of a
238
         * {@link SCPResult#RC_TIMEOUT} message, indicating that communications
239
         * timed out.
240
         */
241
        public static final class TimedOut extends TransientProcessException {
242
                @Serial
243
                private static final long serialVersionUID = -298985937364034661L;
244

245
                private TimedOut(SDPLocation source,
246
                                UnexpectedResponseCodeException cause) {
247
                        super(source, cause);
×
248
                }
×
249
        }
250

251
        /**
252
         * A process exception cause by the receipt of a {@link SCPResult#RC_ROUTE}
253
         * message, indicating that messages cannot be directed to that destination
254
         * for some reason.
255
         */
256
        public static final class NoP2PRoute extends PermanentProcessException {
257
                @Serial
258
                private static final long serialVersionUID = -6132417061161625508L;
259

260
                private NoP2PRoute(SDPLocation source,
261
                                UnexpectedResponseCodeException cause) {
262
                        super(source, cause);
×
263
                }
×
264
        }
265

266
        /**
267
         * A process exception cause by the receipt of a {@link SCPResult#RC_CPU}
268
         * message, indicating that the destination core number was out of range.
269
         */
270
        public static final class BadCPUNumber extends CallerProcessException {
271
                @Serial
272
                private static final long serialVersionUID = 6532417803149087690L;
273

274
                private BadCPUNumber(SDPLocation source,
275
                                UnexpectedResponseCodeException cause) {
276
                        super(source, cause);
×
277
                }
×
278
        }
279

280
        /**
281
         * A process exception cause by the receipt of a {@link SCPResult#RC_DEAD}
282
         * message, indicating that the destination core was not responding to
283
         * messages from SCAMP.
284
         */
285
        public static final class DeadDestination
286
                        extends PermanentProcessException {
287
                @Serial
288
                private static final long serialVersionUID = -3842030808096451015L;
289

290
                private DeadDestination(SDPLocation source,
291
                                UnexpectedResponseCodeException cause) {
292
                        super(source, cause);
×
293
                }
×
294
        }
295

296
        /**
297
         * A process exception cause by the receipt of a {@link SCPResult#RC_BUF}
298
         * message, indicating that SCAMP had exhausted its supply of buffers.
299
         */
300
        public static final class NoBufferAvailable
301
                        extends TransientProcessException {
302
                @Serial
303
                private static final long serialVersionUID = 3647501054775981197L;
304

305
                private NoBufferAvailable(SDPLocation source,
306
                                UnexpectedResponseCodeException cause) {
307
                        super(source, cause);
×
308
                }
×
309
        }
310

311
        /**
312
         * A process exception cause by the receipt of a
313
         * {@link SCPResult#RC_P2P_NOREPLY} message, indicating that the inter-SCAMP
314
         * messaging failed because the channel open failed.
315
         */
316
        public static final class P2PNoReply extends TransientProcessException {
317
                @Serial
318
                private static final long serialVersionUID = 2196366740196153289L;
319

320
                private P2PNoReply(SDPLocation source,
321
                                UnexpectedResponseCodeException cause) {
322
                        super(source, cause);
×
323
                }
×
324
        }
325

326
        /**
327
         * A process exception cause by the receipt of a
328
         * {@link SCPResult#RC_P2P_REJECT} message, indicating that the receiver in
329
         * the inter-SCAMP messaging rejected the message.
330
         */
331
        public static final class P2PReject extends TransientProcessException {
332
                @Serial
333
                private static final long serialVersionUID = -2903670314989693747L;
334

335
                private P2PReject(SDPLocation source,
336
                                UnexpectedResponseCodeException cause) {
337
                        super(source, cause);
×
338
                }
×
339
        }
340

341
        /**
342
         * A process exception cause by the receipt of a
343
         * {@link SCPResult#RC_P2P_BUSY} message, indicating that the receiver in
344
         * the inter-SCAMP messaging was busy.
345
         */
346
        public static final class P2PBusy extends TransientProcessException {
347
                @Serial
348
                private static final long serialVersionUID = 4445680981367158468L;
349

350
                private P2PBusy(SDPLocation source,
351
                                UnexpectedResponseCodeException cause) {
352
                        super(source, cause);
×
353
                }
×
354
        }
355

356
        /**
357
         * A process exception cause by the receipt of a
358
         * {@link SCPResult#RC_P2P_TIMEOUT} message, indicating that the receiver in
359
         * the inter-SCAMP messaging did not respond.
360
         */
361
        public static final class P2PTimedOut extends TransientProcessException {
362
                @Serial
363
                private static final long serialVersionUID = -7686611958418374003L;
364

365
                private P2PTimedOut(SDPLocation source,
366
                                UnexpectedResponseCodeException cause) {
367
                        super(source, cause);
×
368
                }
×
369
        }
370

371
        /**
372
         * A process exception cause by the receipt of a {@link SCPResult#RC_PKT_TX}
373
         * message, indicating that the packet transmission failed.
374
         */
375
        public static final class PacketTransmissionFailed
376
                        extends TransientProcessException {
377
                @Serial
378
                private static final long serialVersionUID = 5119831821960433468L;
379

380
                private PacketTransmissionFailed(SDPLocation source,
381
                                UnexpectedResponseCodeException cause) {
382
                        super(source, cause);
×
383
                }
×
384
        }
385
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc