Fix ConcurrentModificationException in RemoteRecorder
This commit is contained in:
parent
e3f42ffc1c
commit
7218ed04fb
|
@ -15,6 +15,7 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -70,6 +71,7 @@ public class RemoteRecorder implements Recorder {
|
|||
private List<Model> models = Collections.emptyList();
|
||||
private List<Model> onlineModels = Collections.emptyList();
|
||||
private List<Recording> recordings = Collections.emptyList();
|
||||
private ReentrantLock modelGroupLock = new ReentrantLock();
|
||||
private Set<ModelGroup> modelGroups = new HashSet<>();
|
||||
private List<Site> sites;
|
||||
private long spaceTotal = -1;
|
||||
|
@ -202,8 +204,13 @@ public class RemoteRecorder implements Recorder {
|
|||
throw new IOException("Server returned error " + resp.status + " " + resp.msg);
|
||||
}
|
||||
|
||||
modelGroups.clear();
|
||||
modelGroups.addAll(resp.groups);
|
||||
modelGroupLock.lock();
|
||||
try {
|
||||
modelGroups.clear();
|
||||
modelGroups.addAll(resp.groups);
|
||||
} finally {
|
||||
modelGroupLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void addHmacIfNeeded(String msg, Builder builder) throws InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException {
|
||||
|
@ -691,7 +698,12 @@ public class RemoteRecorder implements Recorder {
|
|||
|
||||
@Override
|
||||
public Set<ModelGroup> getModelGroups() {
|
||||
return new HashSet<>(modelGroups);
|
||||
modelGroupLock.lock();
|
||||
try {
|
||||
return new HashSet<>(modelGroups);
|
||||
} finally {
|
||||
modelGroupLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue