From 57eca36d27828733be733f970271b9f89e6160d2 Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Mon, 14 Oct 2013 10:34:40 +0200 Subject: [PATCH] Cleaned up code Removed lots of duplicated code, merged classes, etc. --- .../main/java/ch/psi/fda/aq/Acquisition.java | 18 ++- .../main/java/ch/psi/fda/aq/Collector.java | 13 -- .../src/main/java/ch/psi/fda/core/Guard.java | 9 -- .../src/main/java/ch/psi/fda/core/Sensor.java | 9 -- .../fda/core/guard/ChannelAccessGuard.java | 12 +- .../psi/fda/core/loops/ActorSensorLoop.java | 17 --- .../ChannelAccessDoubleArraySensor.java | 80 ----------- ...leSensor.java => ChannelAccessSensor.java} | 31 ++-- .../sensors/ChannelAccessStringSensor.java | 79 ---------- .../psi/fda/core/sensors/ComplexSensor.java | 136 ------------------ .../sensors/MillisecondTimestampSensor.java | 25 +--- .../core/sensors/OTFNamedChannelSensor.java | 15 -- .../fda/core/sensors/OTFReadbackSensor.java | 22 --- .../core/sensors/OTFScalerChannelSensor.java | 17 --- .../java/ch/psi/fda/model/ModelManager.java | 2 - .../fda/notification/NotificationAgent.java | 2 - .../fda/core/loops/ActorSensorLoopTest.java | 25 ++-- .../ChannelAccessDoubleSensorTest.java | 79 ---------- ...Test.java => ChannelAccessSensorTest.java} | 55 +++++-- .../ChannelAccessStringSensorTest.java | 77 ---------- .../fda/core/sensors/ComplexSensorTest.java | 135 ----------------- 21 files changed, 76 insertions(+), 782 deletions(-) delete mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensor.java rename ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/{ChannelAccessDoubleSensor.java => ChannelAccessSensor.java} (74%) delete mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessStringSensor.java delete mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ComplexSensor.java delete mode 100644 ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleSensorTest.java rename ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/{ChannelAccessDoubleArraySensorTest.java => ChannelAccessSensorTest.java} (55%) delete mode 100644 ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessStringSensorTest.java delete mode 100644 ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ComplexSensorTest.java diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java index 921a831..67c963f 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java @@ -75,9 +75,7 @@ import ch.psi.fda.core.scripting.JythonParameterMapping; import ch.psi.fda.core.scripting.JythonParameterMappingChannel; import ch.psi.fda.core.scripting.JythonParameterMappingGlobalVariable; import ch.psi.fda.core.scripting.JythonParameterMappingID; -import ch.psi.fda.core.sensors.ChannelAccessDoubleArraySensor; -import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor; -import ch.psi.fda.core.sensors.ChannelAccessStringSensor; +import ch.psi.fda.core.sensors.ChannelAccessSensor; import ch.psi.fda.core.sensors.MillisecondTimestampSensor; import ch.psi.fda.core.sensors.OTFNamedChannelSensor; import ch.psi.fda.core.sensors.OTFReadbackSensor; @@ -722,7 +720,7 @@ public class Acquisition { if(name==null){ name = lp.getName(); } - ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(lp.getId(), createChannel(Double.class, name)); + ChannelAccessSensor sensor = new ChannelAccessSensor(lp.getId(), createChannel(Double.class, name)); aLoop.getSensors().add(sensor); } else if(p instanceof FunctionPositioner){ @@ -755,7 +753,7 @@ public class Acquisition { if(name==null){ name = lp.getName(); } - ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(lp.getId(), createChannel(Double.class, name)); + ChannelAccessSensor sensor = new ChannelAccessSensor(lp.getId(), createChannel(Double.class, name)); aLoop.getSensors().add(sensor); } else if (p instanceof ArrayPositioner){ @@ -788,7 +786,7 @@ public class Acquisition { if(name==null){ name = ap.getName(); } - ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(ap.getId(), createChannel(Double.class, name)); + ChannelAccessSensor sensor = new ChannelAccessSensor(ap.getId(), createChannel(Double.class, name)); aLoop.getSensors().add(sensor); } else if (p instanceof RegionPositioner){ @@ -875,7 +873,7 @@ public class Acquisition { if(name==null){ name = rp.getName(); } - ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(rp.getId(), createChannel(Double.class, name)); + ChannelAccessSensor sensor = new ChannelAccessSensor(rp.getId(), createChannel(Double.class, name)); aLoop.getSensors().add(sensor); } else if(p instanceof PseudoPositioner){ @@ -970,10 +968,10 @@ public class Acquisition { // Add sensor Sensor sensor; if(sd.getType().equals("String")){ - sensor = new ChannelAccessStringSensor(sd.getId(), createChannel(String.class,sd.getName())); + sensor = new ChannelAccessSensor<>(sd.getId(), createChannel(String.class,sd.getName())); } else{ - sensor = new ChannelAccessDoubleSensor(sd.getId(), createChannel(Double.class,sd.getName())); + sensor = new ChannelAccessSensor<>(sd.getId(), createChannel(Double.class,sd.getName())); } aLoop.getSensors().add(sensor); @@ -985,7 +983,7 @@ public class Acquisition { aLoop.getPreSensorActions().addAll(mapActions(ad.getPreAction())); // Ad sensor - ChannelAccessDoubleArraySensor sensor = new ChannelAccessDoubleArraySensor(ad.getId(), createChannel(double[].class, ad.getName(), ad.getArraySize())); + Sensor sensor = new ChannelAccessSensor<>(ad.getId(), createChannel(double[].class, ad.getName(), ad.getArraySize())); aLoop.getSensors().add(sensor); } else if (detector instanceof DetectorOfDetectors){ diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/Collector.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/Collector.java index 24c6c70..8a5e43b 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/Collector.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/Collector.java @@ -41,7 +41,6 @@ import ch.psi.fda.core.messages.Message; */ public class Collector implements Runnable{ - // Get Logger private static Logger logger = Logger.getLogger(Collector.class.getName()); /** @@ -56,17 +55,11 @@ public class Collector implements Runnable{ */ private EventBus bus; - /** - * Constructor - */ public Collector(EventBus b){ queues = new ArrayList(); this.bus = b; } - /* (non-Javadoc) - * @see java.lang.Runnable#run() - */ @Override public void run() { @@ -78,9 +71,6 @@ public class Collector implements Runnable{ // Readout aborted through interrupt } } - else{ - // No queue registered for reading - } bus.post(new EndOfStreamMessage()); @@ -126,9 +116,6 @@ public class Collector implements Runnable{ } - /** - * @return the queues - */ public List getQueues() { return queues; } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/Guard.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/Guard.java index a8a2008..1a5bdf4 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/Guard.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/Guard.java @@ -41,13 +41,4 @@ public interface Guard { * @return Returns true if the guard condition was not constrainted since the last init call. False otherwise. */ public boolean check(); - - /** - * Destroy guard. - * Can be used for the cleanup of used resources of the guard (e.g. to close connections, ...) if - * this cannot be done automatically by the GarbageCollector. - * - * After calling this method the guard must not be used any more! - */ - public void destroy(); } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/Sensor.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/Sensor.java index 381b2d6..62f41a1 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/Sensor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/Sensor.java @@ -38,13 +38,4 @@ public interface Sensor { * @return id of sensor */ public String getId(); - - /** - * Destroy sensor. - * Can be used for the cleanup of used resources of the sensor (e.g. to close connections, ...) if - * this cannot be done automatically by the GarbageCollector. - * - * After calling this method the sensor must not be used any more! - */ - public void destroy(); } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/guard/ChannelAccessGuard.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/guard/ChannelAccessGuard.java index ea3d6d6..e38220e 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/guard/ChannelAccessGuard.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/guard/ChannelAccessGuard.java @@ -44,19 +44,14 @@ public class ChannelAccessGuard implements Guard { * Flag to indicate whether a guard condition failed since the last init call * true: all conditions met, false: at least one condition failed */ - private boolean check = true; + private volatile boolean check = true; private final List> conditions; - /** - * Constructor - * @param conditions - */ public ChannelAccessGuard(List> conditions){ this.conditions = conditions; - // Create channel that contribute to the status of the guard for(final ChannelAccessGuardCondition condition: conditions){ condition.getChannel().addPropertyChangeListener(new PropertyChangeListener() { @Override @@ -95,9 +90,4 @@ public class ChannelAccessGuard implements Guard { public boolean check() { return check; } - - @Override - public void destroy() { - } - } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/ActorSensorLoop.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/ActorSensorLoop.java index f172a28..fbd5567 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/ActorSensorLoop.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/ActorSensorLoop.java @@ -452,16 +452,6 @@ public class ActorSensorLoop implements ActionLoop { a.destroy(); } - for(Sensor s: sensors){ - logger.finest("Destroy sensor"); - s.destroy(); - } - - if(guard != null){ - logger.finest("Destroy guard"); - guard.destroy(); - } - // Recursively call cleanup() method of all registered action loops for(ActionLoop actionLoop: actionLoops){ logger.finest("Destroy action loop"); @@ -469,18 +459,11 @@ public class ActorSensorLoop implements ActionLoop { } } - - /* (non-Javadoc) - * @see ch.psi.fda.core.ActionLoop#getPreActions() - */ @Override public List getPreActions() { return preActions; } - /* (non-Javadoc) - * @see ch.psi.fda.core.ActionLoop#getPostActions() - */ @Override public List getPostActions() { return postActions; diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensor.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensor.java deleted file mode 100644 index 8423a98..0000000 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensor.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * - * Copyright 2010 Paul Scherrer Institute. All rights reserved. - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This code is distributed in the hope that it will be useful, - * but without any warranty; without even the implied warranty of - * merchantability or fitness for a particular purpose. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - * - */ - -package ch.psi.fda.core.sensors; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import java.util.logging.Logger; - -import ch.psi.fda.core.EngineConfiguration; -import ch.psi.fda.core.Sensor; -import ch.psi.jcae.Channel; -import ch.psi.jcae.ChannelException; - -/** - * Scalar sensor that reads a double form a Channel Access channel - * @author ebner - * - */ -public class ChannelAccessDoubleArraySensor implements Sensor { - - private static Logger logger = Logger.getLogger(ChannelAccessDoubleArraySensor.class.getName()); - - private final Channel channel; - private final String id; - - /** - * @param id Global id of the sensor - * @param channel - */ - public ChannelAccessDoubleArraySensor(String id, Channel channel){ - this.channel = channel; - this.id = id; - } - - @Override - public Object read() throws InterruptedException { - logger.finest("Read sensor "+channel.getName()); - - double[] v; - try { - v = channel.getValue(); - } catch (TimeoutException | ChannelException | ExecutionException e) { - // Only fail during data acquisition if fail on error sensor flag is on true. Otherwise - // return null - if(EngineConfiguration.getInstance().isFailOnSensorError()){ - // Convert Exception into unchecked RuntimeException - throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e); - } - v = null; - } - return(v); - } - - @Override - public String getId() { - return id; - } - - @Override - public void destroy() { - } - -} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessDoubleSensor.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessSensor.java similarity index 74% rename from ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessDoubleSensor.java rename to ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessSensor.java index 7806799..d3eaa75 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessDoubleSensor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessSensor.java @@ -29,39 +29,32 @@ import ch.psi.jcae.Channel; import ch.psi.jcae.ChannelException; /** - * Scalar sensor that reads a double form a Channel Access channel - * @author ebner - * + * Channel Access sensor capable of reading a channel access channel */ -public class ChannelAccessDoubleSensor implements Sensor { +public class ChannelAccessSensor implements Sensor { - private static Logger logger = Logger.getLogger(ChannelAccessDoubleSensor.class.getName()); + private static Logger logger = Logger.getLogger(ChannelAccessSensor.class.getName()); - private Channel channel; + private Channel channel; private final String id; - /** - * Constructor - * @param id Global id of the sensor - * @param channel - */ - public ChannelAccessDoubleSensor(String id, Channel channel){ - this.channel = channel; + public ChannelAccessSensor(String id, Channel channel){ this.id = id; + this.channel = channel; } @Override public Object read() throws InterruptedException { logger.finest("Read sensor "+channel.getName()); - Double v; + T v; try { v = channel.getValue(); } catch (TimeoutException | ChannelException | ExecutionException e) { if(EngineConfiguration.getInstance().isFailOnSensorError()){ throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e); } - v = Double.NaN; + v = null; } return(v); } @@ -70,12 +63,4 @@ public class ChannelAccessDoubleSensor implements Sensor { public String getId() { return id; } - - @Override - public void destroy() { - } - - public Channel getChannel(){ - return channel; - } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessStringSensor.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessStringSensor.java deleted file mode 100644 index 1771de4..0000000 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessStringSensor.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * - * Copyright 2010 Paul Scherrer Institute. All rights reserved. - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This code is distributed in the hope that it will be useful, - * but without any warranty; without even the implied warranty of - * merchantability or fitness for a particular purpose. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - * - */ - -package ch.psi.fda.core.sensors; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import java.util.logging.Logger; - -import ch.psi.fda.core.EngineConfiguration; -import ch.psi.fda.core.Sensor; -import ch.psi.jcae.Channel; -import ch.psi.jcae.ChannelException; - -/** - * Scalar sensor that reads a double form a Channel Access channel - * @author ebner - * - */ -public class ChannelAccessStringSensor implements Sensor { - - - private static Logger logger = Logger.getLogger(ChannelAccessStringSensor.class.getName()); - - private Channel channel; - private final String id; // Global id of the sensor - - /** - * Constructor - * @param id Global id of the sensor - * @param channelName Name of the Channel Access channel of this sensor - */ - public ChannelAccessStringSensor(String id, Channel channel){ - this.id = id; - this.channel = channel; - } - - @Override - public Object read() throws InterruptedException { - logger.finest("Read sensor "+channel.getName()); - - String v; - try { - v = channel.getValue(); - } catch (TimeoutException | ChannelException | ExecutionException e) { - if(EngineConfiguration.getInstance().isFailOnSensorError()){ - throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e); - } - v = null; - } - return(v); - } - - @Override - public String getId() { - return id; - } - - @Override - public void destroy() { - } - -} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ComplexSensor.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ComplexSensor.java deleted file mode 100644 index 59b04f4..0000000 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ComplexSensor.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * - * Copyright 2010 Paul Scherrer Institute. All rights reserved. - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This code is distributed in the hope that it will be useful, - * but without any warranty; without even the implied warranty of - * merchantability or fitness for a particular purpose. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - * - */ - -package ch.psi.fda.core.sensors; - -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - -import ch.psi.fda.core.Action; -import ch.psi.fda.core.Sensor; - -/** - * Complex sensor that complements an other sensor with pre and post actions. - * Before reading out the complemented sensor the pre actions are executed. After the - * readout the post actions. - * - * @author ebner - * - */ -public class ComplexSensor implements Sensor { - - // Get Logger - private static Logger logger = Logger.getLogger(ComplexSensor.class.getName()); - - /** - * Id of the sensor - */ - private String id; - - /** - * Sensor to complement - */ - private final Sensor sensor; - - /** - * Actions that are executed directly before the first step of this actor - */ - private final List preActions; - - /** - * Actions that are executed directly after the last step of this actor - */ - private final List postActions; - - /** - * Constructor - */ - public ComplexSensor(String id, Sensor sensor){ - this.id = id; - - this.sensor = sensor; - this.preActions = new ArrayList(); - this.postActions = new ArrayList(); - } - - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#read() - */ - @Override - public Object read() throws InterruptedException { - // Execute pre actions - logger.finest("Execute pre actions"); - for(Action action: preActions){ - action.execute(); - } - - // Readout sensor - Object value = sensor.read(); - - // Execute post actions - logger.finest("Execute post actions"); - for(Action action: postActions){ - action.execute(); - } - - return value; - } - - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#getId() - */ - @Override - public String getId() { - return id; - } - - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#destroy() - */ - @Override - public void destroy() { - // Destroy preActions - for(Action a: preActions){ - a.destroy(); - } - - sensor.destroy(); - - // Destroy postActions - for(Action a: postActions){ - a.destroy(); - } - } - - /** - * @return the preActions - */ - public List getPreActions() { - return preActions; - } - - /** - * @return the postActions - */ - public List getPostActions() { - return postActions; - } - -} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/MillisecondTimestampSensor.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/MillisecondTimestampSensor.java index 5c53e35..b993adb 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/MillisecondTimestampSensor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/MillisecondTimestampSensor.java @@ -23,47 +23,24 @@ import ch.psi.fda.core.Sensor; /** * Get the current time in milliseconds - * @author ebner - * */ public class MillisecondTimestampSensor implements Sensor { - /** - * Global id of the sensor - */ - private final String id; + private final String id; // Global id of the sensor - /** - * Constructor - * @param id Global id of the sensor - */ public MillisecondTimestampSensor(String id){ this.id = id; } - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#read() - */ @Override public Object read() { // Return current time in milliseconds return new Double(System.currentTimeMillis()); } - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#getId() - */ @Override public String getId() { return id; } - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#destroy() - */ - @Override - public void destroy() { - // Nothing to be done - } - } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/OTFNamedChannelSensor.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/OTFNamedChannelSensor.java index 315019f..4cb5211 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/OTFNamedChannelSensor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/OTFNamedChannelSensor.java @@ -49,9 +49,6 @@ public class OTFNamedChannelSensor implements Sensor { this.name = name; } - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#read() - */ @Override public Object read() { // Always return 0 if read() method is called. @@ -65,20 +62,8 @@ public class OTFNamedChannelSensor implements Sensor { return name; } - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#getId() - */ @Override public String getId() { return id; } - - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#destroy() - */ - @Override - public void destroy() { - // Nothing to be done - } - } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/OTFReadbackSensor.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/OTFReadbackSensor.java index 83b370f..9b9cdb0 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/OTFReadbackSensor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/OTFReadbackSensor.java @@ -29,42 +29,20 @@ import ch.psi.fda.core.Sensor; */ public class OTFReadbackSensor implements Sensor { - /** - * Global id of the sensor - */ private final String id; - /** - * Constructor - * @param id Global id of the sensor - */ public OTFReadbackSensor(String id){ this.id = id; } - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#read() - */ @Override public Object read() { // Always return 0 if read() method is called. return 0d; } - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#getId() - */ @Override public String getId() { return id; } - - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#destroy() - */ - @Override - public void destroy() { - // Nothing to be done - } - } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/OTFScalerChannelSensor.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/OTFScalerChannelSensor.java index 152485b..119aea2 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/OTFScalerChannelSensor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/OTFScalerChannelSensor.java @@ -24,7 +24,6 @@ import ch.psi.fda.core.Sensor; /** * Sensor to read out a scaler channel. This sensor can only be used within the * OTFLoop. If it is used in other loops, the read value will always be 0. - * @author ebner * */ public class OTFScalerChannelSensor implements Sensor { @@ -49,12 +48,8 @@ public class OTFScalerChannelSensor implements Sensor { this.index = index; } - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#read() - */ @Override public Object read() { - // Always return 0 if read() method is called. return 0d; } @@ -65,20 +60,8 @@ public class OTFScalerChannelSensor implements Sensor { return index; } - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#getId() - */ @Override public String getId() { return id; } - - /* (non-Javadoc) - * @see ch.psi.fda.core.Sensor#destroy() - */ - @Override - public void destroy() { - // Nothing to be done - } - } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/model/ModelManager.java b/ch.psi.fda/src/main/java/ch/psi/fda/model/ModelManager.java index e2e831f..7ed8237 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/model/ModelManager.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/model/ModelManager.java @@ -40,8 +40,6 @@ import ch.psi.fda.model.v1.Configuration; /** * Manage the serialization and deserialization of the FDA data model - * @author ebner - * */ public class ModelManager { diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/notification/NotificationAgent.java b/ch.psi.fda/src/main/java/ch/psi/fda/notification/NotificationAgent.java index 1a16db8..58dbe99 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/notification/NotificationAgent.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/notification/NotificationAgent.java @@ -33,7 +33,6 @@ import ch.psi.fda.model.v1.Recipient; /** * Agent to send out notifications to specified recipients. - * @author ebner */ public class NotificationAgent { @@ -54,7 +53,6 @@ public class NotificationAgent { fromAddress = from; properties = new Properties(); - // Setup mail server properties.put("mail.smtp.host", host); } diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/ActorSensorLoopTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/ActorSensorLoopTest.java index 5b4dae5..cbe0e43 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/ActorSensorLoopTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/ActorSensorLoopTest.java @@ -37,6 +37,7 @@ import org.junit.Test; import ch.psi.fda.TestChannels; import ch.psi.fda.core.Actor; import ch.psi.fda.core.Guard; +import ch.psi.fda.core.Sensor; import ch.psi.fda.core.actions.Delay; import ch.psi.fda.core.actors.ChannelAccessLinearActuator; import ch.psi.fda.core.guard.ChannelAccessGuard; @@ -45,9 +46,7 @@ import ch.psi.fda.core.loops.ActorSensorLoop; import ch.psi.fda.core.messages.DataMessage; import ch.psi.fda.core.messages.DataMessageMetadata; import ch.psi.fda.core.messages.Message; -import ch.psi.fda.core.sensors.ChannelAccessDoubleArraySensor; -import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor; -import ch.psi.fda.core.sensors.ChannelAccessStringSensor; +import ch.psi.fda.core.sensors.ChannelAccessSensor; import ch.psi.jcae.Channel; import ch.psi.jcae.ChannelDescriptor; import ch.psi.jcae.ChannelException; @@ -79,10 +78,10 @@ public class ActorSensorLoopTest { loopOne = new ActorSensorLoop(); ChannelAccessLinearActuator a = new ChannelAccessLinearActuator<>(cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)), null, 1,0, 0, 10, 0.1, timeout); // Positioner - ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel))); // Positioner Readback - ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel))); // Scalar Detector - ChannelAccessStringSensor s1string = new ChannelAccessStringSensor("id3", cservice.createChannel(new ChannelDescriptor<>(String.class, boChannel+".NAME"))); // Scalar String Detector - ChannelAccessDoubleArraySensor s2 = new ChannelAccessDoubleArraySensor("id2", cservice.createChannel(new ChannelDescriptor<>(double[].class, wfChannel,false, 10))); + Sensor s = new ChannelAccessSensor<>("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel))); // Positioner Readback + Sensor s1 = new ChannelAccessSensor<>("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel))); // Scalar Detector + Sensor s1string = new ChannelAccessSensor<>("id3", cservice.createChannel(new ChannelDescriptor<>(String.class, boChannel+".NAME"))); // Scalar String Detector + Sensor s2 = new ChannelAccessSensor<>("id2", cservice.createChannel(new ChannelDescriptor<>(double[].class, wfChannel,false, 10))); loopOne.getActors().add(a); loopOne.getSensors().add(s); @@ -144,8 +143,8 @@ public class ActorSensorLoopTest { ActorSensorLoop loop = new ActorSensorLoop(); int numberOfSensors = 2; - ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel))); - ChannelAccessDoubleSensor s2 = new ChannelAccessDoubleSensor("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel))); + Sensor s1 = new ChannelAccessSensor<>("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel))); + Sensor s2 = new ChannelAccessSensor<>("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel))); loop.getSensors().add(s1); loop.getSensors().add(s2); @@ -183,9 +182,9 @@ public class ActorSensorLoopTest { ChannelAccessLinearActuator a = new ChannelAccessLinearActuator<>(cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)), null, 1,0, 0, 1.5, 0.1,timeout); // Positioner - ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel))); - ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel))); - ChannelAccessDoubleArraySensor s2 = new ChannelAccessDoubleArraySensor("id2", cservice.createChannel(new ChannelDescriptor<>(double[].class,wfChannel, false,10))); + Sensor s = new ChannelAccessSensor<>("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel))); + Sensor s1 = new ChannelAccessSensor<>("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel))); + Sensor s2 = new ChannelAccessSensor<>("id2", cservice.createChannel(new ChannelDescriptor<>(double[].class,wfChannel, false,10))); loop.getActors().add(a); loop.getPostActorActions().add(new Delay(500)); @@ -270,7 +269,7 @@ public class ActorSensorLoopTest { ChannelAccessLinearActuator a = new ChannelAccessLinearActuator<>(cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)), null, 1,0, 0, (steps*0.1), 0.1, timeout); // Positioner - ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel))); + Sensor s = new ChannelAccessSensor<>("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel))); loop.getActors().add(a); loop.getActors().add(new Actor() { diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleSensorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleSensorTest.java deleted file mode 100644 index 44c8ded..0000000 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleSensorTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * - * Copyright 2010 Paul Scherrer Institute. All rights reserved. - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This code is distributed in the hope that it will be useful, - * but without any warranty; without even the implied warranty of - * merchantability or fitness for a particular purpose. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - * - */ - -package ch.psi.fda.core.sensors; - -import static org.junit.Assert.*; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import java.util.logging.Logger; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import ch.psi.fda.TestChannels; -import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor; -import ch.psi.jcae.Channel; -import ch.psi.jcae.ChannelDescriptor; -import ch.psi.jcae.ChannelException; -import ch.psi.jcae.ChannelService; -import ch.psi.jcae.impl.DefaultChannelService; - -/** - * Test class for the ScalarDoubleSensorChannelAccess class. - * @author ebner - * - */ -public class ChannelAccessDoubleSensorTest { - - private static Logger logger = Logger.getLogger(ChannelAccessDoubleSensorTest.class.getName()); - - private static final String channelName = TestChannels.ANALOG_OUT; - private ChannelService cservice; - - @Before - public void setUp() throws Exception { - cservice = new DefaultChannelService(); - } - - @After - public void tearDown() throws Exception { - cservice.destroy(); - } - - @Test - public void testRead() throws InterruptedException, ChannelException, TimeoutException, ExecutionException { - Channel channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, channelName)); - ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor("id0", channel); - - // Prepare sensor channel - Double setValue = 0.1d; - channel.setValue(setValue); - - // Get sensor readout value - Double value = (Double) sensor.read(); - logger.finest("Sensor value: "+value); - if(!value.equals(setValue)){ - fail("Sensor readout value does not match actual value"); - } - } - -} diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessSensorTest.java similarity index 55% rename from ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensorTest.java rename to ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessSensorTest.java index 20c764a..85453aa 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensorTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessSensorTest.java @@ -20,19 +20,18 @@ package ch.psi.fda.core.sensors; import static org.junit.Assert.*; +import gov.aps.jca.CAException; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import java.util.logging.Logger; -import gov.aps.jca.CAException; - import org.junit.After; import org.junit.Before; import org.junit.Test; import ch.psi.fda.TestChannels; -import ch.psi.fda.core.sensors.ChannelAccessDoubleArraySensor; +import ch.psi.fda.core.Sensor; import ch.psi.jcae.Channel; import ch.psi.jcae.ChannelDescriptor; import ch.psi.jcae.ChannelException; @@ -44,12 +43,10 @@ import ch.psi.jcae.impl.DefaultChannelService; * @author ebner * */ -public class ChannelAccessDoubleArraySensorTest { +public class ChannelAccessSensorTest { - private static Logger logger = Logger.getLogger(ChannelAccessDoubleArraySensorTest.class.getName()); + private static Logger logger = Logger.getLogger(ChannelAccessSensorTest.class.getName()); - private static final String channelName = TestChannels.DOUBLE_WAVEFORM; - private static final int numberOfPoints = 10; private ChannelService cservice; @Before @@ -63,9 +60,49 @@ public class ChannelAccessDoubleArraySensorTest { } @Test - public void testRead() throws CAException, InterruptedException, ChannelException, TimeoutException, ExecutionException { + public void testReadDouble() throws InterruptedException, ChannelException, TimeoutException, ExecutionException { + final String channelName = TestChannels.ANALOG_OUT; + + Channel channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, channelName)); + Sensor sensor = new ChannelAccessSensor<>("id0", channel); + + // Prepare sensor channel + Double setValue = 0.1d; + channel.setValue(setValue); + + // Get sensor readout value + Double value = (Double) sensor.read(); + logger.finest("Sensor value: "+value); + if(!value.equals(setValue)){ + fail("Sensor readout value does not match actual value"); + } + } + + @Test + public void testReadString() throws CAException, InterruptedException, ChannelException, TimeoutException { + final String channelName = TestChannels.ANALOG_OUT+".NAME"; + final String actualValue = TestChannels.ANALOG_OUT; + + Channel channel = cservice.createChannel(new ChannelDescriptor<>(String.class, channelName)); + Sensor sensor = new ChannelAccessSensor<>("id0", channel); + + // Get sensor readout value + String value = (String) sensor.read(); + logger.info("Sensor value: "+value); + if(!value.equals(actualValue)){ + fail("Sensor readout "+value+" value does not match actual value "+actualValue); + } + } + + + @Test + public void testReadDoubleArray() throws CAException, InterruptedException, ChannelException, TimeoutException, ExecutionException { + + final String channelName = TestChannels.DOUBLE_WAVEFORM; + final int numberOfPoints = 10; + Channel channel = cservice.createChannel(new ChannelDescriptor<>(double[].class, channelName, false, numberOfPoints)); - ChannelAccessDoubleArraySensor sensor = new ChannelAccessDoubleArraySensor("id0", channel); + Sensor sensor = new ChannelAccessSensor<>("id0", channel); // Prepare sensor channel double[] setValue = new double[] { 0.1,0.2,0.3,4,5,6,77,88,99,10.2}; diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessStringSensorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessStringSensorTest.java deleted file mode 100644 index bb33c59..0000000 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessStringSensorTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * - * Copyright 2010 Paul Scherrer Institute. All rights reserved. - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This code is distributed in the hope that it will be useful, - * but without any warranty; without even the implied warranty of - * merchantability or fitness for a particular purpose. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - * - */ - -package ch.psi.fda.core.sensors; - -import static org.junit.Assert.*; - -import java.util.concurrent.TimeoutException; -import java.util.logging.Logger; - -import gov.aps.jca.CAException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import ch.psi.fda.TestChannels; -import ch.psi.jcae.Channel; -import ch.psi.jcae.ChannelDescriptor; -import ch.psi.jcae.ChannelException; -import ch.psi.jcae.ChannelService; -import ch.psi.jcae.impl.DefaultChannelService; - -/** - * Test class for the ScalarDoubleSensorChannelAccess class. - * @author ebner - * - */ -public class ChannelAccessStringSensorTest { - - private static Logger logger = Logger.getLogger(ChannelAccessStringSensorTest.class.getName()); - - private static final String channelName = TestChannels.ANALOG_OUT+".NAME"; - private static final String actualValue = TestChannels.ANALOG_OUT; - - private ChannelService cservice; - - @Before - public void setUp() throws Exception { - cservice = new DefaultChannelService(); - } - - @After - public void tearDown() throws Exception { - cservice.destroy(); - } - - @Test - public void testRead() throws CAException, InterruptedException, ChannelException, TimeoutException { - Channel channel = cservice.createChannel(new ChannelDescriptor<>(String.class, channelName)); - ChannelAccessStringSensor sensor = new ChannelAccessStringSensor("id0", channel); - - // Get sensor readout value - String value = (String) sensor.read(); - logger.info("Sensor value: "+value); - if(!value.equals(actualValue)){ - fail("Sensor readout "+value+" value does not match actual value "+actualValue); - } - } - -} diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ComplexSensorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ComplexSensorTest.java deleted file mode 100644 index 696b23d..0000000 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ComplexSensorTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/** - * - * Copyright 2010 Paul Scherrer Institute. All rights reserved. - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This code is distributed in the hope that it will be useful, - * but without any warranty; without even the implied warranty of - * merchantability or fitness for a particular purpose. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - * - */ - -package ch.psi.fda.core.sensors; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import java.util.logging.Logger; - -import gov.aps.jca.CAException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import ch.psi.fda.TestChannels; -import ch.psi.fda.core.Action; -import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor; -import ch.psi.fda.core.sensors.ComplexSensor; -import ch.psi.jcae.Channel; -import ch.psi.jcae.ChannelDescriptor; -import ch.psi.jcae.ChannelException; -import ch.psi.jcae.ChannelService; -import ch.psi.jcae.impl.DefaultChannelService; - -/** - * Test class for the ScalarDoubleSensorChannelAccess class. - * @author ebner - * - */ -public class ComplexSensorTest { - - // Get Logger - private static Logger logger = Logger.getLogger(ComplexSensorTest.class.getName()); - - private static final String channelName = TestChannels.ANALOG_OUT; - private ChannelService cservice; - - @Before - public void setUp() throws Exception { - cservice = new DefaultChannelService(); - } - - @After - public void tearDown() throws Exception { - cservice.destroy(); - } - - /** - * Test method for {@link ch.psi.fda.core.sensors.ChannelAccessDoubleSensor#read()}. - * @throws CAException - * @throws ChannelException - * @throws ExecutionException - * @throws TimeoutException - */ - @Test - public void testRead() throws CAException, InterruptedException, ExecutionException, ChannelException, TimeoutException { - - final HashMap timestamps = new HashMap(); - Channel channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, channelName)); - ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id0", channel); - ComplexSensor sensor = new ComplexSensor("id2", s1); - - // Add pre action - sensor.getPreActions().add(new Action() { - - @Override - public void execute() { - logger.info("PreAction"); - timestamps.put("pre", System.currentTimeMillis()); - } - - @Override - public void destroy() { - } - - @Override - public void abort() { - } - }); - - // Add post action - sensor.getPostActions().add(new Action() { - - @Override - public void execute() { - logger.info("PostAction"); - timestamps.put("post", System.currentTimeMillis()); - } - - @Override - public void destroy() { - } - - @Override - public void abort() { - } - }); - - // Prepare sensor channel - Double setValue = 0.1d; - channel.setValue(setValue); - - // Get sensor readout value - Double value = (Double) sensor.read(); - - logger.finest("Sensor value: "+value); - if(!value.equals(setValue)){ - fail("Sensor readout value does not match actual value"); - } - - if(timestamps.get("post")