Javolution 6.0.0 java
|
Classes | |
interface | Listener |
Public Member Functions | |
Configurable () | |
T | get () |
String | getName () |
Permission< Configurable< T > > | getReconfigurePermission () |
T | reconfigure (T newValue) |
Static Public Attributes | |
static Permission< Configurable<?> > | RECONFIGURE_PERMISSION |
Protected Member Functions | |
abstract T | getDefault () |
T | initialized (T value) |
T | parse (String str) |
T | reconfigured (T oldValue, T newValue) |
Private Attributes | |
String | name |
final Permission< Configurable< T > > | reconfigurePermission |
volatile T | value |
An element which is configurable without presupposing how the configuration is done.
Does your class need to know or has to assume that the configuration is coming from system properties ??
The response is obviously NO !
Let's compare the following examples: [code] class Document { private static final Font FONT = Font.decode(System.getProperty("pkg.Document#FONT") != null ? System.getProperty("FONT") : "Arial-BOLD-18"); }[/code]
With the following: [code] class Document { public static final Configurable<Font> FONT = new Configurable<Font>() { @Override protected Font getDefault() { new Font("Arial", Font.BOLD, 18); } }; }[/code]
Not only the second example is cleaner, but the actual configuration data can come from anywhere, from system properties (if property defined), OSGi Configuration Admin service, another bundle, etc. Low level code does not need to know.
Configurables may perform any logic upon initialization or update. Users are notified of configuration events through the OSGi Configurable.Listener service. [code] class Index { // Holds the number of unique preallocated instances (default
).
public static final Configurable<Integer> UNIQUE = new Configurable<Integer>() { @Override protected Integer getDefault() { return 1024; } @Override protected Integer initialized(Integer value) { return MathLib.min(value, 65536); // Hard-limiting } @Override protected Integer reconfigured(Integer oldCount, Integer newCount) { throw new UnsupportedOperationException("Unicity reconfiguration not supported."); }
} }[/code]
Definition at line 78 of file Configurable.java.
javolution.lang.Configurable< T >.Configurable | ( | ) |
Creates a new configurable. If a system property exist for this configurable's name, the the parsed value of the property supersedes the default value of this configurable. For example, running the JVM with the option
disables concurrency support.
Definition at line 142 of file Configurable.java.
T javolution.lang.Configurable< T >.get | ( | ) |
Returns this configurable value.
Reimplemented in javolution.context.LocalContext.Parameter< T >.
Definition at line 170 of file Configurable.java.
Referenced by javolution.context.internal.ConcurrentContextImpl.ConcurrentContextImpl(), javolution.lang.Initializer.initializeLoadedClasses(), javolution.test.Perfometer< T >.measure(), javolution.test.Perfometer< T >.print(), and javolution.test.Perfometer< T >.printDetails().
|
abstractprotected |
Returns this configurable default value (always different from
).
Referenced by javolution.lang.Configurable< javolution.context.LogContext.Level >.Configurable(), and javolution.lang.Configurable< javolution.context.LogContext.Level >.parse().
String javolution.lang.Configurable< T >.getName | ( | ) |
Returns this configurable name. By convention, the name of the configurable is the name of the static field holding the configurable (e.g. "javolution.context.ConcurrentContext#CONCURRENCY"). This method should be overridden if the enclosing class needs to be impervious to obfuscation or if the enclosing class defines multiple configurable fields.
UnsupportedOperationException | if the enclosing class has multiple configurable static fields. |
Definition at line 185 of file Configurable.java.
Referenced by javolution.lang.Configurable< javolution.context.LogContext.Level >.Configurable(), javolution.osgi.internal.ConfigurableListenerImpl.configurableInitialized(), and javolution.osgi.internal.ConfigurableListenerImpl.configurableReconfigured().
Permission<Configurable<T> > javolution.lang.Configurable< T >.getReconfigurePermission | ( | ) |
Returns the permission to configure this instance.
Definition at line 207 of file Configurable.java.
|
protected |
This methods is called when the configurable is initialized. Developers may override this method to perform any initialization logic (e.g. input validation).
value | the requested value for this configurable. |
Definition at line 252 of file Configurable.java.
Referenced by javolution.lang.Configurable< javolution.context.LogContext.Level >.Configurable().
|
protected |
Parses the specified text to return the corresponding value. This method is used to initialize this configurable from system properties. The default implementation uses the TextContext to retrieve the text format (based on DefaultTextFormat class annotation).
Definition at line 264 of file Configurable.java.
Referenced by javolution.lang.Configurable< javolution.context.LogContext.Level >.Configurable().
T javolution.lang.Configurable< T >.reconfigure | ( | T | newValue | ) |
Reconfigures this instance with the specified value if authorized by the SecurityContext. This method returns the actual new value which may be different from the requested new value (see reconfigured(Object, Object)).
newValue | the requested new value. |
SecurityException | if the permission to reconfigure this configurable is not granted. |
UnsupportedOperationException | if this configurable does not support dynamic reconfiguration. |
Definition at line 224 of file Configurable.java.
|
protected |
This methods is called when the configurable is reconfigured. Developers may override this method to perform any reconfiguration logic (e.g. hard limiting values).
oldValue | the old value. |
newValue | the requested new value. |
UnsupportedOperationException | if this configurable does not support dynamic reconfiguration. |
Definition at line 280 of file Configurable.java.
Referenced by javolution.lang.Configurable< javolution.context.LogContext.Level >.reconfigure().
|
private |
Holds the configurable name.
Definition at line 121 of file Configurable.java.
Referenced by javolution.lang.Configurable< javolution.context.LogContext.Level >.Configurable(), and javolution.lang.Configurable< javolution.context.LogContext.Level >.getName().
|
static |
Holds the general permission to reconfigure configurable instances (action "reconfigure"
). Whether or not that permission is granted depends on the current SecurityContext. It is possible that the general permission to reconfigure a configurable is granted but revoked for a specific instance. Also, the general permission to reconfigure a configurable may be revoked but granted only for a specific instance.
Definition at line 115 of file Configurable.java.
|
private |
Holds the reconfigure permission.
Definition at line 126 of file Configurable.java.
Referenced by javolution.lang.Configurable< javolution.context.LogContext.Level >.Configurable(), javolution.lang.Configurable< javolution.context.LogContext.Level >.getReconfigurePermission(), and javolution.lang.Configurable< javolution.context.LogContext.Level >.reconfigure().
|
private |
Holds the configurable value.
Definition at line 131 of file Configurable.java.
Referenced by javolution.lang.Configurable< javolution.context.LogContext.Level >.get(), javolution.lang.Configurable< javolution.context.LogContext.Level >.initialized(), and javolution.lang.Configurable< javolution.context.LogContext.Level >.reconfigure().