Package com.helixframework.env
Class HelixEnvironment
java.lang.Object
com.helixframework.env.HelixEnvironment
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
@Component
public class HelixEnvironment
extends Object
implements org.springframework.context.ApplicationContextAware
Holds context about the currently executing helix environment.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionHelixEnvironment(org.springframework.core.env.Environment environment) Creates an instance of theHelixEnvironmentbased on the supplied SpringEnvironment. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllMetadata(Map<String, Object> values) Adds a collection of metadata entries.voidaddMetadata(String key, Object value) Adds a new metadata entry.booleancontainsProperty(String key) Return whether the given property key is available for resolution, i.e.Gets the Helix account.getAppId()Gets the Helix application identifier.org.springframework.context.ApplicationContextGets the spring application context.Gets the version of the application if available.getDelimitedProperty(String key, String delimiter) Gets the value of a delimited property.getDelimitedProperty(String key, String delimiter, List<String> defaults) Gets the value of a delimited property.Gets the value of the environment variable.Gets the value of the environment variable.Gets the Helix environment name.Gets the Helix version.Gets the instance identifier.Gets metadata.Gets the Helix organization name.Gets all system properties.getProperties(Class<?> baseClass) Gets all properties whose keys begin with the package name of the supplied class.getProperties(String baseName) Gets all system properties whose keys begin with the supplied string (basename).getProperties(Pattern pattern) Gets all properties whose keys match the regular expression.getProperty(String key) Gets the string value of the system property.<T> TgetProperty(String key, Class<T> targetType) Gets the value of the system property.<T> TgetProperty(String key, Class<T> targetType, T defaultValue) Gets the value of the system property.getProperty(String key, String defaultValue) Gets the string value of the system property.Gets the current region.Gets the string value of the system property; throwing aRuntimeExceptionif the property is not defined.<T> TgetRequiredProperty(String key, Class<T> targetType) Gets the value of the system property; throwing aRuntimeExceptionif the property is not defined.getTeam()Gets the Helix team name.booleanisDebug()Gets the current debug state of the application.booleanisLocal()Checks to see if the application is running in the "local" environment.resolveValue(String propertyKey, String varName) Gets the string value of a property or environment variable with the supplied names.resolveValue(String propertyKey, String varName, String defaultValue) Gets the string value of a property or environment variable with the supplied names.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)
-
Field Details
-
PROP_DEBUG
- See Also:
-
ENV_ACCOUNT
- See Also:
-
PROP_ACCOUNT
- See Also:
-
ENV_ENVIRONMENT
- See Also:
-
PROP_ENVIRONMENT
- See Also:
-
ENV_ORG
- See Also:
-
PROP_ORG
- See Also:
-
ENV_REGION
- See Also:
-
PROP_REGION
- See Also:
-
ENV_TEAM
- See Also:
-
PROP_TEAM
- See Also:
-
ENV_APPID
- See Also:
-
PROP_APPID
- See Also:
-
ENV_INSTANCE_ID
- See Also:
-
PROP_INSTANCE_ID
- See Also:
-
PROP_HELIX_VERSION
- See Also:
-
-
Constructor Details
-
HelixEnvironment
@Autowired public HelixEnvironment(org.springframework.core.env.Environment environment) Creates an instance of theHelixEnvironmentbased on the supplied SpringEnvironment.- Parameters:
environment- spring environment
-
-
Method Details
-
getEnv
Gets the value of the environment variable.- Parameters:
name- environment variable name- Returns:
- the string value of the variable, or null if the variable is not defined in the system environment
-
getEnv
Gets the value of the environment variable.- Parameters:
name- environment variable namedefaultValue- string value to return if environment variable does not exist- Returns:
- the string value of the variable, or the default value if the variable is not defined in the system environment
-
containsProperty
Return whether the given property key is available for resolution, i.e. if the value for the given key is not null.- Parameters:
key- property key- Returns:
trueif the property key exists; otherwisefalse
-
getProperty
Gets the string value of the system property.- Parameters:
key- property key- Returns:
- the string value of the property, or null if the property does not exist
-
getProperty
Gets the string value of the system property.- Parameters:
key- property keydefaultValue- string value to return if the property does not exist- Returns:
- the string value of the property, or the default value if the property is not defined
-
getProperty
Gets the value of the system property.- Type Parameters:
T- property value type- Parameters:
key- property keytargetType- the expected type of the property value- Returns:
- the value of the property, or null if the property does not exist
-
getProperty
Gets the value of the system property.- Type Parameters:
T- property value type- Parameters:
key- property keytargetType- the expected type of the property valuedefaultValue- value to return if the property does not exist- Returns:
- the value of the property
-
getDelimitedProperty
Gets the value of a delimited property.For example, a property with value `foo,bar,baz` would return a list containing [`foo`, `bar`, `baz`].
- Parameters:
key- property keydelimiter- property delimiter- Returns:
- the value of the property if it exists
-
getDelimitedProperty
Gets the value of a delimited property. If property does not exist, returns the provided defaults.- Parameters:
key- property keydelimiter- property delimiterdefaults- default list of values to return if property does not exist- Returns:
- the value of the property if it exists, or the default list of values
-
getRequiredProperty
Gets the string value of the system property; throwing aRuntimeExceptionif the property is not defined.- Parameters:
key- property key- Returns:
- the string value of the property
- Throws:
RuntimeException- if the specified property is not defined
-
getRequiredProperty
Gets the value of the system property; throwing aRuntimeExceptionif the property is not defined.- Type Parameters:
T- property value type- Parameters:
key- property keytargetType- the expected type of the property value- Returns:
- the value of the property
-
getProperties
Gets all system properties.- Returns:
- system properties
-
getProperties
Gets all system properties whose keys begin with the supplied string (basename).For example getProperties("app.database") would return all properties whose keys begin with the "app.database" string.
- Parameters:
baseName- base property key name- Returns:
- all system properties whose keys begin with the basename
-
getProperties
Gets all properties whose keys begin with the package name of the supplied class.- Parameters:
baseClass- base class from which to get the package name to use for basename- Returns:
- all system properties whose keys begin with the package name
-
getProperties
Gets all properties whose keys match the regular expression.- Parameters:
pattern- regex- Returns:
- all system properties whose keys match the regular expression
-
resolveValue
Gets the string value of a property or environment variable with the supplied names.System properties are resolved first, followed by environment variables.
- Parameters:
propertyKey- property keyvarName- environment variable- Returns:
- the value of the property or environment variable, or null if neither exist
-
resolveValue
Gets the string value of a property or environment variable with the supplied names.- Parameters:
propertyKey- property keyvarName- environment variabledefaultValue- string value to return if both system property and environment variable do not exist- Returns:
- the value of the property or environment variable, or the default value if neither the system property nor the environment variable exist
-
isDebug
public boolean isDebug()Gets the current debug state of the application.- Returns:
trueif in debug mode; otherwisefalse
-
isLocal
public boolean isLocal()Checks to see if the application is running in the "local" environment.- Returns:
trueif application is running in local environment; otherwisefalse
-
getEnvironmentName
Gets the Helix environment name.- Returns:
- environment
-
getAccount
Gets the Helix account.- Returns:
- account
-
getOrganization
Gets the Helix organization name.- Returns:
- organization
-
getRegion
Gets the current region.- Returns:
- region
-
getTeam
Gets the Helix team name.- Returns:
- team
-
getAppId
Gets the Helix application identifier.- Returns:
- application identifier
-
getInstanceId
Gets the instance identifier.- Returns:
- instance identifier
-
getHelixVersion
Gets the Helix version.- Returns:
- helix version
-
getAppVersion
Gets the version of the application if available.- Returns:
- application version
-
getMetadata
Gets metadata.- Returns:
- metadata in environment variables and system properties
-
addMetadata
Adds a new metadata entry.- Parameters:
key- entry keyvalue- entry value
-
addAllMetadata
Adds a collection of metadata entries.- Parameters:
values- metadata to add to the metadata collection
-
getApplicationContext
public org.springframework.context.ApplicationContext getApplicationContext()Gets the spring application context.- Returns:
- the spring application context
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-