synchronized access to treatment data

This commit is contained in:
Milos Kozak 2018-03-23 20:52:41 +01:00
parent 272fdb4747
commit 9f67ad6b62

View file

@ -58,10 +58,10 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
private IobTotal lastTempBasalsCalculation; private IobTotal lastTempBasalsCalculation;
public static List<Treatment> treatments; public static List<Treatment> treatments;
private static Intervals<TemporaryBasal> tempBasals = new NonOverlappingIntervals<>(); private final static Intervals<TemporaryBasal> tempBasals = new NonOverlappingIntervals<>();
private static Intervals<ExtendedBolus> extendedBoluses = new NonOverlappingIntervals<>(); private final static Intervals<ExtendedBolus> extendedBoluses = new NonOverlappingIntervals<>();
private static Intervals<TempTarget> tempTargets = new OverlappingIntervals<>(); private final static Intervals<TempTarget> tempTargets = new OverlappingIntervals<>();
private static ProfileIntervals<ProfileSwitch> profiles = new ProfileIntervals<>(); private final static ProfileIntervals<ProfileSwitch> profiles = new ProfileIntervals<>();
private boolean fragmentEnabled = true; private boolean fragmentEnabled = true;
private boolean fragmentVisible = true; private boolean fragmentVisible = true;
@ -156,7 +156,9 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
dia = MainApp.getConfigBuilder().getProfile().getDia(); dia = MainApp.getConfigBuilder().getProfile().getDia();
long fromMills = (long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + dia)); long fromMills = (long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + dia));
tempBasals.reset().add(MainApp.getDbHelper().getTemporaryBasalsDataFromTime(fromMills, false)); synchronized (tempBasals) {
tempBasals.reset().add(MainApp.getDbHelper().getTemporaryBasalsDataFromTime(fromMills, false));
}
} }
@ -166,17 +168,23 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
dia = MainApp.getConfigBuilder().getProfile().getDia(); dia = MainApp.getConfigBuilder().getProfile().getDia();
long fromMills = (long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + dia)); long fromMills = (long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + dia));
extendedBoluses.reset().add(MainApp.getDbHelper().getExtendedBolusDataFromTime(fromMills, false)); synchronized (extendedBoluses) {
extendedBoluses.reset().add(MainApp.getDbHelper().getExtendedBolusDataFromTime(fromMills, false));
}
} }
private void initializeTempTargetData() { private void initializeTempTargetData() {
long fromMills = System.currentTimeMillis() - 60 * 60 * 1000L * 24; synchronized (tempTargets) {
tempTargets.reset().add(MainApp.getDbHelper().getTemptargetsDataFromTime(fromMills, false)); long fromMills = System.currentTimeMillis() - 60 * 60 * 1000L * 24;
tempTargets.reset().add(MainApp.getDbHelper().getTemptargetsDataFromTime(fromMills, false));
}
} }
private void initializeProfileSwitchData() { private void initializeProfileSwitchData() {
profiles.reset().add(MainApp.getDbHelper().getProfileSwitchData(false)); synchronized (profiles) {
profiles.reset().add(MainApp.getDbHelper().getProfileSwitchData(false));
}
} }
@Override @Override
@ -302,7 +310,9 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override @Override
public TemporaryBasal getRealTempBasalFromHistory(long time) { public TemporaryBasal getRealTempBasalFromHistory(long time) {
return tempBasals.getValueByInterval(time); synchronized (tempBasals) {
return tempBasals.getValueByInterval(time);
}
} }
@Override @Override
@ -401,7 +411,9 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override @Override
public ExtendedBolus getExtendedBolusFromHistory(long time) { public ExtendedBolus getExtendedBolusFromHistory(long time) {
return extendedBoluses.getValueByInterval(time); synchronized (extendedBoluses) {
return extendedBoluses.getValueByInterval(time);
}
} }
@Override @Override
@ -412,12 +424,16 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override @Override
public Intervals<ExtendedBolus> getExtendedBolusesFromHistory() { public Intervals<ExtendedBolus> getExtendedBolusesFromHistory() {
return extendedBoluses; synchronized (extendedBoluses) {
return extendedBoluses;
}
} }
@Override @Override
public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() { public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() {
return tempBasals; synchronized (tempBasals) {
return tempBasals;
}
} }
@Override @Override
@ -482,18 +498,24 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Nullable @Nullable
@Override @Override
public TempTarget getTempTargetFromHistory() { public TempTarget getTempTargetFromHistory() {
return tempTargets.getValueByInterval(System.currentTimeMillis()); synchronized (tempTargets) {
return tempTargets.getValueByInterval(System.currentTimeMillis());
}
} }
@Nullable @Nullable
@Override @Override
public TempTarget getTempTargetFromHistory(long time) { public TempTarget getTempTargetFromHistory(long time) {
return tempTargets.getValueByInterval(time); synchronized (tempTargets) {
return tempTargets.getValueByInterval(time);
}
} }
@Override @Override
public Intervals<TempTarget> getTempTargetsFromHistory() { public Intervals<TempTarget> getTempTargetsFromHistory() {
return tempTargets; synchronized (tempTargets) {
return tempTargets;
}
} }
// Profile Switch // Profile Switch
@ -504,12 +526,16 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override @Override
public ProfileSwitch getProfileSwitchFromHistory(long time) { public ProfileSwitch getProfileSwitchFromHistory(long time) {
return (ProfileSwitch) profiles.getValueToTime(time); synchronized (profiles) {
return (ProfileSwitch) profiles.getValueToTime(time);
}
} }
@Override @Override
public ProfileIntervals<ProfileSwitch> getProfileSwitchesFromHistory() { public ProfileIntervals<ProfileSwitch> getProfileSwitchesFromHistory() {
return profiles; synchronized (profiles) {
return profiles;
}
} }
@Override @Override