Package org.apache.solr.common.util
Class EnvUtils
- java.lang.Object
-
- org.apache.solr.common.util.EnvUtils
-
public class EnvUtils extends Object
This class is a unified provider of environment variables and system properties. It exposes a mutable copy of the environment variables. It also converts 'SOLR_FOO' variables to system properties 'solr.foo' and provide various convenience accessors for them.
-
-
Constructor Summary
Constructors Constructor Description EnvUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static String
envNameToSyspropName(String envName)
static String
getEnv(String key)
Get a single environment variable as stringstatic String
getEnv(String key, String defaultValue)
Get a single environment variable as string, or defaultstatic boolean
getEnvAsBool(String key)
Get an env var as booleanstatic boolean
getEnvAsBool(String key, boolean defaultValue)
Get an env var as boolean, or default valuestatic List<String>
getEnvAsList(String key)
Get comma separated strings from env as Liststatic List<String>
getEnvAsList(String key, List<String> defaultValue)
Get comma separated strings from env as Liststatic long
getEnvAsLong(String key)
Get an environment variable as longstatic long
getEnvAsLong(String key, long defaultValue)
Get an environment variable as long, or default valuestatic SortedMap<String,String>
getEnvs()
Get Solr's mutable copy of all environment variables.static SortedMap<String,String>
getProperties()
Get all Solr system properties as a sorted mapstatic String
getProperty(String key)
Get a property as stringstatic String
getProperty(String key, String defaultValue)
Get a property as string with a fallback value.static Boolean
getPropertyAsBool(String key)
Get property as booleanstatic Boolean
getPropertyAsBool(String key, Boolean defaultValue)
Get property as boolean, or default valuestatic List<String>
getPropertyAsList(String key)
Get comma separated strings from sysprop as Liststatic List<String>
getPropertyAsList(String key, List<String> defaultValue)
Get comma separated strings from sysprop as List, or default valuestatic Long
getPropertyAsLong(String key)
Get property as integerstatic Long
getPropertyAsLong(String key, Long defaultValue)
Get property as long, or default valuestatic void
setEnv(String key, String value)
Set an environment variablestatic void
setEnvs(Map<String,String> env)
Set all environment variablesstatic void
setProperty(String key, String value)
Set a system property.
-
-
-
Method Detail
-
getEnvs
public static SortedMap<String,String> getEnvs()
Get Solr's mutable copy of all environment variables.- Returns:
- sorted map of environment variables
-
getEnv
public static String getEnv(String key, String defaultValue)
Get a single environment variable as string, or default
-
getEnvAsLong
public static long getEnvAsLong(String key)
Get an environment variable as long
-
getEnvAsLong
public static long getEnvAsLong(String key, long defaultValue)
Get an environment variable as long, or default value
-
getEnvAsBool
public static boolean getEnvAsBool(String key)
Get an env var as boolean
-
getEnvAsBool
public static boolean getEnvAsBool(String key, boolean defaultValue)
Get an env var as boolean, or default value
-
getEnvAsList
public static List<String> getEnvAsList(String key)
Get comma separated strings from env as List
-
getEnvAsList
public static List<String> getEnvAsList(String key, List<String> defaultValue)
Get comma separated strings from env as List
-
getProperties
public static SortedMap<String,String> getProperties()
Get all Solr system properties as a sorted map
-
getProperty
public static String getProperty(String key, String defaultValue)
Get a property as string with a fallback value. All other getProperty* methods use this.- Parameters:
key
- property key, which treats 'camelCase' the same as 'camel.case'defaultValue
- fallback value if property is not found
-
getPropertyAsLong
public static Long getPropertyAsLong(String key, Long defaultValue)
Get property as long, or default value
-
getPropertyAsBool
public static Boolean getPropertyAsBool(String key, Boolean defaultValue)
Get property as boolean, or default value
-
getPropertyAsList
public static List<String> getPropertyAsList(String key)
Get comma separated strings from sysprop as List- Returns:
- list of strings, or null if not found
-
getPropertyAsList
public static List<String> getPropertyAsList(String key, List<String> defaultValue)
Get comma separated strings from sysprop as List, or default value- Returns:
- list of strings, or provided default if not found
-
setProperty
public static void setProperty(String key, String value)
Set a system property. Shim toSystem.setProperty(String, String)
-
-