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

SpiNNakerManchester / JavaSpiNNaker / 6310285782

26 Sep 2023 08:47AM UTC coverage: 36.367% (-0.5%) from 36.866%
6310285782

Pull #658

github

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

1675 of 1675 new or added lines in 266 files covered. (100.0%)

8368 of 23010 relevant lines covered (36.37%)

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/BMPReadMemoryProcess.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.Math.min;
19
import static uk.ac.manchester.spinnaker.messages.Constants.UDP_MESSAGE_MAX_SIZE;
20

21
import java.io.File;
22
import java.io.IOException;
23
import java.io.RandomAccessFile;
24
import java.nio.ByteBuffer;
25

26
import uk.ac.manchester.spinnaker.connections.BMPConnection;
27
import uk.ac.manchester.spinnaker.connections.ConnectionSelector;
28
import uk.ac.manchester.spinnaker.machine.MemoryLocation;
29
import uk.ac.manchester.spinnaker.machine.board.BMPBoard;
30
import uk.ac.manchester.spinnaker.messages.bmp.ReadBMPMemory;
31
import uk.ac.manchester.spinnaker.transceiver.Accumulator.BufferAccumulator;
32
import uk.ac.manchester.spinnaker.transceiver.Accumulator.FileAccumulator;
33

34
/** A process for reading memory on a BMP. */
35
class BMPReadMemoryProcess extends BMPCommandProcess {
36
        /**
37
         * @param connectionSelector
38
         *            How to select how to communicate.
39
         * @param retryTracker
40
         *            Object used to track how many retries were used in an
41
         *            operation. May be {@code null} if no suck tracking is
42
         *            required.
43
         */
44
        BMPReadMemoryProcess(ConnectionSelector<BMPConnection> connectionSelector,
45
                        RetryTracker retryTracker) {
46
                super(connectionSelector, retryTracker);
×
47
        }
×
48

49
        /**
50
         * Core of the memory read system.
51
         *
52
         * @param <T>
53
         *            The type of output from the accumulator
54
         * @param board
55
         *            What board's BMP?
56
         * @param address
57
         *            Where to read from?
58
         * @param size
59
         *            How much to read?
60
         * @param accum
61
         *            Where to accumulate the data
62
         * @return The accumulation (if defined for the accumulator type).
63
         * @throws IOException
64
         *             If anything goes wrong with networking.
65
         * @throws ProcessException
66
         *             If SpiNNaker rejects a message.
67
         * @throws InterruptedException
68
         *             If the communications were interrupted.
69
         */
70
        private <T> T read(BMPBoard board, MemoryLocation address, int size,
71
                        Accumulator<T> accum)
72
                        throws ProcessException, IOException, InterruptedException {
73
                for (int offset = 0, chunk; offset < size; offset += chunk) {
×
74
                        chunk = min(size - offset, UDP_MESSAGE_MAX_SIZE);
×
75
                        accum.add(offset,
×
76
                                        call(new ReadBMPMemory(board, address.add(offset), chunk)));
×
77
                }
78
                return accum.finish();
×
79
        }
80

81
        /**
82
         * Read memory into a prepared buffer.
83
         *
84
         * @param board
85
         *            What board's BMP to read from.
86
         * @param baseAddress
87
         *            where to read from.
88
         * @param receivingBuffer
89
         *            The buffer to receive into; the remaining space of the buffer
90
         *            determines how much memory to read.
91
         * @throws IOException
92
         *             If anything goes wrong with networking.
93
         * @throws ProcessException
94
         *             If SpiNNaker rejects a message.
95
         * @throws InterruptedException
96
         *             If the communications were interrupted.
97
         */
98
        void read(BMPBoard board, MemoryLocation baseAddress,
99
                        ByteBuffer receivingBuffer)
100
                        throws IOException, ProcessException, InterruptedException {
101
                read(board, baseAddress, receivingBuffer.remaining(),
×
102
                                new BufferAccumulator(receivingBuffer));
103
                // Ignore the result; caller already knows it
104
        }
×
105

106
        /**
107
         * Read memory into a new buffer.
108
         *
109
         * @param board
110
         *            What board's BMP to read from.
111
         * @param baseAddress
112
         *            where to read from.
113
         * @param size
114
         *            The number of bytes to read.
115
         * @return the filled buffer
116
         * @throws IOException
117
         *             If anything goes wrong with networking.
118
         * @throws ProcessException
119
         *             If SpiNNaker rejects a message.
120
         * @throws InterruptedException
121
         *             If the communications were interrupted.
122
         */
123
        ByteBuffer read(BMPBoard board, MemoryLocation baseAddress, int size)
124
                        throws IOException, ProcessException, InterruptedException {
125
                return read(board, baseAddress, size, new BufferAccumulator(size));
×
126
        }
127

128
        /**
129
         * Read memory into a file. Note that we can write the file out of order; a
130
         * {@link RandomAccessFile} is required
131
         *
132
         * @param board
133
         *            What board's BMP to read from.
134
         * @param baseAddress
135
         *            Where to read from.
136
         * @param size
137
         *            The number of bytes to read.
138
         * @param dataFile
139
         *            where to write the bytes
140
         * @throws IOException
141
         *             If anything goes wrong with networking or with access to the
142
         *             file.
143
         * @throws ProcessException
144
         *             If SpiNNaker rejects a message.
145
         * @throws InterruptedException
146
         *             If the communications were interrupted.
147
         */
148
        void read(BMPBoard board, MemoryLocation baseAddress, int size,
149
                        RandomAccessFile dataFile)
150
                        throws IOException, ProcessException, InterruptedException {
151
                read(board, baseAddress, size, new FileAccumulator(dataFile));
×
152
        }
×
153

154
        /**
155
         * Read memory into a file.
156
         *
157
         * @param board
158
         *            What board's BMP to read from.
159
         * @param baseAddress
160
         *            where to read from.
161
         * @param size
162
         *            The number of bytes to read.
163
         * @param dataFile
164
         *            where to write the bytes
165
         * @throws IOException
166
         *             If anything goes wrong with networking or with access to the
167
         *             file.
168
         * @throws ProcessException
169
         *             If SpiNNaker rejects a message.
170
         * @throws InterruptedException
171
         *             If the communications were interrupted.
172
         */
173
        void read(BMPBoard board, MemoryLocation baseAddress, int size,
174
                        File dataFile)
175
                        throws IOException, ProcessException, InterruptedException {
176
                try (var s = new RandomAccessFile(dataFile, "rw")) {
×
177
                        read(board, baseAddress, size, new FileAccumulator(s));
×
178
                }
179
        }
×
180
}
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