com.neeve.util
Class UtlEnv

java.lang.Object
  extended by com.neeve.util.UtlEnv

public final class UtlEnv
extends Object

Utility class that loads and maintains runtime environment variables.

The environment maintained here is used by various platform components in 2 fashions. First and foremost it provides a way for overall global configuration values to be specified in the environment or system properties to augment configuration at runtime. Secondly, in the absence of higher level configuration mechanism being initialized, it provides a way for low level platform components to source configuration before higher level configuration mechanism have been initialized that can reinitialize or augment the environment dynamically for other configuration sources.

When higher level configuration mechanisms are used the initial environment loaded by this class can be thought of as bootstrap environment until initialized. In support of this this class provides an initialize(Properties) method than can be used by applications to indicate when the environment can be considered to have been full initialized,

Environment Initialization

The initial environment loaded by this class is constructed by:
  1. Adds all system properties that exist when this class is loaded.
  2. Then adds all properties from the properties file specified by UtlConstants.APP_PROPFILE_PROPNAME if exists and can be loaded. UtlConstants.APP_PROPFILE_DEFAULT itself is resolved by first looking in System.getenv(String) or in System.getProperty(String) if not defined in the environment.
  3. On top of the System Properties and App Properties, value from System.getenv() are applied by taking them and replacing any instance of '_' with a '.'

This class MAY be used by end users, however its usage is not suppport unless one is directed to do so by Neeve Support.


Constructor Summary
UtlEnv()
           
 
Method Summary
static Properties getEnvProps()
          Returns the environment properties.
static Properties getEnvPropsNoWarn()
          Returns the normalized environment properties.
static String getLocalHostAddress()
          Get the local host address This method returns the local host address using the following:
- InetAddress.getLocalHost().getHostAddress.
static String getLocalHostAddressForDisplay(String defaultValue)
          Get the local host address for display purposes.
static InetAddress getLocalHostInetAddress()
          Get the InetAddress representing the local host IP + hostname.
static String getLocalHostName()
          Get the local host name This method returns the local host name using the following:
- InetAddress.getLocalHost().getHostName.
static String getLocalHostNameForDisplay(String defaultValue)
          Get the local host name for display purposes.
static String getPid()
          Get the process pid This method returns the process id of the current process
static String getValue(String name)
          Get the value of a property from the environment props.
static boolean getValue(String name, boolean defValue)
          Convenience method to return an environment property value as a boolean value
static double getValue(String name, double defValue)
          Convenience method to return a property from the environment as a numeric value.
static int getValue(String name, int defValue)
          Convenience method to return a property from the environment as an int value.
static short getValue(String name, short defValue)
          Convenience method to return a property from the environment as an short value.
static String getValue(String name, String defValue)
          Convenience method to return a property value as a String value from the environment
static void initialize(Properties env)
          Initializes the environment.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UtlEnv

public UtlEnv()
Method Detail

initialize

public static void initialize(Properties env)
Initializes the environment. This replaces any bootstrap environment loaded initially with the environment provided.

Parameters:
env - The environment to initialize.
Threading:
This method is safe for concurrent access by multiple threads.

getEnvPropsNoWarn

public static Properties getEnvPropsNoWarn()
Returns the normalized environment properties.

Returns:
The normalized environment properties.
Threading:
This method is safe for concurrent access by multiple threads.

getEnvProps

public static Properties getEnvProps()
Returns the environment properties.

The caller should not modify the returned set of properties. All mutative operations on the environment should be done via calls to this class instead.

Returns:
The normalized environment properties.
Threading:
This method is safe for concurrent access by multiple threads.

getValue

public static String getValue(String name)
Get the value of a property from the environment props.

Parameters:
name - The property name
Returns:
Returns the property value
Threading:
This method is safe for concurrent access by multiple threads.

getValue

public static final boolean getValue(String name,
                                     boolean defValue)
Convenience method to return an environment property value as a boolean value

Parameters:
name - The property name
defValue - The default property value to return in case the property could not be found in the property table.
Returns:
Returns the property value as a boolean value.

This method is a convenience method that returns a property value as a boolean value. It uses getValue(java.lang.String) to retrieve the property value. The default value is returned in case the no property with the provided name exists in the property table.

