cn.dceast.platform.task.config.TaskConfig Maven / Gradle / Ivy
The newest version!
package cn.dceast.platform.task.config;
import cn.dceast.platform.task.TaskInitException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
public class TaskConfig {
private static final String fileName = "application.properties";
private static Properties properties = null;
public static String outputJobInfoExecutor = null;
public static String inputJobInfoExecutor = null;
/**
* mongodb数据库配置,非必要
*/
public static String mongodb_task_host = null;
public static String mongodb_task_dbName = null;
public static String mongodb_task_userName = null;
public static String mongodb_task_password = null;
public static int mongodb_task_minConnectionsPerHost = 0;
public static int mongodb_task_connectionsPerHost = 10;
public static int mongodb_task_threadsAllowedToBlockForConnectionMultiplier = 5;
public static int mongodb_task_maxWaitTime = 120000;
public static int mongodb_task_maxConnectionIdleTime = 600000;
public static int mongodb_task_connectTimeout = 10000;
public static String appName = null;
// public static String scanIniAnnotationPackage = null;
public static void init() {
InputStream inputStream = null;
try {
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); // properties.load(Prop.class.getResourceAsStream(fileName));
if (inputStream == null)
throw new IllegalArgumentException("Properties file not found in classpath: " + fileName);
properties = new Properties();
properties.load(new InputStreamReader(inputStream, Constants.SYS_ENCODING));
outputJobInfoExecutor = properties.getProperty("output.jobinfo.executor");
inputJobInfoExecutor = properties.getProperty("input.jobinfo.executor");
try {
// scanIniAnnotationPackage = properties.getProperty("scan.init.annotation.package");
mongodb_task_host = properties.getProperty("mongodb.task.host");
mongodb_task_dbName = properties.getProperty("mongodb.task.dbName");
mongodb_task_userName = properties.getProperty("mongodb.task.userName");
mongodb_task_password = properties.getProperty("mongodb.task.password");
mongodb_task_minConnectionsPerHost = Integer.parseInt(properties.getProperty("mongodb.task.minConnectionsPerHost"));
mongodb_task_connectionsPerHost = Integer.parseInt(properties.getProperty("mongodb.task.connectionsPerHost"));
mongodb_task_threadsAllowedToBlockForConnectionMultiplier = Integer.parseInt(properties.getProperty("mongodb.task.threadsAllowedToBlockForConnectionMultiplier"));
mongodb_task_maxWaitTime = Integer.parseInt(properties.getProperty("mongodb.task.maxWaitTime"));
mongodb_task_maxConnectionIdleTime = Integer.parseInt(properties.getProperty("mongodb.task.maxConnectionIdleTime"));
mongodb_task_connectTimeout = Integer.parseInt(properties.getProperty("mongodb.task.connectTimeout"));
} catch (Exception e) {
System.out.println(e.getMessage());
}
appName = System.getenv("APPNAME");
if (appName == null || appName == "") {
//取配置文件中appName
appName = properties.getProperty("app.name");
if (appName == null || "".equals(appName)) {
throw new TaskInitException("appName cannot be null!");
}
}
} catch (IOException e) {
throw new TaskInitException("Error loading properties file.", e);
} finally {
if (inputStream != null) try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}