Skip to content
Snippets Groups Projects
Commit 80df3f70 authored by Raphael GIRARDOT's avatar Raphael GIRARDOT
Browse files

- No more use of println: Prefer using slf4j Logger (will help PROBLEM-1604).

- Less silent errors and more use of slf4j Logger (will help PROBLEM-1604).
- Respect java naming convention.
parent d9e09d93
Branches
No related tags found
No related merge requests found
Showing
with 163 additions and 121 deletions
...@@ -16,18 +16,15 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Ta ...@@ -16,18 +16,15 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Ta
* @author CLAISSE * @author CLAISSE
*/ */
public abstract class AtomicIndividualAction extends AbstractIndividualAction { 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 * @param listener The listener to notify on read completion
* The listener to notify on read completion * @param target The device to read from
* @param _target
* The device to read from
* @param _attributesToRead
* The attributes to read
*/ */
public AtomicIndividualAction(final MinimalistActionListener _listener, final Target _target) { public AtomicIndividualAction(final MinimalistActionListener listener, final Target target) {
super(_listener, _target); super(listener, target);
} }
/* /*
...@@ -41,10 +38,10 @@ public abstract class AtomicIndividualAction extends AbstractIndividualAction { ...@@ -41,10 +38,10 @@ public abstract class AtomicIndividualAction extends AbstractIndividualAction {
final ActionResult result = executeAtomicAction(); final ActionResult result = executeAtomicAction();
listener.actionSucceeded(target.get_name(), result); listener.actionSucceeded(target.get_name(), result);
} catch (final Throwable t) { } catch (final Throwable t) {
logger.error("error on {}", target.get_name()); LOGGER.error("error on {}", target.get_name());
logger.error("error ", t); LOGGER.error("error ", t);
if (t instanceof DevFailed) { if (t instanceof DevFailed) {
logger.error("tango error {}", DevFailedUtils.toString((DevFailed) t)); LOGGER.error("tango error {}", DevFailedUtils.toString((DevFailed) t));
} }
listener.actionFailed(target.get_name(), null, t); listener.actionFailed(target.get_name(), null, t);
} finally { } finally {
......
package fr.soleil.actiongroup.collectiveaction.components.singleaction.atomic; 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.singleactioncompletelistener.MinimalistActionListener;
import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.ActionResult; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.ActionResult;
import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DeviceAttributeWrapper; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DeviceAttributeWrapper;
...@@ -6,31 +12,55 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Ta ...@@ -6,31 +12,55 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Ta
/** /**
* Reads attributes from a device. Notifies its listener on completion. * Reads attributes from a device. Notifies its listener on completion.
*
* @author CLAISSE * @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 * The attributes to read
*/ */
private String[] attributesToRead; private final String[] attributesToRead;
/** /**
* @param _listener The listener to notify on read completion * @param listener The listener to notify on read completion
* @param _target The device to read from * @param target The device to read from
* @param _attributesToRead The attributes to read * @param attributesToRead The attributes to read
*/ */
public ReadAttributes ( MinimalistActionListener _listener , Target _target , String[] _attributesToRead ) public ReadAttributes(MinimalistActionListener listener, Target target, String[] attributesToRead) {
{ super(listener, target);
super ( _listener , _target ); this.attributesToRead = attributesToRead;
this.attributesToRead = _attributesToRead;
} }
@Override @Override
protected ActionResult executeAtomicAction() throws Throwable protected ActionResult executeAtomicAction() throws Throwable {
{
long before = System.currentTimeMillis(); long before = System.currentTimeMillis();
DeviceAttributeWrapper [] response = this.target.read_attribute ( this.attributesToRead ); 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; long readTime = System.currentTimeMillis() - before;
return new ActionResult(response, readTime); return new ActionResult(response, readTime);
......
...@@ -6,25 +6,23 @@ import fr.soleil.actiongroup.collectiveaction.components.singleaction.atomic.Rea ...@@ -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.singleactioncompletelistener.ActionListener;
import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Target; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Target;
/** /**
* A group that read attributes from its members * A group that read attributes from its members
*
* @author CLAISSE * @author CLAISSE
*/ */
public abstract class ReadAttributesImpl extends CollectiveActionImpl public abstract class ReadAttributesImpl extends CollectiveActionImpl {
{
/** /**
* @param _proxies The devices to read from * @param proxies The devices to read from
* @param _attributes The list of attributes to read for each device * @param attributes The list of attributes to read for each device
*/ */
public ReadAttributesImpl(Target[] _proxies, String[][] _attributes ) public ReadAttributesImpl(Target[] proxies, String[][] attributes) {
{ super(proxies, attributes);
super ( _proxies , _attributes );
} }
@Override @Override
protected IndividualAction getTask ( int deviceIndex , ActionListener listener ) protected IndividualAction getTask(int deviceIndex, ActionListener listener) {
{
return new ReadAttributes(listener, targets[deviceIndex], attributes[deviceIndex]); return new ReadAttributes(listener, targets[deviceIndex], attributes[deviceIndex]);
} }
} }
...@@ -9,48 +9,43 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Ta ...@@ -9,48 +9,43 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Ta
/** /**
* An action group that read attributes of any types from its members. * 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. * 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 boolean attributesAreSet = false;
private BuildGroupListener buildGroupResponseListener; private BuildGroupListener buildGroupResponseListener;
/** /**
* @param _targets The devices to read from * @param targets The devices to read from
*/ */
public ReadGenericAttributesImpl ( Target[] _targets ) public ReadGenericAttributesImpl(Target[] targets) {
{ super(targets, null);
super ( _targets , null ); super.attributes = new String[targets.length][];
super.attributes = new String[_targets.length][];
} }
@Override @Override
protected ActionListener getTaskCompletionListener() protected ActionListener getTaskCompletionListener() {
{
buildGroupResponseListener = new BuildAttributesGroupListenerImpl(super.getBasicListener()); buildGroupResponseListener = new BuildAttributesGroupListenerImpl(super.getBasicListener());
return buildGroupResponseListener; return buildGroupResponseListener;
} }
public synchronized CollectiveResponse getGroupResponse () @Override
{ public synchronized CollectiveResponse getGroupResponse() {
if ( ! attributesAreSet ) if (!attributesAreSet) {
{ throw new IllegalStateException(
throw new IllegalStateException ( "ReadGenericAttributesActionGroup/getGroupResponse/the attributes are not set! Call setAttributesToRead first" ); "ReadGenericAttributesActionGroup/getGroupResponse/the attributes are not set! Call setAttributesToRead first");
} }
return buildGroupResponseListener.getGroupResponse(); return buildGroupResponseListener.getGroupResponse();
} }
public synchronized void setAttributesToRead(String[] attributesToRead) @Override
{ public synchronized void setAttributesToRead(String[] attributesToRead) {
if ( attributesToRead == null || attributesToRead.length == 0 ) if (attributesToRead == null || attributesToRead.length == 0) {
{
return; return;
} }
for ( int i = 0 ; i < super.attributes.length ; i ++ ) for (int i = 0; i < super.attributes.length; i++) {
{
super.attributes[i] = attributesToRead; super.attributes[i] = attributesToRead;
} }
......
...@@ -59,11 +59,11 @@ public class ReadNumericAttributesImpl extends ReadAttributesImpl implements Rea ...@@ -59,11 +59,11 @@ public class ReadNumericAttributesImpl extends ReadAttributesImpl implements Rea
* Instantiates a new ReadNumericAttributesActionGroup. * Instantiates a new ReadNumericAttributesActionGroup.
* Uses an inactive implementation of IAttributeQualityRegister (DoNothingAttributeQualityRegister). * Uses an inactive implementation of IAttributeQualityRegister (DoNothingAttributeQualityRegister).
* *
* @param _targets The devices to read from * @param targets The devices to read from
* @param _attributes The list of attributes to read for each device * @param attributes The list of attributes to read for each device
*/ */
public ReadNumericAttributesImpl(Target[] _targets, String[][] _attributes) { public ReadNumericAttributesImpl(Target[] targets, String[][] attributes) {
super(_targets, _attributes); super(targets, attributes);
this.attributeQualityRegister = new DoNothingAttributeQualityRegister(); this.attributeQualityRegister = new DoNothingAttributeQualityRegister();
} }
......
...@@ -49,13 +49,13 @@ public class UsePluginImpl extends ReadAttributesImpl implements UsePlugin { ...@@ -49,13 +49,13 @@ public class UsePluginImpl extends ReadAttributesImpl implements UsePlugin {
private PluginContext context; private PluginContext context;
/** /**
* @param _targets The devices to read from * @param targets The devices to read from
* @param _attributes The list of attributes to read for each device * @param attributes The list of attributes to read for each device
* @param _pluginAction The action to perform on each attribute * @param pluginAction The action to perform on each attribute
*/ */
public UsePluginImpl(Target[] _targets, String[][] _attributes, Plugin _pluginAction) { public UsePluginImpl(Target[] targets, String[][] attributes, Plugin pluginAction) {
super(_targets, _attributes); super(targets, attributes);
this.pluginAction = _pluginAction; this.pluginAction = pluginAction;
} }
@Override @Override
...@@ -72,7 +72,7 @@ public class UsePluginImpl extends ReadAttributesImpl implements UsePlugin { ...@@ -72,7 +72,7 @@ public class UsePluginImpl extends ReadAttributesImpl implements UsePlugin {
} }
@Override @Override
public synchronized void setPluginContext(PluginContext _context) { public synchronized void setPluginContext(PluginContext context) {
this.context = _context; this.context = context;
} }
} }
...@@ -133,12 +133,17 @@ public class SnapConnectionParameters { ...@@ -133,12 +133,17 @@ public class SnapConnectionParameters {
initFromDefaultProperties(); initFromDefaultProperties();
} }
public static void printSnapConnectionInfoLog() { public static StringBuilder appendSnapConnectionInfoLog(StringBuilder builder) {
System.out.println("################"); StringBuilder result = builder;
System.out.println("### Snapshot ###"); if (result == null) {
System.out.println("################"); result = new StringBuilder();
snapInfoConnector.printLoggertrace(); }
System.out.println("############################"); result.append("################\n");
result.append("### Snapshot ###\n");
result.append("################\n");
snapInfoConnector.appendLoggerTrace(result);
result.append("\n############################");
return result;
} }
} }
...@@ -100,6 +100,9 @@ import java.util.Arrays; ...@@ -100,6 +100,9 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.esrf.Tango.AttrDataFormat; import fr.esrf.Tango.AttrDataFormat;
import fr.esrf.Tango.AttrWriteType; import fr.esrf.Tango.AttrWriteType;
import fr.esrf.Tango.DevFailed; import fr.esrf.Tango.DevFailed;
...@@ -128,6 +131,9 @@ import fr.soleil.archiving.snap.api.tools.SnapshotingException; ...@@ -128,6 +131,9 @@ import fr.soleil.archiving.snap.api.tools.SnapshotingException;
import fr.soleil.lib.project.math.NumberArrayUtils; import fr.soleil.lib.project.math.NumberArrayUtils;
public class SnapManagerApi { public class SnapManagerApi {
private static final Logger LOGGER = LoggerFactory.getLogger(SnapManagerApi.class);
private static final String NAN_ARRAY = "[NaN]"; private static final String NAN_ARRAY = "[NaN]";
private static final String NAN = "NaN"; private static final String NAN = "NaN";
...@@ -427,7 +433,8 @@ public class SnapManagerApi { ...@@ -427,7 +433,8 @@ public class SnapManagerApi {
SnapConnectionParameters.getSnapSchema(), SnapConnectionParameters.getSnapUser(), SnapConnectionParameters.getSnapSchema(), SnapConnectionParameters.getSnapUser(),
SnapConnectionParameters.getSnapPassword(), SnapConnectionParameters.isSnapRac()); SnapConnectionParameters.getSnapPassword(), SnapConnectionParameters.isSnapRac());
SnapConnectionParameters.printSnapConnectionInfoLog(); LOGGER.info(SnapConnectionParameters.appendSnapConnectionInfoLog(new StringBuilder("Connection info:\n"))
.toString());
snapDataBase.connect_auto(); snapDataBase.connect_auto();
} }
...@@ -469,7 +476,8 @@ public class SnapManagerApi { ...@@ -469,7 +476,8 @@ public class SnapManagerApi {
for (int i = 0; i < devslist.length; i++) { for (int i = 0; i < devslist.length; i++) {
if (i > 1 && 0 == i % 2 && devslist[i].equalsIgnoreCase(device_name)) { if (i > 1 && 0 == i % 2 && devslist[i].equalsIgnoreCase(device_name)) {
device_name = devslist[i]; 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); String attribute_name = att_complete_name.substring(index + 1);
...@@ -758,8 +766,8 @@ public class SnapManagerApi { ...@@ -758,8 +766,8 @@ public class SnapManagerApi {
* @return * @return
* @throws SnapshotingException * @throws SnapshotingException
*/ */
public static List<SnapAttributeExtract> getSnapshotAssociatedAttributes(final SnapshotLight snapshot, int contextID) public static List<SnapAttributeExtract> getSnapshotAssociatedAttributes(final SnapshotLight snapshot,
throws SnapshotingException { int contextID) throws SnapshotingException {
if (snapDataBase == null) { if (snapDataBase == null) {
throw new SnapshotingException(DATA_BASE_API_NOT_INIT); throw new SnapshotingException(DATA_BASE_API_NOT_INIT);
} }
......
...@@ -10,7 +10,7 @@ import fr.soleil.archiving.snap.api.persistence.spring.dto.Val; ...@@ -10,7 +10,7 @@ import fr.soleil.archiving.snap.api.persistence.spring.dto.Val;
public abstract class AbstractValDAO<V extends Val> implements ValDAO<V> { 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; protected HibernateTemplate hibernateTemplate;
public AbstractValDAO(final SessionFactory sessionFactory) { public AbstractValDAO(final SessionFactory sessionFactory) {
...@@ -19,8 +19,12 @@ public abstract class AbstractValDAO<V extends Val> implements ValDAO<V> { ...@@ -19,8 +19,12 @@ public abstract class AbstractValDAO<V extends Val> implements ValDAO<V> {
@Override @Override
public V create(final V line) { public V create(final V line) {
logger.debug("saving hibernate " + line); LOGGER.debug("saving hibernate " + line);
try {
hibernateTemplate.save(line); hibernateTemplate.save(line);
} catch (Exception e) {
LOGGER.error("hibernate save error", e);
}
// throw new RuntimeException(); Uncomment to test correct rollback // throw new RuntimeException(); Uncomment to test correct rollback
// management // management
return line; return line;
...@@ -28,9 +32,14 @@ public abstract class AbstractValDAO<V extends Val> implements ValDAO<V> { ...@@ -28,9 +32,14 @@ public abstract class AbstractValDAO<V extends Val> implements ValDAO<V> {
@Override @Override
public V findByKey(final CompositeId compositeId) { public V findByKey(final CompositeId compositeId) {
V line = null;
try {
final Class<V> valueClass = this.getValueClass(); final Class<V> valueClass = this.getValueClass();
final Object res = hibernateTemplate.get(valueClass, compositeId); final Object res = hibernateTemplate.get(valueClass, compositeId);
final V line = valueClass.cast(res); line = valueClass.cast(res);
} catch (Exception e) {
LOGGER.error("hibernate find error", e);
}
return line; return line;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment