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
No related branches found
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
* @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);
}
/*
......@@ -41,10 +38,10 @@ public abstract class AtomicIndividualAction extends AbstractIndividualAction {
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);
LOGGER.error("error on {}", target.get_name());
LOGGER.error("error ", t);
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);
} finally {
......
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;
......@@ -6,31 +12,55 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Ta
/**
* 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
{
protected ActionResult executeAtomicAction() throws Throwable {
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;
return new ActionResult(response, readTime);
......
......@@ -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
*/
public abstract class ReadAttributesImpl extends CollectiveActionImpl
{
public abstract class ReadAttributesImpl extends CollectiveActionImpl {
/**
* @param _proxies The devices to read from
* @param _attributes The list of attributes to read for each device
* @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 )
{
protected IndividualAction getTask(int deviceIndex, ActionListener listener) {
return new ReadAttributes(listener, targets[deviceIndex], attributes[deviceIndex]);
}
}
......@@ -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.
* It can use an IPluginAction implementation to call specific actions on each attribute.
*
* @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()
{
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();
}
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 ++ )
{
for (int i = 0; i < super.attributes.length; i++) {
super.attributes[i] = attributesToRead;
}
......
......@@ -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();
}
......
......@@ -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;
}
}
......@@ -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;
}
}
......@@ -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);
}
......
......@@ -10,7 +10,7 @@ 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) {
......@@ -19,8 +19,12 @@ public abstract class AbstractValDAO<V extends Val> implements ValDAO<V> {
@Override
public V create(final V line) {
logger.debug("saving hibernate " + 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;
......@@ -28,9 +32,14 @@ public abstract class AbstractValDAO<V extends Val> implements ValDAO<V> {
@Override
public V findByKey(final CompositeId compositeId) {
V line = null;
try {
final Class<V> valueClass = this.getValueClass();
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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment