synchronized access to treatment data
This commit is contained in:
parent
272fdb4747
commit
9f67ad6b62
1 changed files with 44 additions and 18 deletions
|
@ -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));
|
||||
|
||||
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();
|
||||
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() {
|
||||
long fromMills = System.currentTimeMillis() - 60 * 60 * 1000L * 24;
|
||||
tempTargets.reset().add(MainApp.getDbHelper().getTemptargetsDataFromTime(fromMills, false));
|
||||
synchronized (tempTargets) {
|
||||
long fromMills = System.currentTimeMillis() - 60 * 60 * 1000L * 24;
|
||||
tempTargets.reset().add(MainApp.getDbHelper().getTemptargetsDataFromTime(fromMills, false));
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeProfileSwitchData() {
|
||||
profiles.reset().add(MainApp.getDbHelper().getProfileSwitchData(false));
|
||||
synchronized (profiles) {
|
||||
profiles.reset().add(MainApp.getDbHelper().getProfileSwitchData(false));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -302,7 +310,9 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
|
||||
@Override
|
||||
public TemporaryBasal getRealTempBasalFromHistory(long time) {
|
||||
return tempBasals.getValueByInterval(time);
|
||||
synchronized (tempBasals) {
|
||||
return tempBasals.getValueByInterval(time);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -401,7 +411,9 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
|
||||
@Override
|
||||
public ExtendedBolus getExtendedBolusFromHistory(long time) {
|
||||
return extendedBoluses.getValueByInterval(time);
|
||||
synchronized (extendedBoluses) {
|
||||
return extendedBoluses.getValueByInterval(time);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -412,12 +424,16 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
|
||||
@Override
|
||||
public Intervals<ExtendedBolus> getExtendedBolusesFromHistory() {
|
||||
return extendedBoluses;
|
||||
synchronized (extendedBoluses) {
|
||||
return extendedBoluses;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() {
|
||||
return tempBasals;
|
||||
synchronized (tempBasals) {
|
||||
return tempBasals;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -482,18 +498,24 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
@Nullable
|
||||
@Override
|
||||
public TempTarget getTempTargetFromHistory() {
|
||||
return tempTargets.getValueByInterval(System.currentTimeMillis());
|
||||
synchronized (tempTargets) {
|
||||
return tempTargets.getValueByInterval(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TempTarget getTempTargetFromHistory(long time) {
|
||||
return tempTargets.getValueByInterval(time);
|
||||
synchronized (tempTargets) {
|
||||
return tempTargets.getValueByInterval(time);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intervals<TempTarget> getTempTargetsFromHistory() {
|
||||
return tempTargets;
|
||||
synchronized (tempTargets) {
|
||||
return tempTargets;
|
||||
}
|
||||
}
|
||||
|
||||
// Profile Switch
|
||||
|
@ -504,12 +526,16 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
|
||||
@Override
|
||||
public ProfileSwitch getProfileSwitchFromHistory(long time) {
|
||||
return (ProfileSwitch) profiles.getValueToTime(time);
|
||||
synchronized (profiles) {
|
||||
return (ProfileSwitch) profiles.getValueToTime(time);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileIntervals<ProfileSwitch> getProfileSwitchesFromHistory() {
|
||||
return profiles;
|
||||
synchronized (profiles) {
|
||||
return profiles;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue