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