`
gaojingsong
  • 浏览: 1155148 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

PropertyUtils 文件解读

阅读更多
单例模式 ,静态代码块
/**
 * property utils
 * single instance
 */
public class PropertyUtils {

    /**
     * logger
     */
private static final Logger logger = LoggerFactory.getLogger(PropertyUtils.class);

    private static final Properties properties = new Properties();

    private PropertyUtils() {
        throw new UnsupportedOperationException("Construct PropertyUtils");
    }

    static {
        String[] propertyFiles = new String[]{"/common.properties"};
        for (String fileName : propertyFiles) {
            InputStream fis = null;
            try {
                fis = PropertyUtils.class.getResourceAsStream(fileName);
                properties.load(fis);

            } catch (IOException e) {
                logger.error(e.getMessage(), e);
                if (fis != null) {
                    IOUtils.closeQuietly(fis);
                }
                System.exit(1);
            } finally {
                IOUtils.closeQuietly(fis);
            }
        }
    }

    /**
     *
     * @return  judge whether resource upload startup
     */
public static Boolean getResUploadStartupState(){
        // HDFS 或者S3 资源是否启用
String resUploadStartupType = PropertyUtils.getUpperCaseString("resource.storage.type");
        ResUploadType resUploadType = ResUploadType.valueOf(resUploadStartupType);
        return resUploadType == ResUploadType.HDFS || resUploadType == ResUploadType.S3;
    }
   // 获取指定key或者获取不到赋予默认值省略
}


相关存储枚举如下:

/**
 * data base types
 */
public enum ResUploadType {
  /**
   * 0 hdfs
   * 1 s3
   * 2 none
   */
HDFS,S3,NONE
}
代码来源于dolphinscheduler 的1.36版本

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics