Skip to content

Commit

Permalink
#2854 Safely starting and stopping applications:
Browse files Browse the repository at this point in the history
- removed blocking the writing of values before data points are initialized;
  • Loading branch information
Limraj committed Apr 19, 2024
1 parent b2f7048 commit 697b8dc
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 31 deletions.
16 changes: 3 additions & 13 deletions src/com/serotonin/mango/rt/RuntimeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,11 @@ public class RuntimeManager {


private volatile boolean started = false;
private volatile boolean startedDataPoints = false;

//
// Lifecycle
synchronized public void initialize(boolean safe) {
if (started || startedDataPoints)
if (started)
throw new ShouldNeverHappenException(
"RuntimeManager already started");

Expand Down Expand Up @@ -1076,21 +1075,12 @@ public boolean isStarted() {
return started;
}

public boolean isStartedDataPoints() {
return startedDataPoints;
}

private void startPoints() {
try {
DataPointService dataPointService = new DataPointService();
StartStopDataPointsUtils.startPoints(dataPointService, this::startDataPointSafe, this::getDataPoint, this::getRunningDataSource);
} finally {
this.startedDataPoints = true;
}
DataPointService dataPointService = new DataPointService();
StartStopDataPointsUtils.startPoints(dataPointService, this::startDataPointSafe, this::getDataPoint, this::getRunningDataSource);
}

private void stopPoints() {
this.startedDataPoints = false;
StartStopDataPointsUtils.stopPoints(this.dataPoints.values(), this::stopDataPointSafe, this::getDataPoint);
}
}
4 changes: 0 additions & 4 deletions src/com/serotonin/mango/rt/dataImage/DataPointNonSyncRT.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ public DataPointNonSyncRT(DataPointVO vo, PointLocatorRT pointLocator) {
@Override
protected void savePointValue(PointValueTime newValue, SetPointSource source,
boolean async) {
if(isBlocked()) {
return;
}

// Null values are not very nice, and since they don't have a specific
// meaning they are hereby ignored.
if (newValue == null)
Expand Down
4 changes: 0 additions & 4 deletions src/com/serotonin/mango/rt/dataImage/DataPointRT.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ public void setPointValue(PointValueTime newValue, SetPointSource source) {

protected void savePointValue(PointValueTime newValue, SetPointSource source,
boolean async) {
if(isBlocked()) {
return;
}

// Null values are not very nice, and since they don't have a specific
// meaning they are hereby ignored.
if (newValue == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ public DataPointSynchronizedRT(DataPointVO vo, PointLocatorRT pointLocator) {
@Override
protected void savePointValue(PointValueTime newValue, SetPointSource source,
boolean async) {
if(isBlocked()) {
return;
}

// Null values are not very nice, and since they don't have a specific
// meaning they are hereby ignored.
if (newValue == null)
Expand Down
4 changes: 0 additions & 4 deletions src/com/serotonin/mango/rt/dataImage/IDataPointRT.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,4 @@ public interface IDataPointRT extends IDataPoint, ILifecycle, TimeoutClient,
void initialize();
@Override
void terminate();

default boolean isBlocked() {
return !Common.ctx.getRuntimeManager().isStartedDataPoints();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void preconfig() throws Exception {

RuntimeManager runtimeManager = new RuntimeManager();
runtimeManagerMock = mock(RuntimeManager.class);
when(runtimeManagerMock.isStartedDataPoints()).thenReturn(true);

doAnswer(a -> {
runtimeManager.saveDataPoint((DataPointVO)a.getArguments()[0]);
return null;
Expand Down
2 changes: 1 addition & 1 deletion test/utils/mock/MockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void configMockContextWrapper(RuntimeManager runtimeManager) {
ServletContext servletContext = new ServletContextMock(a ->
a.contains("scriptFunctions") ? "test/scriptFunctions.js" : "".equals(a) ? "test/" : "");
BackgroundProcessing backgroundProcessing = mock(BackgroundProcessing.class);
when(runtimeManager.isStartedDataPoints()).thenReturn(true);

when(contextWrapper.getRuntimeManager()).thenReturn(runtimeManager);
when(contextWrapper.getServletContext()).thenReturn(servletContext);
when(contextWrapper.getBackgroundProcessing()).thenReturn(backgroundProcessing);
Expand Down

0 comments on commit 697b8dc

Please sign in to comment.