Threading:
This method is safe for concurrent access by multiple threads.

getValue

public static final double getValue(String name,
                                    double defValue)
Convenience method to return a property from the environment as a numeric value.

Parameters:
name - The property name
defValue - The default property value to return in case the property could not be found in the property table.
Returns:
Returns the property value as a numeric value.

This method is a convenience method that returns a property value as a numeric value. It uses getValue(java.lang.String) to retrieve the property value. The default value is returned in case the no property with the provided name exists in the property table.

Threading:
This method is safe for concurrent access by multiple threads.

getValue

public static final int getValue(String name,
                                 int defValue)
Convenience method to return a property from the environment as an int value.

Parameters:
name - The property name
defValue - The default property value to return in case the property could not be found in the property table.
Returns:
Returns the property value as a numeric value.

This method is a convenience method that returns a property value as an int value. It uses getValue(String) to retrieve the property value. The default value is returned in case the no property with the provided name exists in the property table.

Threading:
This method is safe for concurrent access by multiple threads.

getValue

public static final short getValue(String name,
                                   short defValue)
Convenience method to return a property from the environment as an short value.

Parameters:
name - The property name
defValue - The default property value to return in case the property could not be found in the property table.
Returns:
Returns the property value as a numeric value.

This method is a convenience method that returns a property value as a numeric value. It uses getValue(java.lang.String) to retrieve the property value. The default value is returned in case the no property with the provided name exists in the property table.

Threading:
This method is safe for concurrent access by multiple threads.

getValue

public static String getValue(String name,
                              String defValue)
Convenience method to return a property value as a String value from the environment

Parameters:
name - The property name
defValue - The default property value to return in case the property could not be found in the property table.
Returns:
Returns the property value as a String value.

This method is a convenience method that returns a property value as a string value. It uses getValue(java.lang.String) to retrieve the property value. The default value is returned in case the no property with the provided name exists in the property table.

Threading:
This method is safe for concurrent access by multiple threads.

getPid

public static final String getPid()
Get the process pid

This method returns the process id of the current process

Threading:
This method is safe for concurrent access by multiple threads.

getLocalHostInetAddress

public static final InetAddress getLocalHostInetAddress()
                                                 throws UnknownHostException
Get the InetAddress representing the local host IP + hostname.

Throws:
UnknownHostException - Thrown if a local InetAddress could not be determined.
Threading:
This method is safe for concurrent access by multiple threads.

getLocalHostNameForDisplay

public static final String getLocalHostNameForDisplay(String defaultValue)
Get the local host name for display purposes.

Parameters:
defaultValue - The value to return if a local host name could not be determined.

This method returns the name of the local host machine on which the X process is running. The defaultValue is returned if the local host name could not be determined for whatever reason

Threading:
This method is safe for concurrent access by multiple threads.

getLocalHostName

public static final String getLocalHostName()
                                     throws UnknownHostException
Get the local host name

This method returns the local host name using the following:
- InetAddress.getLocalHost().getHostName.
If a host name could not be determined, then this method throws an UnknownHostException exception.

Throws:
UnknownHostException - Thrown if the local host name could not be determined via InetAddress.getLocalHost().getHostName
Threading:
This method is safe for concurrent access by multiple threads.

getLocalHostAddressForDisplay

public static final String getLocalHostAddressForDisplay(String defaultValue)
Get the local host address for display purposes.

Parameters:
defaultValue - The value to return if a local host address could not be determined.

This method returns the address of the local host machine on which the X process is running as returned by InetAddress.getLocalHost().getHostAddress. The defaultValue is returned if the local host address could not be determined for whatever reason

Threading:
This method is safe for concurrent access by multiple threads.

getLocalHostAddress

public static final String getLocalHostAddress()
                                        throws UnknownHostException
Get the local host address

This method returns the local host address using the following:
- InetAddress.getLocalHost().getHostAddress.
If a host address could not be determined, then this method throws an UnknownHostException exception.

Throws:
UnknownHostException - Thrown if the local host address could not be determined via InetAddress.getLocalHost().getHostAddress
Threading:
This method is safe for concurrent access by multiple threads.


Copyright © 2016 Neeve Research, LLC. All Rights Reserved.