Fix concurrent modification bug in delete method
This commit is contained in:
parent
b44a1c2422
commit
53f77afb85
|
@ -23,6 +23,8 @@ import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -93,6 +95,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
||||||
ContextMenu popup;
|
ContextMenu popup;
|
||||||
ProgressBar spaceLeft;
|
ProgressBar spaceLeft;
|
||||||
Label spaceLabel;
|
Label spaceLabel;
|
||||||
|
Lock recordingsLock = new ReentrantLock();
|
||||||
|
|
||||||
public RecordingsTab(String title, Recorder recorder, Config config, List<Site> sites) {
|
public RecordingsTab(String title, Recorder recorder, Config config, List<Site> sites) {
|
||||||
super(title);
|
super(title);
|
||||||
|
@ -165,14 +168,12 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
||||||
setStyle(null);
|
setStyle(null);
|
||||||
} else {
|
} else {
|
||||||
setText(StringUtil.formatSize(sizeInByte));
|
setText(StringUtil.formatSize(sizeInByte));
|
||||||
|
setStyle("-fx-alignment: CENTER-RIGHT;");
|
||||||
if(Objects.equals(System.getenv("CTBREC_DEV"), "1")) {
|
if(Objects.equals(System.getenv("CTBREC_DEV"), "1")) {
|
||||||
int row = this.getTableRow().getIndex();
|
int row = this.getTableRow().getIndex();
|
||||||
JavaFxRecording rec = tableViewProperty().get().getItems().get(row);
|
JavaFxRecording rec = tableViewProperty().get().getItems().get(row);
|
||||||
if(!rec.valueChanged() && rec.getStatus() == STATUS.RECORDING) {
|
if(!rec.valueChanged() && rec.getStatus() == STATUS.RECORDING) {
|
||||||
setStyle("-fx-alignment: CENTER-RIGHT; -fx-background-color: red");
|
setStyle("-fx-alignment: CENTER-RIGHT; -fx-background-color: red");
|
||||||
} else {
|
|
||||||
setStyle("-fx-alignment: CENTER-RIGHT;");
|
|
||||||
//setStyle(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,23 +281,28 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Iterator<JavaFxRecording> iterator = observableRecordings.iterator(); iterator.hasNext();) {
|
recordingsLock.lock();
|
||||||
JavaFxRecording old = iterator.next();
|
try {
|
||||||
if (!recordings.contains(old)) {
|
for (Iterator<JavaFxRecording> iterator = observableRecordings.iterator(); iterator.hasNext();) {
|
||||||
// remove deleted recordings
|
JavaFxRecording old = iterator.next();
|
||||||
iterator.remove();
|
if (!recordings.contains(old)) {
|
||||||
|
// remove deleted recordings
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
for (JavaFxRecording recording : recordings) {
|
||||||
for (JavaFxRecording recording : recordings) {
|
if (!observableRecordings.contains(recording)) {
|
||||||
if (!observableRecordings.contains(recording)) {
|
// add new recordings
|
||||||
// add new recordings
|
observableRecordings.add(recording);
|
||||||
observableRecordings.add(recording);
|
} else {
|
||||||
} else {
|
// update existing ones
|
||||||
// update existing ones
|
int index = observableRecordings.indexOf(recording);
|
||||||
int index = observableRecordings.indexOf(recording);
|
JavaFxRecording old = observableRecordings.get(index);
|
||||||
JavaFxRecording old = observableRecordings.get(index);
|
old.update(recording);
|
||||||
old.update(recording);
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
recordingsLock.unlock();
|
||||||
}
|
}
|
||||||
table.sort();
|
table.sort();
|
||||||
}
|
}
|
||||||
|
@ -552,20 +558,25 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
||||||
Thread deleteThread = new Thread() {
|
Thread deleteThread = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
recordingsLock.lock();
|
||||||
try {
|
try {
|
||||||
for (JavaFxRecording r : recordings) {
|
List<Recording> deleted = new ArrayList<>();
|
||||||
|
for (Iterator<JavaFxRecording> iterator = recordings.iterator(); iterator.hasNext();) {
|
||||||
|
JavaFxRecording r = iterator.next();
|
||||||
if(r.getStatus() != STATUS.FINISHED) {
|
if(r.getStatus() != STATUS.FINISHED) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
recorder.delete(r);
|
recorder.delete(r);
|
||||||
Platform.runLater(() -> observableRecordings.remove(r));
|
deleted.add(r);
|
||||||
} catch (IOException | InvalidKeyException | NoSuchAlgorithmException | IllegalStateException e1) {
|
} catch (IOException | InvalidKeyException | NoSuchAlgorithmException | IllegalStateException e1) {
|
||||||
LOG.error("Error while deleting recording", e1);
|
LOG.error("Error while deleting recording", e1);
|
||||||
showErrorDialog("Error while deleting recording", "Recording not deleted", e1);
|
showErrorDialog("Error while deleting recording", "Recording not deleted", e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
observableRecordings.removeAll(deleted);
|
||||||
} finally {
|
} finally {
|
||||||
|
recordingsLock.unlock();
|
||||||
Platform.runLater(() -> table.setCursor(Cursor.DEFAULT));
|
Platform.runLater(() -> table.setCursor(Cursor.DEFAULT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue