Synchronizing object packing

Synchronize object packing between the binary store and the network
sender since we're having trouble with these two users of data
overwriting each others work in progress.
This commit is contained in:
Douglas Gillespie 2023-02-07 17:35:01 +00:00
parent ac004ab9cc
commit e4c4c95340
2 changed files with 13 additions and 6 deletions

View File

@ -42,6 +42,8 @@ public abstract class BinaryDataSource {
private BackgroundBinaryWriter backgroundBinaryWriter;
public static final Object packSynchObject = new Object();
/**
* Create a binary data source. These are used both to store data in binary
* files, and possibly also to send data to other PAMguard instances over the network.
@ -224,12 +226,14 @@ public abstract class BinaryDataSource {
* Then pack the data
*/
BinaryObjectData data;
synchronized (packSynchObject) {
if (pamDataUnit instanceof BackgroundDataUnit) {
data = getBackgroundBinaryWriter().packBackgroundData((BackgroundDataUnit) pamDataUnit);
}
else {
data = getPackedData(pamDataUnit);
}
}
/*
* Then put it back to how it was a moment ago.
*/

View File

@ -75,7 +75,10 @@ public class NetworkObjectPacker {
BinaryDataSource binarySource = dataBlock.getBinaryDataSource();
int dataType2 = dataBlock.getQuickId();
BinaryObjectData packedObject = binarySource.getPackedData(dataUnit);
BinaryObjectData packedObject = null;
synchronized (BinaryDataSource.packSynchObject) {
packedObject = binarySource.getPackedData(dataUnit);
}
byte[] data = packedObject.getData();
int duDataLength = data.length + 12;
DataUnitBaseData baseData = dataUnit.getBasicData();