Skip to content

Commit 13f8dc2

Browse files
authored
Merge pull request #16 from pjreed/remove-locks
Remove locks when reading bag files
2 parents b4fa086 + 681f8f9 commit 13f8dc2

5 files changed

Lines changed: 14 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Java Bag Reader changelog
22

3+
1.6
4+
5+
- Removed file locking when reading bag files
6+
37
1.5
48

59
- Acquiring shared locks when reading bag files

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Add the following dependency to your Maven pom.xml:
1818
<dependency>
1919
<groupId>com.github.swri-robotics</groupId>
2020
<artifactId>bag-reader-java</artifactId>
21-
<version>1.4</version>
21+
<version>1.6</version>
2222
</dependency>
2323
```
2424

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<groupId>com.github.swri-robotics</groupId>
1010
<artifactId>bag-reader-java</artifactId>
1111
<packaging>jar</packaging>
12-
<version>1.5</version>
12+
<version>1.6</version>
1313
<name>bag-reader-java</name>
1414
<url>https://github.com/swri-robotics/bag-reader-java</url>
1515
<properties>

src/main/java/com/github/swrirobotics/bags/reader/BagFile.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import java.nio.ByteBuffer;
5151
import java.nio.ByteOrder;
5252
import java.nio.channels.FileChannel;
53-
import java.nio.channels.FileLock;
5453
import java.nio.channels.ReadableByteChannel;
5554
import java.nio.channels.SeekableByteChannel;
5655
import java.nio.file.FileSystems;
@@ -275,7 +274,6 @@ public Connection findFirstConnectionByMd5Sum(String msgMd5Sum) {
275274
public void forFirstTopicWithMessagesOfType(String messageType, MessageHandler handler) throws BagReaderException {
276275
for (Connection conn : myConnectionsByType.get(messageType)) {
277276
try (FileChannel channel = getChannel()) {
278-
FileLock lock = channel.lock(0, Long.MAX_VALUE, true);
279277
MsgIterator iter = new MsgIterator(myChunkInfos, conn, channel);
280278

281279
while (iter.hasNext()) {
@@ -307,7 +305,6 @@ public void forFirstTopicWithMessagesOfType(String messageType, MessageHandler h
307305
public void forMessagesOfType(String messageType, MessageHandler handler) throws BagReaderException {
308306
for (Connection conn : myConnectionsByType.get(messageType)) {
309307
try (FileChannel channel = getChannel()) {
310-
FileLock lock = channel.lock(0, Long.MAX_VALUE, true);
311308
MsgIterator iter = new MsgIterator(myChunkInfos, conn, channel);
312309

313310
while (iter.hasNext()) {
@@ -336,7 +333,6 @@ public void forMessagesOfType(String messageType, MessageHandler handler) throws
336333
public void forMessagesOnTopic(String topic, MessageHandler handler) throws BagReaderException {
337334
for (Connection conn : myConnectionsByTopic.get(topic)) {
338335
try (FileChannel channel = getChannel()) {
339-
FileLock lock = channel.lock(0, Long.MAX_VALUE, true);
340336
MsgIterator iter = new MsgIterator(myChunkInfos, conn, channel);
341337

342338
while (iter.hasNext()) {
@@ -361,7 +357,6 @@ public void forMessagesOnTopic(String topic, MessageHandler handler) throws BagR
361357
public MessageType getFirstMessageOfType(String messageType) throws BagReaderException {
362358
for (Connection conn : myConnectionsByType.get(messageType)) {
363359
try (FileChannel channel = getChannel()) {
364-
FileLock lock = channel.lock(0, Long.MAX_VALUE, true);
365360
MsgIterator iter = new MsgIterator(myChunkInfos, conn, channel);
366361
if (iter.hasNext()) {
367362
return iter.next();
@@ -388,7 +383,6 @@ public MessageType getFirstMessageOfType(String messageType) throws BagReaderExc
388383
public MessageType getFirstMessageOnTopic(String topic) throws BagReaderException {
389384
for (Connection conn : myConnectionsByTopic.get(topic)) {
390385
try (FileChannel channel = getChannel()) {
391-
FileLock lock = channel.lock(0, Long.MAX_VALUE, true);
392386
MsgIterator iter = new MsgIterator(myChunkInfos, conn, channel);
393387
if (iter.hasNext()) {
394388
return iter.next();
@@ -507,7 +501,6 @@ else if (compression.equals("lz4")) {
507501
chunkPositions.add(info.getChunkPos());
508502
}
509503
try (FileChannel channel = getChannel()) {
510-
FileLock lock = channel.lock(0, Long.MAX_VALUE, true);
511504
for (Long chunkPos : chunkPositions) {
512505
Chunk chunk = new Chunk(recordAt(channel, chunkPos));
513506
String compression = chunk.getCompression();
@@ -598,7 +591,6 @@ public MessageType getMessageOnTopicAtIndex(String topic,
598591
}
599592

600593
try (FileChannel channel = getChannel()) {
601-
FileLock lock = channel.lock(0, Long.MAX_VALUE, true);
602594
MessageIndex msgIndex = indexes.get(index);
603595
Record record = BagFile.recordAt(channel, msgIndex.fileIndex);
604596
ByteBufferChannel chunkChannel = new ByteBufferChannel(record.getData());
@@ -626,7 +618,6 @@ public MessageType getMessageOnTopicAtIndex(String topic,
626618
private void generateIndexesForTopic(String topic) throws BagReaderException {
627619
List<MessageIndex> msgIndexes = Lists.newArrayList();
628620
try (FileChannel channel = getChannel()) {
629-
FileLock lock = channel.lock(0, Long.MAX_VALUE, true);
630621
for (Connection conn : myConnectionsByTopic.get(topic)) {
631622
for (ChunkInfo chunkInfo : myChunkInfosByConnectionId.get(conn.getConnectionId())) {
632623
long chunkPos = chunkInfo.getChunkPos();
@@ -807,7 +798,6 @@ public void read() throws BagReaderException {
807798
}
808799

809800
try (FileChannel input = getChannel()){
810-
FileLock lock = input.lock(0, Long.MAX_VALUE, true);
811801
verifyBagFile(input);
812802

813803
while (hasNext(input)) {

src/main/java/com/github/swrirobotics/bags/reader/messages/serialization/PrimitiveType.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ public void setName(String name) {
9191
*/
9292
abstract public void setValue(String value);
9393

94+
/**
95+
* Sets the value of this field from an object of the same type.
96+
* @param value The value to set in this field.
97+
*/
98+
public void setValue(T value) {
99+
myValue = value;
100+
}
101+
94102
/**
95103
* Creates a copy of this field. The new field will have the same type,
96104
* name, and default value, but if this field had previously been read

0 commit comments

Comments
 (0)