Java tutorial
/* * <pre> * Copyright (c) 2014 Samsung SDS. * All right reserved. * * This software is the confidential and proprietary information of Samsung * SDS. You shall not disclose such Confidential Information and * shall use it only in accordance with the terms of the license agreement * you entered into with Samsung SDS. * * Author : Takkies * Date : 2014. 04. 01. * Description : * </pre> */ package com.sds.acube.ndisc.mts.xserver.util; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Properties; import org.apache.commons.lang.StringUtils; import org.jconfig.Configuration; import org.jconfig.ConfigurationManager; import com.sds.acube.ndisc.mts.filter.iface.FilterIF; import com.sds.acube.ndisc.mts.util.loader.DynamicClassLoader; /** * XNDisc ? * * @author Takkies * */ public class XNDiscConfig { /* ? */ public static final Configuration configuration = ConfigurationManager.getConfiguration(); /* ? ? ? */ public static final int INIT_BUFFER_SIZE = 4096; /* ? ? ? */ public static final int REPLY_BUFFER_SIZE = 4096; public static final int FILE_TRANS_BUFFER_SIZE = 4096 * 8; // 32768 byte (32k) /* ??? ? ? */ public static final String DELIM_STR = "|"; /* ? ?( ??? ? ) */ public static final String NO_ERROR = "0"; /* ? ?( ??? ? ) */ public static final String ERROR = "-1"; /* ? storage */ public static final String STORAGE_PATH_REGIST = "PATH_REGIST"; /* ? */ public static final String STORAGE_PATH_ACCESS = "PATH_ACCESS"; /* , ? */ public static final String STAT_NONE = "0"; /* */ public static final String STAT_COMP = "1"; /* */ public static final String STAT_ENC = "2"; /* + */ public static final String STAT_COMP_ENC = "3"; /* (DRM ? ) */ public static final String STAT_AUTO = "-1"; /* ? ? ? */ public static final String NDISC_NA_RESERV = "@@NOT_ASSIGN@@"; /* ?(config.xml)? XNDisc Server host property */ public static final String HOST = "host"; /* host */ public static final String LOCAL_HOST = "127.0.0.1"; /* port */ public static final int LOCAL_PORT = 7404; /* ?(config.xml)? XNDisc Server port property */ public static final String PORT = "port"; /* ?(config.xml)? storage ? property */ public static final String STORAGE = "impl_class_storage"; /* ?(config.xml)? logger ? property */ public static final String LOGGER = "impl_class_logger"; /* ?(config.xml)? ? property */ public static final String COMPRESS = "impl_class_comp"; /* ?(config.xml)? ? property */ public static final String ENCRYPT = "impl_class_enc"; /* ?(config.xml)? property */ public static final String TEMP_DIR = "tmp_dir"; /* XNDisc Server ? Worker Pool Size property */ public static final String SIZE_WORKER_POOL = "workerpool_size"; /* XNDisc Server ? Worker Pool minimum Size property */ public static final String MIN_SIZE_WORKER_POOL = "workerpool_min_size"; /* XNDisc Server ? Worker Pool property */ public static final String WORKER_POOL_THREAD_COUNT = "workerpool_thread_count"; /* XNDisc Server ? Worker Pool property */ public static final String WORKER_POOL_TYPE = "workerpool_type"; /* XNDisc Server ? Worker Pool property */ public static final String WORKER_POOL_PRIORITY = "workpool_thread_priority"; /* XNDisc Server ? ? property */ public static final String DISPATCHER_INIT_COUNT = "dispatcher_initial_count"; /* XNDisc Server ? ? property */ public static final String DISPATCHER_MAX_HANDLES = "dispatcher_max_handles"; /* XNDisc Server ? ? ? property */ public static final String READ_BUFFER_USEDIRECT = "readbuffer_usedirect"; /* XNDisc Server? property */ public static final String NDISC_CIPHER_KEY = "cipher_key"; /* XNDisc Server? ?? property */ public static final String NDISC_LICENSE_KEY = "license_key"; /* XNDisc Server fail over */ public static final String NDISC_FAILOVER_CATEGORY = "connection_failover"; /* XNDisc Server fail over ? property */ public static final String NDISC_FAILOVER_APPLY = "con_failover_apply"; /* XNDisc Server fail over (HOST:PORT;HOST1:PORT1...) property */ public static final String NDISC_FAILOVER_HOSTS = "con_failover_target"; /* FixedThreadPool ? Processor? ? ? */ public static final String MULTIPLICATION_THREAD_AVAILABLE_PROCESSORS = "multiplication_thread_available_processors"; /* ? ? detach property */ public static final String DETACH_HANDLE_NO_OPERATION = "detach_handle_no_operation"; /* ? ?? ? property */ public static final String TRANSFER_MAPPED_BYTE_BUFFER_MAXSIZE = "transfer_mapped_bytebuffer_maxsize"; /* XNDisc Server SSL property */ public static final String USE_SSL = "use_ssl"; /* XNDisc Server SSL key file (? (? ?? ? )?) property */ public static final String SSL_SERVER_KEY_FILE = "ssl_server_key_file"; /* XNDisc Server SSL property */ public static final String SSL_PASSPHRASE = "ssl_passphrase"; public static final String XSOCKET_DEBUG = "xsocket_debug"; public static final String TRANSFER_TYPE = "transfer_type"; /* ? */ private static FilterIF filterEncrypt; /* ? */ private static FilterIF filterCompress; /* ? */ private static HashMap<String, String> config; static { config = new HashMap<String, String>(); reset(); } /** * */ private static void reset() { try { if (config != null) { config.clear(); } init(); } catch (Exception e) { e.printStackTrace(); } } /** * */ private static void init() { Properties props = null; String[] categoryNames = configuration.getCategoryNames(); for (String catgnm : categoryNames) { props = configuration.getProperties(catgnm); Enumeration<?> enumeration = props.propertyNames(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); String value = props.getProperty(key); config.put(key, replaceValueByVariables(value)); } } } /** * variable? ? value * * @param value ? * @return ? ? */ @SuppressWarnings("unchecked") private static String replaceValueByVariables(String value) { HashMap<String, String> variables = configuration.getVariables(); Iterator<String> iterator = variables.keySet().iterator(); String key = ""; String keyval = ""; String repkeyval = ""; while (iterator.hasNext()) { key = (String) iterator.next(); keyval = "${".concat(key).concat("}"); repkeyval = "\\$\\{".concat(key).concat("\\}"); if (value.indexOf(keyval) != -1) { value = value.replaceAll(repkeyval, variables.get(key)); break; } } return value; } /** * * * @param key * @param category * @return */ public static String[] getArray(String key, String category) { String vals[] = configuration.getArray(key, new String[] {}, category); if (vals == null || vals.length < 0) { return new String[] {}; } return vals; } /** * ? * * @param key * @return ? */ public static String getString(String key) { return getString(key, null); } /** * ? * * @param key * @param defval (? ? ) * @return ? */ public static String getString(String key, String defval) { String val = config.get(key); if (StringUtils.isEmpty(val)) { return defval; } else { return val; } } /** * ?(INTEGER) * * @param key * @return ?(INTEGER) */ public static int getInt(String key) { return getInt(key, 0); } /** * ?(INTEGER) * * @param key * @param defval (? ? ) * @return ?(INTEGER) */ public static int getInt(String key, int defval) { String val = config.get(key); if (StringUtils.isEmpty(val)) { return defval; } else { return Integer.parseInt(val); } } /** * ?(LONG) * * @param key * @return ?(LONG) */ public static long getLong(String key) { return getLong(key, 0); } /** * ?(LONG) * * @param key * @param defval (? ? ) * @return ?(LONG) */ public static long getLong(String key, long defval) { String val = config.get(key); if (StringUtils.isEmpty(val)) { return defval; } else { return Long.parseLong(val); } } /** * (Boolean) <br> * ? ? (1, true, Y)? ?. * * @param key * @return */ public static boolean getBoolean(String key) { String val = getString(key, "0"); return (val.equals("1") || val.equalsIgnoreCase("true") || val.equalsIgnoreCase("Y")); } /** * ? * * @return */ public static FilterIF getFilterEncrypt() { if (filterEncrypt == null) { try { filterEncrypt = (FilterIF) DynamicClassLoader.createInstance(config.get(ENCRYPT)); } catch (Exception e) { } } return filterEncrypt; } /** * * * @param filterEncrypt */ public static void setFilterEncrypt(FilterIF filterEncrypt) { XNDiscConfig.filterEncrypt = filterEncrypt; } /** * ? * @return */ public static FilterIF getFilterCompress() { if (filterCompress == null) { try { filterCompress = (FilterIF) DynamicClassLoader.createInstance(config.get(COMPRESS)); } catch (Exception e) { } } return filterCompress; } /** * * * @param filterCompress */ public static void setFilterCompress(FilterIF filterCompress) { XNDiscConfig.filterCompress = filterCompress; } }