📄 setting.java.svn-base
字号:
/*
* Copyright(C) 2008, NTT AT Co., Ltd.
* Project: AWGView
*
* Notes:
* N/A
*
* Record of change:
* Date Version Name Content
* 2008/12/15 1.0 TriNT First create
*/
package jp.co.ntt.awgview.server.common;
import org.snmp4j.mp.SnmpConstants;
import jp.co.ntt.awgview.server.AppMainServer;
import jp.co.ntt.awgview.server.constant.Constants;
/**
* Class name : Setting <BR>
* Package : jp.co.ntt_at.awgview.server.common <BR>
* Description: Setting class is memory setting parameter for AWG-View<BR>
*
* @author : AI&T
* @version : 1.0
*/
public class Setting {
private static final String JBOSS_HOST_PORT = "awgview.server.jms.JbossHostPort";
private static String serverAddress;
private static final String KEY_SNMP_RETRY = "awgview.server.snmp.SnmpRetry";
private static int DEFAULT_SNMP_RETRY = 3;
private static int MIN_SNMP_RETRY = 1;
private static int MAX_SNMP_RETRY = 10;
private static int snmpRetry;
private static final String KEY_SNMP_TIMEOUT = "awgview.server.snmp.SnmpTimeOut";
private static int DEFAULT_SNMP_TIMEOUT = 3000;// Milliseconds
private static int MIN_SNMP_TIMEOUT = 1000;// Milliseconds
private static int MAX_SNMP_TIMEOUT = 60000; // Milliseconds
private static int snmpTimeOut;
// The SNMP community string for connection use.
public static final String KEY_SNMP_COMMUNITY = "awgview.server.snmp.SnmpCommunity";
private static final String DEFAULT_SNMP_COMMUNITY = "public";
private static String snmpCommunity;
private static final String DB_HOST = "awgview.server.Database.Host";
private static String dbHost;
private static final String DB_PORT = "awgview.server.Database.Port";
private static int dbPort;
private static final String DB_NAME = "awgview.server.Database.Name";
private static String dbName;
private static final String DB_USER_NAME = "awgview.server.Database.UserName";
private static String dbUserName;
private static final String DB_USER_PASS = "awgview.server.Database.Password";
private static String dbUserPass;
private static final String DB_MAX_CONNECT = "awgview.server.Database.MaxConnection";
private static final int DEFAULT_DB_MAX_CONNECT = 10;
private static final int MIN_CONNECT = 1;
public static final int MAX_CONNECT = 100;
private static int dbMaxConnect;
private static final String DB_MAX_CAPCITY_OPER_HISTORY = "awgview.server.Database.MaxCapacityOperationHistory";
private static final int DEFAULT_CAPCITY_OPER_HISTORY = 100000;
private static int MIN_CAPCITY_OPER_HISTORY = 10000;
private static int MAX_CAPCITY_OPER_HISTORY = 100000;
private static long dbMaxCapcityOperHistory;
private static final String DB_MAX_CAPCITY_ALAMR_HISTORY = "awgview.server.Database.MaxCapacityAlarmHistory";
private static final int DEFAULT_CAPCITY_ALAMR_HISTORY = 100000;
private static int MIN_CAPCITY_ALAMR_HISTORY = 10000;
private static int MAX_CAPCITY_ALAMR_HISTORY = 100000;
private static long dbMaxCapcityAlarmHistory;
private static final String DB_MAX_CAPCITY_CURRENT_ALARM = "awgview.server.Database.MaxCapacityCurrentAlarm";
private static final int DEFAULT_MAX_CAPCITY_CURRENT_ALARM = 1000;
private static int MIN_CAPCITY_CURRENT_ALARM = 1000;
private static int MAX_CAPCITY_CURRENT_ALARM = 100000;
private static long dbMaxCapcityCurrentAlarm;
private static final String KEEP_ALIVE_TIME_OUT = "awgview.server.user.KeepAliveTimeOut";
private static final int DEFAULT_KEEP_ALIVE_TIME_OUT = 60;
private static int MIN_KEEP_ALIVE_TIME_OUT = 30;// Second
private static int MAX_KEEP_ALIVE_TIME_OUT = 180; // Second
private static int keepAliveTimeOut;
// SNMP Version: [0 = Version 1]; [1 = Version 2C]
private static final String SNMP_VERSION = "awgview.server.snmp.Version";
private static final int DEFAULT_SNMP_VERSION = SnmpConstants.version1; // Version 1
private static int snmpVersion = DEFAULT_SNMP_VERSION;
private static boolean isReadConfig = false;
/**
* Get SNMP Version
*
* @return snmpVersion
*/
public static int getSnmpVersion() {
return snmpVersion;
}
/**
* Get SNMP time out
*
* @return snmpTimeOut
*/
public static int getSNMPTimeOut() {
return snmpTimeOut;
}
/**
* Get SNMP Retry
*
* @return snmpRetry
*/
public static int getSNMPRetry() {
return snmpRetry;
}
/**
* Get SNMP Community
*
* @return snmpCommunity
*/
public static String getSNMPCommunity() {
return snmpCommunity;
}
/**
* Get Server Address
*
* @return String The Server Address
*/
public static String getServerAddress() {
return serverAddress;
}
/**
* Returns the DB Host
*
* @return dbHost
*/
public static String getDBHost() {
return dbHost;
}
public static int getDBPort() {
return dbPort;
}
public static String getDBName() {
return dbName;
}
public static String getDBUserName() {
return dbUserName;
}
public static String getDBUserPass() {
return dbUserPass;
}
public static int getDBMaxConnect() {
return dbMaxConnect;
}
public static long getDBMaxCapcityOperHistory() {
return dbMaxCapcityOperHistory;
}
public static long getDBMaxCapcityAlarmHistory() {
return dbMaxCapcityAlarmHistory;
}
public static long getDBMaxCurrentAlarm() {
return dbMaxCapcityCurrentAlarm;
}
public static int getKeepAliveTimeOut() {
return keepAliveTimeOut;
}
public static int getMaximumUSerLogin() {
return dbMaxConnect;
}
/**
* Returns JBoss Home
*
* @return String
*/
public static String getJBossHome() {
if (AppMainServer.JBOSS_HOME == null) {
AppMainServer.JBOSS_HOME = System.getenv("JBOSS_HOME");
if (AppMainServer.JBOSS_HOME == null) {
LogWriter.getDBLogger().fatal("Make sure that JBOSS_HOME is still defined in the environment");
LogWriter.getSNMPLogger().fatal("Make sure that JBOSS_HOME is still defined in the environment");
System.exit(0);
}
}
return AppMainServer.JBOSS_HOME;
}
/**
* Read configuration file to get parameters of the application
*
* @return boolean
*/
public static boolean readConfig() {
String pathConf = getJBossHome() + Constants.SERVER_CONFIG_FILE;
if (isReadConfig) {
return true;
}
LogWriter.getDBLogger().info("Read file configuration with path: " + pathConf);
LogWriter.getSNMPLogger().info("Read file configuration with path: " + pathConf);
if (Config.loadFile(pathConf) == null) {
return false;
}
if (!getSettingServerAddress()) {
return false;
}
if (!(getSettingDBName())) {
return false;
}
if (!(getSettingDBHost())) {
return false;
}
if (!(getSettingDBPort())) {
return false;
}
if (!(getSettingDBUserName())) {
return false;
}
if (!(getSettingDBUserPass())) {
return false;
}
getSettingDBMaxConnect();
getSettingDBMaxCapcityAlarmHistory();
getSettingDBMaxCapcityCurrentAlarm();
getSettingDBMaxCapcityOperHistory();
getSettingSNMPRetry();
getSettingSNMPTimeOut();
getSettingSNMPCommunity();
getSettingKeepAliveTimeOut();
getSettingSnmpVersion();
isReadConfig = true;
return true;
}
/**
* Get setting SNMP Retry form configuration file
*/
private static void getSettingSNMPRetry() {
String strSNMPRetry = Config.getParamConfig(KEY_SNMP_RETRY);
if (strSNMPRetry != null) {
try {
snmpRetry = Utils.parseInt(strSNMPRetry, -1);
if (snmpRetry < MIN_SNMP_RETRY) {
snmpRetry = DEFAULT_SNMP_RETRY;
LogWriter.getSNMPLogger().error("Setting SNMP retry is less than " + MIN_SNMP_RETRY);
LogWriter.getSNMPLogger().warn("Setting SNMP retry is default value: " + DEFAULT_SNMP_RETRY);
} else if (snmpRetry > MAX_SNMP_RETRY) {
snmpRetry = DEFAULT_SNMP_RETRY;
LogWriter.getSNMPLogger().error("Setting SNMP retry is large than " + MAX_SNMP_RETRY);
LogWriter.getSNMPLogger().warn("Setting SNMP retry is default value: " + DEFAULT_SNMP_RETRY);
} else {
LogWriter.getSNMPLogger().info("Snmp Retry = " + snmpRetry);
}
} catch (NumberFormatException e) {
snmpRetry = DEFAULT_SNMP_RETRY;
LogWriter.getSNMPLogger().error(e.getMessage());
LogWriter.getSNMPLogger().error("Invalid format of SNMP retry " + strSNMPRetry);
LogWriter.getSNMPLogger().warn("Setting SNMP retry is default value: " + DEFAULT_SNMP_RETRY);
}
} else {
snmpRetry = DEFAULT_SNMP_RETRY;
LogWriter.getSNMPLogger().error("Could not read setting SNMP retry");
LogWriter.getSNMPLogger().warn("Setting SNMP retry is default value: " + DEFAULT_SNMP_RETRY);
}
}
/**
* Get setting SNMP Time Out form configuration file
*/
private static void getSettingSNMPTimeOut() {
String strSNMPTimeOut = Config.getParamConfig(KEY_SNMP_TIMEOUT);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -