Skip to content

Commit

Permalink
Merge pull request #1152 from SCADA-LTS/feature/#1151_PointLink
Browse files Browse the repository at this point in the history
working version of PoinLink with junit
  • Loading branch information
grzesiekb authored Apr 6, 2020
2 parents 727f9c9 + 6dcafe6 commit dc01402
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ branches:
- "/^siv/develop.*$/"
- "/^siv/master.*$/"
- "/^feature_s/#1156.*$/"


- "/^feature/#1151.*$/"
notifications:
email: false
env:
Expand Down
39 changes: 19 additions & 20 deletions src/com/serotonin/mango/rt/link/PointLinkRT.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,38 @@

import javax.script.ScriptException;

import com.serotonin.mango.rt.dataImage.DataPointListener;
import com.serotonin.mango.rt.dataImage.DataPointRT;
import com.serotonin.mango.rt.dataImage.IDataPoint;
import com.serotonin.mango.rt.dataImage.PointValueTime;
import com.serotonin.mango.rt.dataImage.PointLinkSetPointSource;
import com.serotonin.mango.rt.maint.work.PointLinkSetPointWorkItem;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.serotonin.mango.Common;
import com.serotonin.mango.DataTypes;
import com.serotonin.mango.rt.dataImage.DataPointListener;
import com.serotonin.mango.rt.dataImage.DataPointRT;
import com.serotonin.mango.rt.dataImage.IDataPoint;
import com.serotonin.mango.rt.dataImage.PointValueTime;
import com.serotonin.mango.rt.dataImage.SetPointSource;
import com.serotonin.mango.rt.dataSource.meta.ResultTypeException;
import com.serotonin.mango.rt.dataSource.meta.ScriptExecutor;
import com.serotonin.mango.rt.event.type.EventType;
import com.serotonin.mango.rt.event.type.SystemEventType;
import com.serotonin.mango.rt.maint.work.SetPointWorkItem;
import com.serotonin.mango.vo.link.PointLinkVO;
import com.serotonin.util.StringUtils;
import com.serotonin.web.i18n.LocalizableMessage;

/**
* @author Matthew Lohbihler
*/
public class PointLinkRT implements DataPointListener, SetPointSource {
public class PointLinkRT implements DataPointListener, PointLinkSetPointSource {
public static final String CONTEXT_VAR_NAME = "source";
private final PointLinkVO vo;
private final SystemEventType eventType;
private Log LOG = LogFactory.getLog(PointLinkRT.class);

// Added to stop excessive point link calls
private volatile Boolean ready;
private volatile boolean ready;
private final Object lock = new Object();

//That constructor is only for the junit test.
public PointLinkRT(PointLinkVO vo, boolean ready) {
this.vo = vo;
eventType = null;
ready = ready;
}

public PointLinkRT(PointLinkVO vo) {
this.vo = vo;
Expand Down Expand Up @@ -109,15 +104,18 @@ private void raiseFailureEvent(long time, LocalizableMessage message) {
private void returnToNormal() {
SystemEventType.returnToNormal(eventType, System.currentTimeMillis());
}

private void execute(PointValueTime newValue) {

// Bail out if already running a point link operation
synchronized (ready) {
if (!ready)
synchronized (lock) {
if (!ready) {
LOG.trace("PointLinkRT.ready is set to false.Any of scripts (in meaning source-target) will not work.");
return;
else
}
else {
LOG.trace("PointLinkRT.ready will set to false.Scripts (in meaning source-target) will not work.");
ready = false; // Stop anyone else from using this
}
}

// Propagate the update to the target point. Validate that the target
Expand Down Expand Up @@ -175,7 +173,7 @@ private void execute(PointValueTime newValue) {

// Queue a work item to perform the update.
Common.ctx.getBackgroundProcessing().addWorkItem(
new SetPointWorkItem(vo.getTargetPointId(), newValue, this));
new PointLinkSetPointWorkItem(vo.getTargetPointId(), newValue, this));
returnToNormal();
}

Expand Down Expand Up @@ -228,7 +226,7 @@ public int getSetPointSourceId() {

@Override
public int getSetPointSourceType() {
return SetPointSource.Types.POINT_LINK;
return Types.POINT_LINK;
}

@Override
Expand All @@ -246,5 +244,6 @@ public void raiseRecursionFailureEvent() {
@Override
public void pointSetComplete() {
this.ready = true;
LOG.trace("PointLinkRT.pointSetComplete. Ready property is set to true ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public boolean isSettable() {
pointLinkVO.setId(1);
pointLinkVO.setXid("X_POINT_LINK");

PointLinkRT pointLinkRT = new PointLinkRT( pointLinkVO,true);
PointLinkRT pointLinkRT = new PointLinkRT( pointLinkVO);
dataPointRT.addCollectionIntoCache( pointValueCacheTest.getSavedPointValueTimeInCache(pointLinkRT) );


Expand Down

0 comments on commit dc01402

Please sign in to comment.