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));
synchronized (tempBasals) {
tempBasals.reset().add(MainApp.getDbHelper().getTemporaryBasalsDataFromTime(fromMills, false)); tempBasals.reset().add(MainApp.getDbHelper().getTemporaryBasalsDataFromTime(fromMills, false));
}
} }
@ -166,18 +168,24 @@ 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));
synchronized (extendedBoluses) {
extendedBoluses.reset().add(MainApp.getDbHelper().getExtendedBolusDataFromTime(fromMills, false)); extendedBoluses.reset().add(MainApp.getDbHelper().getExtendedBolusDataFromTime(fromMills, false));
}
} }
private void initializeTempTargetData() { private void initializeTempTargetData() {
synchronized (tempTargets) {
long fromMills = System.currentTimeMillis() - 60 * 60 * 1000L * 24; long fromMills = System.currentTimeMillis() - 60 * 60 * 1000L * 24;
tempTargets.reset().add(MainApp.getDbHelper().getTemptargetsDataFromTime(fromMills, false)); tempTargets.reset().add(MainApp.getDbHelper().getTemptargetsDataFromTime(fromMills, false));
} }
}
private void initializeProfileSwitchData() { private void initializeProfileSwitchData() {
synchronized (profiles) {
profiles.reset().add(MainApp.getDbHelper().getProfileSwitchData(false)); profiles.reset().add(MainApp.getDbHelper().getProfileSwitchData(false));
} }
}
@Override @Override
public IobTotal getLastCalculationTreatments() { public IobTotal getLastCalculationTreatments() {
@ -302,8 +310,10 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override @Override
public TemporaryBasal getRealTempBasalFromHistory(long time) { public TemporaryBasal getRealTempBasalFromHistory(long time) {
synchronized (tempBasals) {
return tempBasals.getValueByInterval(time); return tempBasals.getValueByInterval(time);
} }
}
@Override @Override
public boolean isTempBasalInProgress() { public boolean isTempBasalInProgress() {
@ -401,8 +411,10 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override @Override
public ExtendedBolus getExtendedBolusFromHistory(long time) { public ExtendedBolus getExtendedBolusFromHistory(long time) {
synchronized (extendedBoluses) {
return extendedBoluses.getValueByInterval(time); return extendedBoluses.getValueByInterval(time);
} }
}
@Override @Override
public boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus) { public boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus) {
@ -412,13 +424,17 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override @Override
public Intervals<ExtendedBolus> getExtendedBolusesFromHistory() { public Intervals<ExtendedBolus> getExtendedBolusesFromHistory() {
synchronized (extendedBoluses) {
return extendedBoluses; return extendedBoluses;
} }
}
@Override @Override
public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() { public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() {
synchronized (tempBasals) {
return tempBasals; return tempBasals;
} }
}
@Override @Override
public boolean addToHistoryTempBasal(TemporaryBasal tempBasal) { public boolean addToHistoryTempBasal(TemporaryBasal tempBasal) {
@ -482,19 +498,25 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Nullable @Nullable
@Override @Override
public TempTarget getTempTargetFromHistory() { public TempTarget getTempTargetFromHistory() {
synchronized (tempTargets) {
return tempTargets.getValueByInterval(System.currentTimeMillis()); return tempTargets.getValueByInterval(System.currentTimeMillis());
} }
}
@Nullable @Nullable
@Override @Override
public TempTarget getTempTargetFromHistory(long time) { public TempTarget getTempTargetFromHistory(long time) {
synchronized (tempTargets) {
return tempTargets.getValueByInterval(time); return tempTargets.getValueByInterval(time);
} }
}
@Override @Override
public Intervals<TempTarget> getTempTargetsFromHistory() { public Intervals<TempTarget> getTempTargetsFromHistory() {
synchronized (tempTargets) {
return tempTargets; return tempTargets;
} }
}
// Profile Switch // Profile Switch
@Subscribe @Subscribe
@ -504,13 +526,17 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override @Override
public ProfileSwitch getProfileSwitchFromHistory(long time) { public ProfileSwitch getProfileSwitchFromHistory(long time) {
synchronized (profiles) {
return (ProfileSwitch) profiles.getValueToTime(time); return (ProfileSwitch) profiles.getValueToTime(time);
} }
}
@Override @Override
public ProfileIntervals<ProfileSwitch> getProfileSwitchesFromHistory() { public ProfileIntervals<ProfileSwitch> getProfileSwitchesFromHistory() {
synchronized (profiles) {
return profiles; return profiles;
} }
}
@Override @Override
public void addToHistoryProfileSwitch(ProfileSwitch profileSwitch) { public void addToHistoryProfileSwitch(ProfileSwitch profileSwitch) {