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