Search in sources :

Example 1 with IniFileReader

use of com.zhouzifei.tool.media.file.common.fastdfs.common.IniFileReader in project simpleFS by shengdingbox.

the class ClientGlobal method init.

/**
 * load global variables
 *
 * @param conf_filename config filename
 */
public static void init(String conf_filename) throws IOException, ServiceException {
    IniFileReader iniReader;
    String[] szTrackerServers;
    String[] parts;
    iniReader = new IniFileReader(conf_filename);
    g_connect_timeout = iniReader.getIntValue("connect_timeout", DEFAULT_CONNECT_TIMEOUT);
    if (g_connect_timeout < 0) {
        g_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
    }
    // millisecond
    g_connect_timeout *= 1000;
    g_network_timeout = iniReader.getIntValue("network_timeout", DEFAULT_NETWORK_TIMEOUT);
    if (g_network_timeout < 0) {
        g_network_timeout = DEFAULT_NETWORK_TIMEOUT;
    }
    // millisecond
    g_network_timeout *= 1000;
    g_charset = iniReader.getStrValue("charset");
    if (g_charset == null || g_charset.length() == 0) {
        g_charset = "ISO8859-1";
    }
    szTrackerServers = iniReader.getValues("tracker_server");
    if (szTrackerServers == null) {
        throw new ServiceException("item \"tracker_server\" in " + conf_filename + " not found");
    }
    InetSocketAddress[] tracker_servers = new InetSocketAddress[szTrackerServers.length];
    for (int i = 0; i < szTrackerServers.length; i++) {
        parts = szTrackerServers[i].split("\\:", 2);
        if (parts.length != 2) {
            throw new ServiceException("the value of item \"tracker_server\" is invalid, the correct format is host:port");
        }
        tracker_servers[i] = new InetSocketAddress(parts[0].trim(), Integer.parseInt(parts[1].trim()));
    }
    g_tracker_group = new TrackerGroup(tracker_servers);
    g_tracker_http_port = iniReader.getIntValue("http.tracker_http_port", 80);
    g_anti_steal_token = iniReader.getBoolValue("http.anti_steal_token", false);
    if (g_anti_steal_token) {
        g_secret_key = iniReader.getStrValue("http.secret_key");
    }
    g_connection_pool_enabled = iniReader.getBoolValue("connection_pool.enabled", DEFAULT_CONNECTION_POOL_ENABLED);
    g_connection_pool_max_count_per_entry = iniReader.getIntValue("connection_pool.max_count_per_entry", DEFAULT_CONNECTION_POOL_MAX_COUNT_PER_ENTRY);
    g_connection_pool_max_idle_time = iniReader.getIntValue("connection_pool.max_idle_time", DEFAULT_CONNECTION_POOL_MAX_IDLE_TIME);
    if (g_connection_pool_max_idle_time < 0) {
        g_connection_pool_max_idle_time = DEFAULT_CONNECTION_POOL_MAX_IDLE_TIME;
    }
    g_connection_pool_max_idle_time *= 1000;
    g_connection_pool_max_wait_time_in_ms = iniReader.getIntValue("connection_pool.max_wait_time_in_ms", DEFAULT_CONNECTION_POOL_MAX_WAIT_TIME_IN_MS);
    if (g_connection_pool_max_wait_time_in_ms < 0) {
        g_connection_pool_max_wait_time_in_ms = DEFAULT_CONNECTION_POOL_MAX_WAIT_TIME_IN_MS;
    }
}
Also used : ServiceException(com.zhouzifei.tool.common.ServiceException) InetSocketAddress(java.net.InetSocketAddress) IniFileReader(com.zhouzifei.tool.media.file.common.fastdfs.common.IniFileReader)

Aggregations

ServiceException (com.zhouzifei.tool.common.ServiceException)1 IniFileReader (com.zhouzifei.tool.media.file.common.fastdfs.common.IniFileReader)1 InetSocketAddress (java.net.InetSocketAddress)1