[ 
https://issues.apache.org/jira/browse/QPID-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12598284#action_12598284
 ] 

Rob Godfrey commented on QPID-1018:
-----------------------------------

Personally I prefer a variant of option 2; where the type information is 
preserved...

Something like

abstract public class ConfigurationProperty<T extends Object>
{

    private static final Logger _logger = 
LoggerFactory.getLogger(ConfigurationProperty.class);

    static final Map<String, ConfigurationProperty<? extends Object>> 
_propertiesMap = new HashMap<String, ConfigurationProperty<? extends 
Object>>();    

    private final String _name;
    private T _value;


    protected ConfigurationProperty(Class<T> clazz, String name, String 
systemProperty, T defaultValue)
    {
        _name = name;

        T value = null;

        if(systemProperty != null && 
System.getProperties().containsKey(systemProperty))
        {
            String systemPropertyValue = System.getProperty(systemProperty);

            try
            {
                Constructor<T> constructor = clazz.getConstructor(String.class);
                value = constructor.newInstance(systemPropertyValue);
            }
            catch (NoSuchMethodException e)
            {
                _logger.error("Unable to find constructor for class "
                              + clazz.getName()
                              + " for configuration property "
                              + name, e);
            }
            catch (InvocationTargetException e)
            {
                _logger.error("Unable to execute constructor for class "
                              + clazz.getName()
                              + " for configuration property "
                              + name, e);
            }
            catch (IllegalAccessException e)
            {
                _logger.error("Unable to access constructor for class "
                              + clazz.getName()
                              + " for configuration property "
                              + name, e);
            }
            catch (InstantiationException e)
            {
                _logger.error("Error while attempting to construct for class "
                              + clazz.getName()
                              + " for configuration property "
                              + name
                              + " using value '"
                              + systemPropertyValue
                              +"'", e);
            }

            _propertiesMap.put(_name, this);
        }

        if(value == null)
        {
            value = defaultValue;
        }

        _value = value;

    }


    final public String getName()
    {
        return _name;
    }

    final public T getValue()
    {
        return _value;
    }



And then:

public class CommonConfigurationProperty<T extends Object> extends 
ConfigurationProperty<T>
{
    protected CommonConfigurationProperty(final Class<T> clazz,
                                          final String name,
                                          final String systemProperty,
                                          final T defaultValue)
    {
        super(clazz, name, systemProperty, defaultValue);
    }

    public static final ConfigurationProperty<Boolean> USE_BIASED_JOB_QUEUE =
            new CommonConfigurationProperty(Boolean.class,
                                            "UseBiasedJobQueue",
                                            
"org.apache.qpid.common.useBiasedJobQueue",
                                            Boolean.FALSE);

}


which would allow you to do

CommonConfigurationPropert.USE_BIASED_JOB_QUEUE,getValue() -> [Bb]oolean

But also ensure that we get the system properties etc in a uniform way.  Also 
it leaves open for sub classes (particularly the server properties) to update 
the values of properties based on some other configuration mechanism (not just 
java system properties)..

> Client properties centralization 
> ---------------------------------
>
>                 Key: QPID-1018
>                 URL: https://issues.apache.org/jira/browse/QPID-1018
>             Project: Qpid
>          Issue Type: Improvement
>          Components: Java Client
>    Affects Versions: M3
>            Reporter: Arnaud Simon
>            Assignee: Arnaud Simon
>             Fix For: M3
>
>
> Currently client props are distributed all over the code. It would be more 
> coherent and easy to document if we centralized them. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to