类 EnvUtil


  • public class EnvUtil
    extends java.lang.Object
    Its own configuration information manipulation tool class.
    作者:
    liaochuntao
    • 字段详细资料

      • STANDALONE_MODE_ALONE

        public static final java.lang.String STANDALONE_MODE_ALONE
        另请参阅:
        常量字段值
      • STANDALONE_MODE_CLUSTER

        public static final java.lang.String STANDALONE_MODE_CLUSTER
        另请参阅:
        常量字段值
      • FUNCTION_MODE_CONFIG

        public static final java.lang.String FUNCTION_MODE_CONFIG
        另请参阅:
        常量字段值
      • FUNCTION_MODE_NAMING

        public static final java.lang.String FUNCTION_MODE_NAMING
        另请参阅:
        常量字段值
      • NACOS_HOME_KEY

        public static final java.lang.String NACOS_HOME_KEY
        The key of nacos home.
        另请参阅:
        常量字段值
      • localAddress

        private static java.lang.String localAddress
      • port

        private static int port
      • isStandalone

        private static java.lang.Boolean isStandalone
      • functionModeType

        private static java.lang.String functionModeType
      • contextPath

        private static java.lang.String contextPath
      • FILE_PREFIX

        private static final java.lang.String FILE_PREFIX
        另请参阅:
        常量字段值
      • SERVER_PORT_PROPERTY

        private static final java.lang.String SERVER_PORT_PROPERTY
        另请参阅:
        常量字段值
      • DEFAULT_SERVER_PORT

        private static final int DEFAULT_SERVER_PORT
        另请参阅:
        常量字段值
      • DEFAULT_WEB_CONTEXT_PATH

        private static final java.lang.String DEFAULT_WEB_CONTEXT_PATH
        另请参阅:
        常量字段值
      • MEMBER_LIST_PROPERTY

        private static final java.lang.String MEMBER_LIST_PROPERTY
        另请参阅:
        常量字段值
      • NACOS_HOME_PROPERTY

        private static final java.lang.String NACOS_HOME_PROPERTY
        另请参阅:
        常量字段值
      • CUSTOM_CONFIG_LOCATION_PROPERTY

        private static final java.lang.String CUSTOM_CONFIG_LOCATION_PROPERTY
        另请参阅:
        常量字段值
      • DEFAULT_CONFIG_LOCATION

        private static final java.lang.String DEFAULT_CONFIG_LOCATION
        另请参阅:
        常量字段值
      • DEFAULT_RESOURCE_PATH

        private static final java.lang.String DEFAULT_RESOURCE_PATH
        另请参阅:
        常量字段值
      • DEFAULT_ADDITIONAL_PATH

        private static final java.lang.String DEFAULT_ADDITIONAL_PATH
        另请参阅:
        常量字段值
      • DEFAULT_ADDITIONAL_FILE

        private static final java.lang.String DEFAULT_ADDITIONAL_FILE
        另请参阅:
        常量字段值
      • NACOS_HOME_ADDITIONAL_FILEPATH

        private static final java.lang.String NACOS_HOME_ADDITIONAL_FILEPATH
        另请参阅:
        常量字段值
      • NACOS_TEMP_DIR_1

        private static final java.lang.String NACOS_TEMP_DIR_1
        另请参阅:
        常量字段值
      • NACOS_TEMP_DIR_2

        private static final java.lang.String NACOS_TEMP_DIR_2
        另请参阅:
        常量字段值
      • confPath

        private static java.lang.String confPath
      • nacosHomePath

        private static java.lang.String nacosHomePath
      • OPERATING_SYSTEM_MX_BEAN

        private static final com.sun.management.OperatingSystemMXBean OPERATING_SYSTEM_MX_BEAN
      • environment

        private static org.springframework.core.env.ConfigurableEnvironment environment
      • nacosTmpDir

        private static java.lang.String nacosTmpDir
    • 构造器详细资料

      • EnvUtil

        public EnvUtil()
    • 方法详细资料

      • getEnvironment

        public static org.springframework.core.env.ConfigurableEnvironment getEnvironment()
      • setEnvironment

        public static void setEnvironment​(org.springframework.core.env.ConfigurableEnvironment environment)
      • containsProperty

        public static boolean containsProperty​(java.lang.String key)
      • getProperty

        public static java.lang.String getProperty​(java.lang.String key)
      • getProperty

        public static java.lang.String getProperty​(java.lang.String key,
                                                   java.lang.String defaultValue)
      • getProperty

        public static <T> T getProperty​(java.lang.String key,
                                        java.lang.Class<T> targetType)
      • getProperty

        public static <T> T getProperty​(java.lang.String key,
                                        java.lang.Class<T> targetType,
                                        T defaultValue)
      • getRequiredProperty

        public static java.lang.String getRequiredProperty​(java.lang.String key)
                                                    throws java.lang.IllegalStateException
        抛出:
        java.lang.IllegalStateException
      • getRequiredProperty

        public static <T> T getRequiredProperty​(java.lang.String key,
                                                java.lang.Class<T> targetType)
                                         throws java.lang.IllegalStateException
        抛出:
        java.lang.IllegalStateException
      • resolvePlaceholders

        public static java.lang.String resolvePlaceholders​(java.lang.String text)
      • resolveRequiredPlaceholders

        public static java.lang.String resolveRequiredPlaceholders​(java.lang.String text)
                                                            throws java.lang.IllegalArgumentException
        抛出:
        java.lang.IllegalArgumentException
      • getPropertyList

        public static java.util.List<java.lang.String> getPropertyList​(java.lang.String key)
      • getLocalAddress

        public static java.lang.String getLocalAddress()
      • setLocalAddress

        public static void setLocalAddress​(java.lang.String localAddress)
      • getPort

        public static int getPort()
      • setPort

        public static void setPort​(int port)
      • getContextPath

        public static java.lang.String getContextPath()
      • setContextPath

        public static void setContextPath​(java.lang.String contextPath)
      • setIsStandalone

        public static void setIsStandalone​(java.lang.Boolean isStandalone)
      • getStandaloneMode

        public static boolean getStandaloneMode()
        Standalone mode or not.
      • getFunctionMode

        public static java.lang.String getFunctionMode()
        server function mode.
      • getNacosTmpDir

        public static java.lang.String getNacosTmpDir()
      • getNacosHome

        public static java.lang.String getNacosHome()
      • setNacosHomePath

        public static void setNacosHomePath​(java.lang.String nacosHomePath)
      • getIPsBySystemEnv

        public static java.util.List<java.lang.String> getIPsBySystemEnv​(java.lang.String key)
      • getSystemEnv

        public static java.lang.String getSystemEnv​(java.lang.String key)
      • getLoad

        public static float getLoad()
      • getCPU

        public static float getCPU()
      • getMem

        public static float getMem()
      • getConfPath

        public static java.lang.String getConfPath()
      • setConfPath

        public static void setConfPath​(java.lang.String confPath)
      • getClusterConfFilePath

        public static java.lang.String getClusterConfFilePath()
      • readClusterConf

        public static java.util.List<java.lang.String> readClusterConf()
                                                                throws java.io.IOException
        read cluster.conf to ip list.
        返回:
        ip list.
        抛出:
        java.io.IOException - ioexception IOException
      • analyzeClusterConf

        public static java.util.List<java.lang.String> analyzeClusterConf​(java.io.Reader reader)
                                                                   throws java.io.IOException
        read file stream to ip list.
        参数:
        reader - reader
        返回:
        ip list.
        抛出:
        java.io.IOException - IOException
      • writeClusterConf

        public static void writeClusterConf​(java.lang.String content)
                                     throws java.io.IOException
        抛出:
        java.io.IOException
      • getMemberList

        public static java.lang.String getMemberList()
      • loadProperties

        public static java.util.Map<java.lang.String,​?> loadProperties​(org.springframework.core.io.Resource resource)
                                                                      throws java.io.IOException
        load resource to map.
        参数:
        resource - resource
        返回:
        Map<String, Object>
        抛出:
        java.io.IOException - IOException
      • getApplicationConfFileResource

        public static org.springframework.core.io.Resource getApplicationConfFileResource()
      • getCustomFileResource

        private static org.springframework.core.io.Resource getCustomFileResource()
      • getRelativePathResource

        private static org.springframework.core.io.Resource getRelativePathResource​(java.lang.String parentPath,
                                                                                    java.lang.String path)
      • getDefaultResource

        private static org.springframework.core.io.Resource getDefaultResource()
      • getAvailableProcessors

        public static int getAvailableProcessors()
        Get available processor numbers from environment.

        If there are setting of nacos.core.sys.basic.processors in config/JVM/system, use it. If no setting, use the one time ThreadUtils.getSuitableThreadCount().

        返回:
        available processor numbers from environment, will not lower than 1.
      • getAvailableProcessors

        public static int getAvailableProcessors​(int multiple)
        Get a multiple time of available processor numbers from environment.
        参数:
        multiple - multiple of available processor numbers
        返回:
        available processor numbers from environment, will not lower than 1.
      • getAvailableProcessors

        public static int getAvailableProcessors​(double scale)
        Get a scale of available processor numbers from environment.
        参数:
        scale - scale from 0 to 1.
        返回:
        available processor numbers from environment, will not lower than 1.