Skip navigation links
javolution.lang

Class Configurable<T>

    • Constructor Detail

      • Configurable

        public Configurable(T defaultValue)
        Creates a new configurable having the specified default value.
        Parameters:
        defaultValue - the default value.
        Throws:
        IllegalArgumentException - if defaultValue is null.
    • Method Detail

      • get

        public T get()
        Returns the current value for this configurable.
        Returns:
        the current value (always different from null).
      • getDefault

        public T getDefault()
        Returns the default value for this configurable.
        Returns:
        the default value (always different from null).
      • getContainer

        public Class getContainer()
        Returns the container class of this configurable (the class where this configurable is defined as a public static field.
        Returns:
        the container class or null if unknown (e.g. J2ME).
      • getName

        public String getName()
        Returns the field name of this configurable (for example "javolution.context.ConcurrentContext#MAXIMUM_CONCURRENCY") for ConcurrentContext.MAXIMUM_CONCURRENCY.
        Returns:
        this configurable name or null if the name of this configurable is unknown (e.g. J2ME).
      • notifyChange

        protected void notifyChange(T oldValue,
                                    T newValue)
                             throws UnsupportedOperationException
        Notifies this configurable that its runtime value is going to be changed. The default implementation does nothing.
        Parameters:
        oldValue - the previous value.
        newValue - the new value.
        Throws:
        UnsupportedOperationException - if dynamic reconfiguration of this configurable is not allowed (regardless of the security context).
      • toString

        public String toString()
        Returns the string representation of the value of this configurable.
        Overrides:
        toString in class Object
        Returns:
        String.valueOf(this.get())
      • getInstance

        public static Configurable getInstance(String name)
        Returns the configurable instance having the specified name. For example:[code] Configurable cfg = Configurable.getInstance("javolution.context.ConcurrentContext#MAXIMUM_CONCURRENCY") [/code] returns ConcurrentContext.MAXIMUM_CONCURRENCY.

        Note: OSGI based framework should ensure that class loaders of configurable instances are known to the Reflection utility class.

        Parameters:
        name - the name of the configurable to retrieve.
        Returns:
        the corresponding configurable or null if it cannot be found.
      • configure

        public static <T> void configure(Configurable<T> cfg,
                                         T newValue)
                                  throws SecurityException
        Sets the run-time value of the specified configurable. If the configurable value is different from the previous one, then notifyChange(T, T) is called. This method raises a SecurityException if the specified configurable cannot be reconfigured.
        Parameters:
        cfg - the configurable being configured.
        newValue - the new run-time value.
        Throws:
        IllegalArgumentException - if value is null.
        SecurityException - if the specified configurable cannot be modified.
      • read

        public static void read(Properties properties)
        Convenience method to read the specified properties and reconfigure accordingly. For example:[code] // Load configurables from system properties. Configurable.read(System.getProperties());[/code] Configurables are identified by their field names. The textual representation of their value is defined by TextFormat.getInstance(Class) text format}. For example:[code] javolution.util.FastComparator#REHASH_SYSTEM_HASHCODE = true javolution.context.ConcurrentContext#MAXIMUM_CONCURRENCY = 0 javolution.xml.stream.XMLInputFactory#CLASS = com.foo.bar.XMLInputFactoryImpl [/code] Conversion of String values to actual object is performed using TextFormat.getInstance(Class).

        Note: OSGI based framework should ensure that class loaders of configurable instances are known to the Reflection utility class.

        Parameters:
        properties - the properties.
      • read

        public static void read(InputStream inputStream)
        Convenience method to read configurable values from the specified XML stream. This method uses Javolution XML facility to perform the deserialization. Here is an example of XML configuration file.[code] [/code] It can be read directly with the following code:[code] FileInputStream xml = new FileInputStream("D:/configuration.xml"); Configurable.read(xml);[/code]

        Note: OSGI based framework should ensure that class loaders of configurable instances are known to the Reflection utility.

        Parameters:
        inputStream - the input stream holding the xml configuration.

Copyright © 2005–2017 Javolution. All rights reserved.