diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/AtomicIndividualAction.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/AtomicIndividualAction.java index 0e0101b5e4bc226e17932d2cf5b3708129a183f3..226fc02f7d00b3e6d22151d21b8b8d154e4ab8c5 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/AtomicIndividualAction.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/AtomicIndividualAction.java @@ -16,18 +16,15 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Ta * @author CLAISSE */ public abstract class AtomicIndividualAction extends AbstractIndividualAction { - private final Logger logger = LoggerFactory.getLogger(AtomicIndividualAction.class); + + private static final Logger LOGGER = LoggerFactory.getLogger(AtomicIndividualAction.class); /** - * @param _listener - * The listener to notify on read completion - * @param _target - * The device to read from - * @param _attributesToRead - * The attributes to read + * @param listener The listener to notify on read completion + * @param target The device to read from */ - public AtomicIndividualAction(final MinimalistActionListener _listener, final Target _target) { - super(_listener, _target); + public AtomicIndividualAction(final MinimalistActionListener listener, final Target target) { + super(listener, target); } /* @@ -37,21 +34,21 @@ public abstract class AtomicIndividualAction extends AbstractIndividualAction { */ @Override public void run() { - try { - final ActionResult result = executeAtomicAction(); - listener.actionSucceeded(target.get_name(), result); - } catch (final Throwable t) { - logger.error("error on {}", target.get_name()); - logger.error("error ", t); - if (t instanceof DevFailed) { - logger.error("tango error {}", DevFailedUtils.toString((DevFailed) t)); - } - listener.actionFailed(target.get_name(), null, t); - } finally { - listener.actionCompleted(); // Latch countdown in the finally clause - // to avoid deadlocks in case of read - // failure - } + try { + final ActionResult result = executeAtomicAction(); + listener.actionSucceeded(target.get_name(), result); + } catch (final Throwable t) { + LOGGER.error("error on {}", target.get_name()); + LOGGER.error("error ", t); + if (t instanceof DevFailed) { + LOGGER.error("tango error {}", DevFailedUtils.toString((DevFailed) t)); + } + listener.actionFailed(target.get_name(), null, t); + } finally { + listener.actionCompleted(); // Latch countdown in the finally clause + // to avoid deadlocks in case of read + // failure + } } protected abstract ActionResult executeAtomicAction() throws Throwable; diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/ReadAttributes.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/ReadAttributes.java index 86478ec989e6d114f82bb7a4ecd7c924a67347f5..a64073059e0c80ce78d4c3067c36b687458885fc 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/ReadAttributes.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/ReadAttributes.java @@ -1,38 +1,68 @@ package fr.soleil.actiongroup.collectiveaction.components.singleaction.atomic; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tango.utils.DevFailedUtils; + +import fr.esrf.Tango.DevFailed; import fr.soleil.actiongroup.collectiveaction.components.singleactioncompletelistener.MinimalistActionListener; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.ActionResult; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DeviceAttributeWrapper; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Target; /** - * Reads attributes from a device. Notifies its listener on completion. - * @author CLAISSE + * Reads attributes from a device. Notifies its listener on completion. + * + * @author CLAISSE */ -public class ReadAttributes extends AtomicIndividualAction -{ +public class ReadAttributes extends AtomicIndividualAction { + + private static final Logger LOGGER = LoggerFactory.getLogger(ReadAttributes.class); + /** * The attributes to read */ - private String[] attributesToRead; - + private final String[] attributesToRead; + /** - * @param _listener The listener to notify on read completion - * @param _target The device to read from - * @param _attributesToRead The attributes to read + * @param listener The listener to notify on read completion + * @param target The device to read from + * @param attributesToRead The attributes to read */ - public ReadAttributes ( MinimalistActionListener _listener , Target _target , String[] _attributesToRead ) - { - super ( _listener , _target ); - this.attributesToRead = _attributesToRead; + public ReadAttributes(MinimalistActionListener listener, Target target, String[] attributesToRead) { + super(listener, target); + this.attributesToRead = attributesToRead; } @Override - protected ActionResult executeAtomicAction() throws Throwable - { - long before = System.currentTimeMillis (); - DeviceAttributeWrapper [] response = this.target.read_attribute ( this.attributesToRead ); - long readTime = System.currentTimeMillis () - before; - - return new ActionResult ( response , readTime ); + protected ActionResult executeAtomicAction() throws Throwable { + long before = System.currentTimeMillis(); + DeviceAttributeWrapper[] response = null; + try { + response = this.target.read_attribute(this.attributesToRead); + } catch (Throwable t) { + StringBuilder builder = new StringBuilder(); + if (attributesToRead == null) { + builder.append("Failed to read attributes as attribute list is null"); + } else if (attributesToRead.length == 0) { + builder.append("Failed to read attributes as there is no attribute to read"); + } else { + builder.append("Failed to read following attributes:"); + for (String attr : attributesToRead) { + builder.append("\n- ").append(attr); + } + builder.append("\nReason:\n"); + if (t instanceof DevFailed) { + builder.append(DevFailedUtils.toString((DevFailed) t)); + } else { + builder.append(t.getMessage()); + } + } + LOGGER.error(builder.toString(), t); + throw t; + } + long readTime = System.currentTimeMillis() - before; + + return new ActionResult(response, readTime); } } \ No newline at end of file diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/ReadAttributesImpl.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/ReadAttributesImpl.java index 7e0fcddad76118d6a2392c45a9a674da47d0bd53..24fd0402d2c2be8170f48325039fe372c25e4653 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/ReadAttributesImpl.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/ReadAttributesImpl.java @@ -6,25 +6,23 @@ import fr.soleil.actiongroup.collectiveaction.components.singleaction.atomic.Rea import fr.soleil.actiongroup.collectiveaction.components.singleactioncompletelistener.ActionListener; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Target; - /** * A group that read attributes from its members - * @author CLAISSE + * + * @author CLAISSE */ -public abstract class ReadAttributesImpl extends CollectiveActionImpl -{ - /** - * @param _proxies The devices to read from - * @param _attributes The list of attributes to read for each device +public abstract class ReadAttributesImpl extends CollectiveActionImpl { + + /** + * @param proxies The devices to read from + * @param attributes The list of attributes to read for each device */ - public ReadAttributesImpl(Target[] _proxies, String[][] _attributes ) - { - super ( _proxies , _attributes ); + public ReadAttributesImpl(Target[] proxies, String[][] attributes) { + super(proxies, attributes); } - + @Override - protected IndividualAction getTask ( int deviceIndex , ActionListener listener ) - { - return new ReadAttributes ( listener , targets [ deviceIndex ] , attributes [ deviceIndex ] ); + protected IndividualAction getTask(int deviceIndex, ActionListener listener) { + return new ReadAttributes(listener, targets[deviceIndex], attributes[deviceIndex]); } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/ReadGenericAttributesImpl.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/ReadGenericAttributesImpl.java index 1e0fb3097ccc026b91be0b39b86d3c7aeb2eb323..6812bc3c6f0093794739ff1eacc4c1ff0ceb2772 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/ReadGenericAttributesImpl.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/ReadGenericAttributesImpl.java @@ -9,51 +9,46 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Ta /** * An action group that read attributes of any types from its members. * It can use an IPluginAction implementation to call specific actions on each attribute. - * @author CLAISSE + * + * @author CLAISSE */ -public class ReadGenericAttributesImpl extends ReadAttributesImpl implements ReadGenericAttributes -{ +public class ReadGenericAttributesImpl extends ReadAttributesImpl implements ReadGenericAttributes { private boolean attributesAreSet = false; private BuildGroupListener buildGroupResponseListener; - + /** - * @param _targets The devices to read from + * @param targets The devices to read from */ - public ReadGenericAttributesImpl ( Target[] _targets ) - { - super ( _targets , null ); - - super.attributes = new String[_targets.length][]; + public ReadGenericAttributesImpl(Target[] targets) { + super(targets, null); + super.attributes = new String[targets.length][]; } - + @Override - protected ActionListener getTaskCompletionListener() - { - buildGroupResponseListener = new BuildAttributesGroupListenerImpl ( super.getBasicListener () ); + protected ActionListener getTaskCompletionListener() { + buildGroupResponseListener = new BuildAttributesGroupListenerImpl(super.getBasicListener()); return buildGroupResponseListener; } - public synchronized CollectiveResponse getGroupResponse () - { - if ( ! attributesAreSet ) - { - throw new IllegalStateException ( "ReadGenericAttributesActionGroup/getGroupResponse/the attributes are not set! Call setAttributesToRead first" ); + @Override + public synchronized CollectiveResponse getGroupResponse() { + if (!attributesAreSet) { + throw new IllegalStateException( + "ReadGenericAttributesActionGroup/getGroupResponse/the attributes are not set! Call setAttributesToRead first"); } - return buildGroupResponseListener.getGroupResponse (); + return buildGroupResponseListener.getGroupResponse(); } - - public synchronized void setAttributesToRead(String[] attributesToRead) - { - if ( attributesToRead == null || attributesToRead.length == 0 ) - { + + @Override + public synchronized void setAttributesToRead(String[] attributesToRead) { + if (attributesToRead == null || attributesToRead.length == 0) { return; } - - for ( int i = 0 ; i < super.attributes.length ; i ++ ) - { - super.attributes [ i ] = attributesToRead; + + for (int i = 0; i < super.attributes.length; i++) { + super.attributes[i] = attributesToRead; } - + this.attributesAreSet = true; } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/ReadNumericAttributesImpl.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/ReadNumericAttributesImpl.java index dbedf3986c17f804eadafbab6e4610448d6ddb66..1456bcd06740b6cd2440ca1b13e7993167123abf 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/ReadNumericAttributesImpl.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/ReadNumericAttributesImpl.java @@ -59,11 +59,11 @@ public class ReadNumericAttributesImpl extends ReadAttributesImpl implements Rea * Instantiates a new ReadNumericAttributesActionGroup. * Uses an inactive implementation of IAttributeQualityRegister (DoNothingAttributeQualityRegister). * - * @param _targets The devices to read from - * @param _attributes The list of attributes to read for each device + * @param targets The devices to read from + * @param attributes The list of attributes to read for each device */ - public ReadNumericAttributesImpl(Target[] _targets, String[][] _attributes) { - super(_targets, _attributes); + public ReadNumericAttributesImpl(Target[] targets, String[][] attributes) { + super(targets, attributes); this.attributeQualityRegister = new DoNothingAttributeQualityRegister(); } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/UsePluginImpl.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/UsePluginImpl.java index 0cf9224c28512abd332e14c1e0308a1c7d86ee2a..506a224fedeb256eea68e59238efac9434939619 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/UsePluginImpl.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/UsePluginImpl.java @@ -49,13 +49,13 @@ public class UsePluginImpl extends ReadAttributesImpl implements UsePlugin { private PluginContext context; /** - * @param _targets The devices to read from - * @param _attributes The list of attributes to read for each device - * @param _pluginAction The action to perform on each attribute + * @param targets The devices to read from + * @param attributes The list of attributes to read for each device + * @param pluginAction The action to perform on each attribute */ - public UsePluginImpl(Target[] _targets, String[][] _attributes, Plugin _pluginAction) { - super(_targets, _attributes); - this.pluginAction = _pluginAction; + public UsePluginImpl(Target[] targets, String[][] attributes, Plugin pluginAction) { + super(targets, attributes); + this.pluginAction = pluginAction; } @Override @@ -72,7 +72,7 @@ public class UsePluginImpl extends ReadAttributesImpl implements UsePlugin { } @Override - public synchronized void setPluginContext(PluginContext _context) { - this.context = _context; + public synchronized void setPluginContext(PluginContext context) { + this.context = context; } } diff --git a/src/main/java/fr/soleil/archiving/snap/api/SnapConnectionParameters.java b/src/main/java/fr/soleil/archiving/snap/api/SnapConnectionParameters.java index 828aecb42e3811143cd9b43475c1421e69662b43..ae41817087624583e5a3590499c5fff7b53264ca 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/SnapConnectionParameters.java +++ b/src/main/java/fr/soleil/archiving/snap/api/SnapConnectionParameters.java @@ -133,12 +133,17 @@ public class SnapConnectionParameters { initFromDefaultProperties(); } - public static void printSnapConnectionInfoLog() { - System.out.println("################"); - System.out.println("### Snapshot ###"); - System.out.println("################"); - snapInfoConnector.printLoggertrace(); - System.out.println("############################"); + public static StringBuilder appendSnapConnectionInfoLog(StringBuilder builder) { + StringBuilder result = builder; + if (result == null) { + result = new StringBuilder(); + } + result.append("################\n"); + result.append("### Snapshot ###\n"); + result.append("################\n"); + snapInfoConnector.appendLoggerTrace(result); + result.append("\n############################"); + return result; } } diff --git a/src/main/java/fr/soleil/archiving/snap/api/manager/SnapManagerApi.java b/src/main/java/fr/soleil/archiving/snap/api/manager/SnapManagerApi.java index f260a06930a7cbcb2c91d6d028f5776e21e0a2b4..d2efa4241c4791aa51b9405eac78dd6454d28f0e 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/manager/SnapManagerApi.java +++ b/src/main/java/fr/soleil/archiving/snap/api/manager/SnapManagerApi.java @@ -100,6 +100,9 @@ import java.util.Arrays; import java.util.List; import java.util.Random; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import fr.esrf.Tango.AttrDataFormat; import fr.esrf.Tango.AttrWriteType; import fr.esrf.Tango.DevFailed; @@ -128,6 +131,9 @@ import fr.soleil.archiving.snap.api.tools.SnapshotingException; import fr.soleil.lib.project.math.NumberArrayUtils; public class SnapManagerApi { + + private static final Logger LOGGER = LoggerFactory.getLogger(SnapManagerApi.class); + private static final String NAN_ARRAY = "[NaN]"; private static final String NAN = "NaN"; @@ -427,7 +433,8 @@ public class SnapManagerApi { SnapConnectionParameters.getSnapSchema(), SnapConnectionParameters.getSnapUser(), SnapConnectionParameters.getSnapPassword(), SnapConnectionParameters.isSnapRac()); - SnapConnectionParameters.printSnapConnectionInfoLog(); + LOGGER.info(SnapConnectionParameters.appendSnapConnectionInfoLog(new StringBuilder("Connection info:\n")) + .toString()); snapDataBase.connect_auto(); } @@ -469,7 +476,8 @@ public class SnapManagerApi { for (int i = 0; i < devslist.length; i++) { if (i > 1 && 0 == i % 2 && devslist[i].equalsIgnoreCase(device_name)) { device_name = devslist[i]; - // System.out.println("SnapManagerAPI.register: And the name of "+att_complete_name+" device is "+device_name); + // System.out.println("SnapManagerAPI.register: And the name of "+att_complete_name+" device is + // "+device_name); } } String attribute_name = att_complete_name.substring(index + 1); @@ -758,8 +766,8 @@ public class SnapManagerApi { * @return * @throws SnapshotingException */ - public static List<SnapAttributeExtract> getSnapshotAssociatedAttributes(final SnapshotLight snapshot, int contextID) - throws SnapshotingException { + public static List<SnapAttributeExtract> getSnapshotAssociatedAttributes(final SnapshotLight snapshot, + int contextID) throws SnapshotingException { if (snapDataBase == null) { throw new SnapshotingException(DATA_BASE_API_NOT_INIT); } diff --git a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dao/AbstractValDAO.java b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dao/AbstractValDAO.java index d23419b591247f78de92ac9a5c62dde9243fd8b4..6808b62ca861d27fefdd9bc5fe3914f5effa52b3 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dao/AbstractValDAO.java +++ b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dao/AbstractValDAO.java @@ -10,28 +10,37 @@ import fr.soleil.archiving.snap.api.persistence.spring.dto.Val; public abstract class AbstractValDAO<V extends Val> implements ValDAO<V> { - private final Logger logger = LoggerFactory.getLogger(AbstractValDAO.class); + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractValDAO.class); protected HibernateTemplate hibernateTemplate; public AbstractValDAO(final SessionFactory sessionFactory) { - this.hibernateTemplate = new HibernateTemplate(sessionFactory); + this.hibernateTemplate = new HibernateTemplate(sessionFactory); } @Override public V create(final V line) { - logger.debug("saving hibernate " + line); - hibernateTemplate.save(line); - // throw new RuntimeException(); Uncomment to test correct rollback - // management - return line; + LOGGER.debug("saving hibernate " + line); + try { + hibernateTemplate.save(line); + } catch (Exception e) { + LOGGER.error("hibernate save error", e); + } + // throw new RuntimeException(); Uncomment to test correct rollback + // management + return line; } @Override public V findByKey(final CompositeId compositeId) { - final Class<V> valueClass = this.getValueClass(); - final Object res = hibernateTemplate.get(valueClass, compositeId); - final V line = valueClass.cast(res); - return line; + V line = null; + try { + final Class<V> valueClass = this.getValueClass(); + final Object res = hibernateTemplate.get(valueClass, compositeId); + line = valueClass.cast(res); + } catch (Exception e) { + LOGGER.error("hibernate find error", e); + } + return line; } protected abstract Class<V> getValueClass();