package com.eactive.eai.adapter.socket2.config;

import java.io.Serializable;
import java.util.Properties;
import java.util.concurrent.Semaphore;

import com.eactive.eai.adapter.AdapterVO;
import com.eactive.eai.adapter.socket2.protocol.IRequestProcessor;
 

/** 
* 1. 기능 : SocketAdapter의 구성정보 및 속성을 나타내는 Object Class
* 2. 처리 개요 : 
*     - 구성정보의 DEFAULT값을 갖고 있으며, 각 속성에 대한 getter/setter 기능을 제공한다.
* 3. 주의사항 
*     - 해당 Property의 기본속성값을 확인하여, 해당 Property의 속성지정을 생략시 어떤 값을 갖는지 확인하여야한다.
**/

public class SocketAdapterContext implements Serializable {
	public static final String INBOUND_SOCKET 	= "INBOUND";
	public static final String OUTBOUND_SOCKET 	= "OUTBOUND";
	public static final String IOBOUND_SOCKET 	= "IOBOUND";
	
	public static final String SERVER_SOCKET 	= "SERVER";
	public static final String CLIENT_SOCKET 	= "CLIENT";
	public static final String ADMIN_SOCKET 	= "ADMIN";

	public static final String SYNC_MODE		= "SYNC";
	public static final String ASYNC_MODE		= "ASYN";
    
//	public static final String ACKON_MODE       = "AKON";
	
	public static final String TRUE_FLAG		= "Y";
	public static final String FALSE_FLAG		= "N";
	
    /**
     * trace level
     */
	public  static final int TRACE_LEVEL_DEFAULT 	= 0;		// WARNING, ERROR, FATAL인 경우 에러로깅
	public  static final int TRACE_LEVEL_INFO 		= 1;		// INFO 수준의 LOGGING을 수행한다.
	public  static final int TRACE_LEVEL_DEBUG		= 2;		// DEBUG 수준의 송수신전문 및 에러 메인처리내용의 모든수준의 로깅을 수행한다.
	public  static final int TRACE_LEVEL_TRACE		= 3;		// TRACE 수준의 송수신전문 및 에러 메인처리내용의 모든수준의 로깅을 수행한다.

	/**
	 * xecure type
	 */
	public static final String XECURE_TYPE_BASIC       = "BASIC";
	public static final String XECURE_TYPE_FIXED       = "FIXED";
	public static final String XECURE_TYPE_WELCOME     = "WELCOME";
	public static final String XECURE_TYPE_ENVELOPE    = "ENVELOPE";       // 전자봉투 
	public static final String XECURE_TYPE_FIXEDHEADER = "FIXEDHEADER";
	
	/**
	 * Configuration properties
	 */
	private String	adapterGroupName	= "AdapterGroup";	    // SOCKET ADADAPTER GROUP NAME
	private String 	adapterName 		= "Adapter"; 		  	// SOCKET ADAPTER 구성 이름
	
	private String  protocol            = "FIXED_LENGTH_HEADER"; //FIXED_LENGTH_HEADER | CISCO | ADMIN | XECURE | CERT | HTTP
	private String  permanent			= "Y";					// Permanent or Non-Permanent
	
	private String 	boundUsage 			= IOBOUND_SOCKET; 		// INBOUND | OUTBOUND | IOBOUND
	private String 	socketType 			= CLIENT_SOCKET; 		// SERVER | CLIENT

	
	private String 	hostName 			= "localhost"; 			// BIND할 서버의 호스트명 또는 IP ADDRESS
	private int 	portNumber 			= 0; 					// BIND할 서버의 PORT NUMBER

	private String 	localHostName 		= ""; 					// Client Socket Type에 한하여 설정
	private int 	localPortNumber 	= 0; 					// Client Socket Type으로 원격서버와 연결시 BIND할localPortNumber
	
	private int		connLimitPerIp		= 0;					// SERVER TYPE SOCKET의 경우 REMOTE의 특정 IP별  CONNECTION 수를 제한시키는 것
	private int 	maxConnection 		= 0; 					// 원격시스템과 Socket Connection 최대허용 수
																// Server Socket의 경우 - Server Listening port로 접속허용할 최대 수
																// Client Socket의 경우 - Remote Host의 지정 포트로 연결할 최대 Connection 수
	private Semaphore maxConnSemaphore  = null;
	private boolean	bCloseExistingConnection = false; 			// maxConnection < 0 일 경우 이전 'YOUNG' connection을 끊고 새로운 connection을 맺는다.
	// negative(-) 옵션을 준 상태에서 세션이 Full 상태 일때, 가장 오래 된 세션을 끊고 새로운 세션을 연결한다. 
	private boolean bCloseExistingConnectionPerIpLimit = false;	// maxConnectionPerIp < 0 일 경우 이전 'OLDEST' connection을 끊고 새로운 connection을 맺는다.

	private int 	maxThread 			= 10; 					// INBOUND의 경우한하여 의미가 있음.
//	private int 	maxThread 			= 1; 					// Worker Thread default 1로 조정, 2009.10.16
																// Socket Adapter의 N개의 Connection에 대해 session을 연결할 최대 수 (실행 Thread Pool의 Session수)

	private int 	timeout 			= 60; 					// Socket Read Timeout & Transaction Timeout 값 설정 (단위 : 초) 
	
	private int 	idleTimeout         = 0;                    // 초단위
	
	private String 	responseType 		= SYNC_MODE; 			// SYNC_MODE, ASYNC_MODE
	private String  socketReuse 		= TRUE_FLAG; 			// "Y" - Socket Connection reuse

	/**
	 * client & non-perm & fixed_length_header & sync
	 * 일 경우 서버에서 응답을 주고 connection 을 끊는 경우 처리를 위하여
	 * 예) 데이콤
	 */
	private String  blocking             = "N";
	
	/**
	 * ll
	 */
	private String  llFieldType 		= "BIN";	            // BIN(Binary), CHAR(Numeric Character), CISCO
	private int		llFieldLength		= 2;					// LL필드길이 2-unsigned short, 4 ~ 8 Numeric Char
	private int		llFieldOffset       = 0;					// LL 필드가 중간에 있을 경우 offset
	private String  llFieldInclude		= FALSE_FLAG;			// LL 필드 length 가 (header=ll) 을 포함하는가?
	private String  llOffsetExclude	    = FALSE_FLAG;			// Offset을 포함하여 LL Length를 계산할 것인가?
	private String  llInclude			= FALSE_FLAG;			// LL 필드를 포함하여 F/W 에 던질 것인가?
	
	private int		llLenAdjust       = 0;					// 한은맘 헤더 길이 평문테스트 용
	
	/**
	 * payload length
	 */
	private int     sendPayloadLength       = 0;
	private int     recvPayloadLength       = 0;
	
	/**
	 * variable header length
	 */
	private int     sendHeaderLength       = 0;
	private int     recvHeaderLength       = 0;
	
	
	
	private String  ackSupport          = FALSE_FLAG;           // ACK송수신 여부 -- Client Type의 Socket에 적용되며, 서버는 Protocol에 의해 작동판단...
    private String 	bwkClsCd 			= ""; 					// 업무구분코드
    
    private String  validationRule      = "";
    
	/**
	 * dataControlRule 금결원
	 */
	private String dataControlRule      = "";
    
	private int 	traceLevel 			= TRACE_LEVEL_DEFAULT; 	// 추적관리 수준 - 0, 1, 2
	private String 	description 		= ""; 					// Socket Adapter Configuration에 대한 용도설명

	/**
	 * acl
	 */
	private String  aclList 			= "";
	
	/**
	 * script (groovy | response message)
	 */
	private String 	script              = "";
	
	/**
	 * polling
	 */
	private String  pollingUse			    = "N";
	private String  pollingRole			    = "";                // SENDER|RECEIVER
	private String  pollingOneway			= "N";               // Y|N
	private int		pollingTimeout		    = 600;
	private String  pollingRequest		    = "HDRREQPOLL%d{MMddHHmmss}";
	private String  pollingRequestPattern   = "(HDR)?(REQPOLL)([0-9]{10})";
	private String  pollingReplacement      = "$1RESPOLL$3";
	private String  pollingResponsePattern  = "(HDR)?(RESPOLL)([0-9]{10})";
	
	/**
	 * init Message
	 */
	private String  initMsgUse			    = "N";
	private String  initMsgRole			    = "";                // SENDER|RECEIVER
	private String  initMsgRequest		    = "INITREQMSG%d{MMddHHmmss}";
	private String  initMsgRequestPattern   = "(INIT)?(REQMSG)([0-9]{10})";
	private String  initMsgReplacement      = "$1RESMSG$3";
	private String  initMsgResponsePattern  = "(INIT)?(RESMSG)([0-9]{10})";
	
	/**
	 * Security - SSL
	 */
	private String sslUse               = "N";
	private String sslCertStore 		= "";                   // SSL용 보안 인증서, TCSEED용 Key저장소 
	private String sslCertPassword 		= "";                   // SSL용 인증서 암호
	
	/**
	 * inisafe
	 */
	private String inisafeConfigPath 			= "";    
	private String inisafeRelatedAdapterGroups 	= "";
	private String inisafeStartMessage          = "STARTED";
	private String inisafeStopMessage           = "STOPPED";
	
	/**
	 * inisafe_payload
	 */
	private String inisafeIdPassword 			= "";           // 은행코드(3) + ID(8) + Password(20)
	
	/**
	 * SMS
	 */
	private String smsRunningTime		= "";
	
	/**
	 * XC (XecureConnect)
	 */
	private String xecureType       	= "";                   // XC 보안 모듈 타입 (TYPEA, TYPEB, ..)
	private String xecureConfigPath 	= "";                   // XecureConnect 설정에 필요한 정보 (인증서정보, 세팅사항 등..)
	private String xecurePassword   	= "";                   // 개인키 추출을 위한 비밀번호 문자열
	private String xecureRemoteCert 	= "";                   // 전자봉투 방식 - remote cert file
	
	/**
	 * Xecure2 Connect[Session Manager]
	 */
	private String xecure2ConfigPath	= ""; // example : "/fshome/greai/eaiadm/softforum/xc20/conf/cert.txt";
	private String xecure2SmIp			= "127.0.0.1";
	private int    xecure2SmPort		= 9300;

	/**
	 * Xecure3 Connect
	 */
	private String xecure3CertStore		= "/fshome/greai/eaiadm/softforum/xc30/certstore";
	private String xecure3ServerCert	= "/fshome/greai/eaiadm/softforum/xc30/cert/kb/SignCert.der";
	private String xecure3CertKey		= "/fshome/greai/eaiadm/softforum/xc30/cert/kb/signPri.key";
	private String xecure3ClientCert	= "/fshome/greai/eaiadm/softforum/xc30/cert/army/SignCert.der";
	private String xecure3CertPassword 	= "qwer1234";
	
	/**
	 * Xecure3 epb
	 */
	private String xc3epbPassword       = "";                   // 개인키 추출을 위한 비밀번호 문자열
	private String xc3epbConfigPath 	= "";                   // XecureConnect3 설정에 필요한 정보 (인증서정보, 세팅사항 등..)
	
	/**
	 * ENVELOP Connect[Session Manager]
	 */
	private String envelopSigncertPath	= ""; // example : "/fshome/greai/eaiadm/softforum/xc20/conf/signCert.der"
	private String envelopSignkeyPath	= ""; // example : "/fshome/greai/eaiadm/softforum/xc20/conf/signPri.key"
	private String envelopPassword   	= ""; // example : "qwer1234";
	
	/**
	 * login client 
	 */
	private String loginSend                = "";
	private String loginRecv   	            = "";
	private String bindType                 = "";
	private int	   llFieldLengthAlpha       =  0;
	
	/**
	 * Security - TCSEED
	 */
	private String tcseedKeyStore 		= "";                   // TCSEED용 Key저장소 
	
	/**
	 * inisis
	 */
	private String inicisKeyPath ="";
	private String inicisKeyPass ="";
	
	/**
	 * append protocol
	 */
	private String appendHead               ="";
	private String appendTail               ="";
	
	/**
	 * block ip list
	 */
	private String blockIpList                     ="";

	/**
	 * l4 skip ip list
	 */
	private String l4SkipIpList                     ="";
	/**
	 * delimiter
	 */	
	private String delimiter                        ="";	
	
	/**
	 * IS_SINGLE_SESSION
	 */
	private String singleSession = "N"; // Y : 기관 허용세션이 1인 경우
	
	// 기관 허용세션이 1이면서 Active/Active 인스던스 2개 운영시 Primary 인스던스명 - 싱글어댑터 속성
	private String primaryInstId = ""; 
	

	private String dynamicOffsetPattern    = "";
	private String dataAddRule             = "";
	private String dataRemoveRule          = "";
	
	/**
	 * SO_KEEPALIVE
	 */
	private String keepAlive = "N"; // Y : TCP KeepAlive option

	
	/**
	 * 
	 */
	private AdapterVO 		  adapterVO        = null;
	private IRequestProcessor requestProcessor = null;
    private boolean           started          = true;
    

    
    public SocketAdapterContext() {
    }
    
	public SocketAdapterContext(Properties prop) {		
		this.adapterGroupName	= prop.getProperty("ADAPTER_GROUP_NAME", "").trim();
		this.adapterName		= prop.getProperty("ADAPTER_NAME", "").trim();
		this.hostName 			= prop.getProperty("HOST_NAME", "").trim();
		this.portNumber 		= Integer.parseInt(prop.getProperty("PORT_NUMBER", "").trim());		
		this.traceLevel 		= Integer.parseInt(prop.getProperty("TRACE_LEVEL", "2").trim());		

		this.socketType 		= prop.getProperty("SOCKET_TYPE", CLIENT_SOCKET).trim();
		this.boundUsage 		= prop.getProperty("BOUND_USAGE", OUTBOUND_SOCKET).trim();
		this.ackSupport 		= prop.getProperty("ACK_SUPPORT", FALSE_FLAG).trim();
		this.protocol   		= prop.getProperty("PROTOCOL", "FIXED_LENGTH_HEADER").trim();
		this.llFieldType 		= prop.getProperty("LL_FIELD_TYPE", "BIN").trim();
		this.llFieldLength 		= Integer.parseInt(prop.getProperty("LL_FIELD_LENGTH", "2").trim());
		this.llFieldOffset 		= Integer.parseInt(prop.getProperty("LL_FIELD_OFFSET", "0").trim());
		this.llFieldInclude		= prop.getProperty("LL_FIELD_INCLUDE", "N").trim();
		this.llOffsetExclude	= prop.getProperty("LL_OFFSET_EXCLUDE", "N").trim();
		this.llInclude  		= prop.getProperty("LL_INCLUDE", "N").trim();
		this.responseType 		= prop.getProperty("RESPONSE_TYPE", "SYNC").trim();
		this.timeout    		= Integer.parseInt(prop.getProperty("TIMEOUT", "60").trim());
		this.maxConnection 		= Integer.parseInt(prop.getProperty("MAX_CONNECTION", "1").trim());
		this.maxConnSemaphore	= new Semaphore(this.maxConnection > 0 ? this.maxConnection : -this.maxConnection);
		this.permanent  		= prop.getProperty("PERMANENT", "Y").trim();
		this.aclList  			= prop.getProperty("ACL_LSIT", "").trim();
		
		this.recvHeaderLength   = Integer.parseInt(prop.getProperty("RECV_HEADER_LENGTH", "0").trim());
		this.sendHeaderLength   = Integer.parseInt(prop.getProperty("SEND_HEADER_LENGTH", "0").trim());
		
		this.smsRunningTime		= prop.getProperty("SMS_RUNNING_TIME", "").trim();
		
		this.pollingUse			= prop.getProperty("POLLING_USE", "N").trim();
		
		this.initMsgUse         = prop.getProperty("INIT_MSG_USE", "N").trim();
		
		this.singleSession      = prop.getProperty("IS_SINGLE_SESSION", "N").trim();
		
		this.keepAlive      = prop.getProperty("KEEP_ALIVE", "N").trim();
		
	}

	public String getAdapterGroupName() {
		return adapterGroupName;
	}

	public void setAdapterGroupName(String adapterGroupName) {
		this.adapterGroupName = adapterGroupName;
	}

	public String getAdapterName() {
		return adapterName;
	}

	public void setAdapterName(String adapterName) {
		this.adapterName = adapterName;
	}
	
	
	public void setProtocol(String protocol) {
		this.protocol = protocol;
	}
	
	public String getProtocol() {
		return this.protocol;
	}

	public int getConnLimitPerIp() {
		return connLimitPerIp;
	}

	public void setConnLimitPerIp(int connLimitPerIp) {
		if (connLimitPerIp < 0) {
			setCloseExistingConnectionPerIpLimit(true);
			this.connLimitPerIp = -connLimitPerIp;
		} else {
			this.connLimitPerIp = connLimitPerIp;
		}
	}
	
	public boolean getCloseExistingConnectionPerIpLimit() {
		return this.bCloseExistingConnectionPerIpLimit;
	}

	public void setCloseExistingConnectionPerIpLimit(boolean bCloseExistingConnectionPerIpLimit) {
		this.bCloseExistingConnectionPerIpLimit = bCloseExistingConnectionPerIpLimit;
	}

	public String getBwkClsCd() {
		return bwkClsCd;
	}

	public void setBwkClsCd(String bizCode) {
		this.bwkClsCd = bizCode;
	}
    
    public String getAckSupport() {
		return ackSupport;
	}

	public void setAckSupport(String ackSupport) {
		this.ackSupport = ackSupport;
	}

	public String getBoundUsage() {
		return boundUsage;
	}

	public void setBoundUsage(String boundUsage) {
		this.boundUsage = boundUsage;
	}
	
	public void setPermanent(String permanent) {
		this.permanent = permanent;
	}

	public String getPermanent() {
		return permanent;
	}
	
	public boolean isPermanent() {
		return "Y".equals(permanent);
	}

	public void setPollingUse(String pollingUse) {
		this.pollingUse = pollingUse;
	}

	public String getPollingUse() {
		return pollingUse;
	}
	
	public boolean isPollingUse() {
		return "Y".equals(pollingUse);
	}

	public void setPollingRole(String pollingRole) {
		this.pollingRole = pollingRole;
	}

	public String getPollingRole() {
		return pollingRole;
	}
	
	public boolean isPollingSender() {
		if ("".equals(pollingRole)) {
			return isClient();
		} else {
			return "SENDER".equals(pollingRole);
		}
	}
	
	public boolean isPollingReceiver() {
		return !isPollingSender();
	}
	
	public String getPollingOneway() {
		return pollingOneway;
	}
	
	public void setPollingOneway(String oneway) {
		this.pollingOneway = oneway;
	}
	
	public boolean isPollingOneway() {
		return "Y".equals(pollingOneway);
	}

	public void setPollingTimeout(int pollingTimeout) {
		this.pollingTimeout = pollingTimeout;
	}

	public int getPollingTimeout() {
		return pollingTimeout;
	}


	public void setPollingRequest(String pollingRequest) {
		this.pollingRequest = pollingRequest;	
	}

	public String getPollingRequest() {
		return pollingRequest;
	}	

	public void setPollingRequestPattern(String pollingRequestPattern) {
		this.pollingRequestPattern = pollingRequestPattern;	
	}

	public String getPollingRequestPattern() {
		return pollingRequestPattern;
	}

	public void setPollingResponsePattern(String pollingResponsePattern) {
		this.pollingResponsePattern = pollingResponsePattern;
	}

	public String getPollingResponsePattern() {
		return pollingResponsePattern;
	}

	public void setPollingReplacement(String pollingReplacement) {
		this.pollingReplacement = pollingReplacement;
	}

	public String getPollingReplacement() {
		return pollingReplacement;
	}

//KSH
	public void setInitMsgUse(String initMsgUse) {
		this.initMsgUse = initMsgUse;
	}
	
	public String getInitMsgUse() {
		return initMsgUse;
	}

	public boolean isInitMsgUse() {
		return "Y".equals(initMsgUse);
	}

	public void setInitMsgRole(String initMsgRole) {
		this.initMsgRole = initMsgRole;
	}
	
	public String getInitMsgRole() {
		return initMsgRole;
	}

	public boolean isInitMsgSender() {
		if ("".equals(initMsgRole)) {
			return isClient();
		} else {
			return "SENDER".equals(initMsgRole);
		}
	}
	
	public boolean isInitMsgReceiver() {
		return !isInitMsgSender();
	}
	
	public void setInitMsgRequest(String initMsgRequest) {
		this.initMsgRequest = initMsgRequest;
	}

	public String getInitMsgRequest() {
		return initMsgRequest;
	}
	
	public void setInitMsgRequestPattern(String initMsgRequestPattern) {
		this.initMsgRequestPattern = initMsgRequestPattern;
	}
	
	public String getInitMsgRequestPattern() {
		return initMsgRequestPattern;
	}

	public void setInitMsgResponsePattern(String initMsgResponsePattern) {
		this.initMsgResponsePattern = initMsgResponsePattern;
	}

	public String getInitMsgResponsePattern() {
		return initMsgResponsePattern;
	}

	public void setInitMsgReplacement(String initMsgReplacement) {
		this.initMsgReplacement = initMsgReplacement;
	}
	
	public String getInitMsgReplacement() {
		return initMsgReplacement;
	}
	
//-----------------------------

	public String getValidationRule() {
		return validationRule;
	}

	public void setValidationRule(String validationRule) {
		this.validationRule = validationRule;
	}	

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public String getAclList() {
		return aclList;
	}
	
	public void setAclList(String aclList) {
		this.aclList = aclList;
	}
	
	public String getScript() {
		return script;
	}
	
	public void setScript(String script) {
		this.script = script;
	}

	public String getHostName() {
		return hostName;
	}

	public void setHostName(String hostName) {
		this.hostName = hostName;
	}

	/**
	 * ll field
	 */
	public String getLlFieldType() {
		return llFieldType;
	}

	public void setLlFieldType(String llFieldType) {
		this.llFieldType = llFieldType;
	}

	public int getLlFieldOffset() {
		return llFieldOffset;
	}

	public void setLlFieldOffset(int llFieldOffset) {
		this.llFieldOffset = llFieldOffset;
	}
	
	
	public int getLlLenAdjust() {
		return llLenAdjust;
	}

	public void setLlLenAdjust(int llLenAdjust) {
		this.llLenAdjust = llLenAdjust;
	}

	public int getLlFieldLength() {
		return llFieldLength;
	}

	public void setLlFieldLength(int llFieldLength) {
		this.llFieldLength = llFieldLength;
	}
	
	public String getLlFieldInclude() {
		return llFieldInclude;
	}

	public void setLlFieldInclude(String llFieldInclude) {
		this.llFieldInclude = llFieldInclude;
	}

	public String getLlOffsetExclude() {
		return llOffsetExclude;
	}

	public void setLlOffsetExclude(String llOffsetExclude) {
		this.llOffsetExclude = llOffsetExclude;
	}

	public String getLlInclude() {
		return llInclude;
	}

	public void setLlInclude(String llInclude) {
		this.llInclude = llInclude;
	}
	
	/**
	 * payload length
	 */
	public int getSendPayloadLength() {
		return sendPayloadLength;
	}

	public void setSendPayloadLength(int sendPayloadLength) {
		this.sendPayloadLength = sendPayloadLength;
	}
	
	public int getRecvPayloadLength() {
		return recvPayloadLength;
	}

	public void setRecvPayloadLength(int recvPayloadLength) {
		this.recvPayloadLength = recvPayloadLength;
	}
	
	/**
	 * ssl
	 */
	public String getSslUse() {
		return sslUse;
	}

	public void setSslUse(String sslUse) {
		this.sslUse = sslUse;
	}

	public String getSslCertStore() {
		return sslCertStore;
	}

	public void setSslCertStore(String sslCertStore) {
		this.sslCertStore = sslCertStore;
	}

	public String getSslCertPassword() {
		return sslCertPassword;
	}

	public void setSslCertPassword(String sslCertPassword) {
		this.sslCertPassword = sslCertPassword;
	}

	public String getLocalHostName() {
		return localHostName;
	}

	public void setLocalHostName(String localHostName) {
		this.localHostName = localHostName;
	}

	public int getLocalPortNumber() {
		return localPortNumber;
	}

	public void setLocalPortNumber(int localPortNumber) {
		this.localPortNumber = localPortNumber;
	}

	public int getMaxConnection() {
		return maxConnection;
	}

	public void setMaxConnection(int maxConnection) {
		if (maxConnection < 0) {
			setCloseExistingConnection(true);
			this.maxConnection = -maxConnection;
		} else {
			this.maxConnection = maxConnection;
		}
		
		this.maxConnSemaphore	= new Semaphore(this.maxConnection);
	}

	public boolean getCloseExistingConnection() {
		return this.bCloseExistingConnection;
	}

	public void setCloseExistingConnection(boolean bCloseExistingConnection) {
		this.bCloseExistingConnection = bCloseExistingConnection;
	}
	
	public Semaphore getMaxConnSemaphore() {
		return maxConnSemaphore;
	}

	public int getMaxThread() {
		return maxThread;
	}

	public void setMaxThread(int maxThread) {
		this.maxThread = maxThread;
	}

	public int getPortNumber() {
		return portNumber;
	}

	public void setPortNumber(int portNumber) {
		this.portNumber = portNumber;
	}

	public int getTimeout() {
		return timeout;
	}

	public void setTimeout(int timeout) {
		this.timeout = timeout;
	}

	public int getIdleTimeout() {
		return idleTimeout;
	}

	public void setIdleTimeout(int idleTimeout) {
		this.idleTimeout = idleTimeout;
	}

	public boolean isAckProtocol() {
		return this.ackSupport.equals(TRUE_FLAG);
	}

	public void setResponseType(String responseType) {
		this.responseType = responseType;
	}
	
	public String getResponseType() {
		return responseType;
	}
	
	public boolean isSync() {
		return this.responseType.equals(SYNC_MODE);
	}
	
	public void setSocketReuse(String socketReuse) {
		this.socketReuse = socketReuse;
	}
	
	public String getSocketReuse() {
		return socketReuse;
	}

	public boolean isSocketReuse() {
		return socketReuse.equals(TRUE_FLAG);
	}
	
	public String getSocketType() {
		return socketType;
	}

	public void setSocketType(String socketType) {
		this.socketType = socketType;
	}
	
	public boolean isClient() {
		return CLIENT_SOCKET.equals(socketType);
	}
	
	public boolean isServer() {
		return SERVER_SOCKET.equals(socketType);
	}
	
	public String getBlocking() {
		return blocking;
	}
	
	public void setBlocking(String blocking) {
		this.blocking = blocking;
	}
	
	public boolean isBlocking() {
		return "Y".equals(blocking);
	}

	public int getTraceLevel() {
		return traceLevel;
	}

	public void setTraceLevel(int traceLevel) {
		this.traceLevel = traceLevel;
	}

	/**
	 * inisafe protocol related
	 */
	public String getInisafeConfigPath() {
		return inisafeConfigPath;
	}

	public void setInisafeConfigPath(String inisafeConfigPath) {
		this.inisafeConfigPath = inisafeConfigPath;
	}

	public String getInisafeRelatedAdapterGroups() {
		return inisafeRelatedAdapterGroups;
	}

	public void setInisafeRelatedAdapterGroups(String inisafeRelatedAdapterGroups) {
		this.inisafeRelatedAdapterGroups = inisafeRelatedAdapterGroups;
	}
	
	public String getInisafeStartMessage() {
		return inisafeStartMessage;
	}

	public void setInisafeStartMessage(String inisafeStartMessage) {
		this.inisafeStartMessage = inisafeStartMessage;
	}
	
	public String getInisafeStopMessage() {
		return inisafeStopMessage;
	}

	public void setInisafeStopMessage(String inisafeStopMessage) {
		this.inisafeStopMessage = inisafeStopMessage;
	}

	public IRequestProcessor getRequestProcessor() {
		return requestProcessor;
	}

	public void setRequestProcessor(IRequestProcessor requestProcessor) {
		this.requestProcessor = requestProcessor;
	}	

	public void setAdapterVO(AdapterVO adapterVO) {
		this.adapterVO = adapterVO;
	}

	public AdapterVO getAdapterVO() {
		return adapterVO;
	}

    public void setStarted(boolean on) {
        this.started    = on;
    }
    
    public boolean isStarted() {
        return this.started;
    }
    
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append( this.adapterName ).append( " [Adapter의 등록정보입니다. : " );
        sb.append("adapter.group.name=").append( this.adapterGroupName );
        sb.append(", bound.usage=").append( this.boundUsage );
        sb.append(", socket.type=").append( this.socketType );
        sb.append(", host.name=").append( this.hostName );
        sb.append(", port.number=").append( this.portNumber);
        sb.append(", local.host.name=").append( this.localHostName );
        sb.append(", local.port.number=").append( this.localPortNumber );
        if ( this.connLimitPerIp > 0 ) {
            sb.append(", connection.limit.per.ip=").append( this.connLimitPerIp );
        } else {
            sb.append(", connection.limit.per.ip=0(UNLIMITED)" );
        }
        
        if ( this.maxConnection > 0 ) {
            sb.append(", max.connection=").append( this.maxConnection );
        } else {
            sb.append(", max.connection=0 (UNLIMITED)" );
        }
        
        sb.append(", max.thread=").append( this.maxThread );
        sb.append(", timeout=").append( this.timeout );
        sb.append(", response.type=").append( this.responseType );
        sb.append(", socket.reuse=").append( this.socketReuse );
        sb.append(", ll.field.type=").append( this.llFieldType );
        sb.append(", ll.field.offset=").append( this.llFieldOffset );
        sb.append(", ll.field.length=").append( this.llFieldLength );
        sb.append(", ll.field.include=").append( this.llFieldInclude );
        sb.append(", ll.include=").append( this.llInclude );
        sb.append(", variable.head.length=").append( this.sendHeaderLength );
        sb.append(", payload.length=").append( this.sendPayloadLength );
        sb.append(", ack.support=").append( this.ackSupport );
        sb.append(", business.work.class.code=").append( this.bwkClsCd );
        
        sb.append(", trace.level=");
        if ( this.traceLevel == 2 ) {
            sb.append( this.traceLevel ).append("(DEBUG)");
        } else if ( this.traceLevel == 1 ) {
        	sb.append( this.traceLevel ).append("(INFO)");
        } else {
        	sb.append( this.traceLevel ).append("(ERROR)");
        }
        
        sb.append(", description=").append(this.description);
        
    	if ("XECURE".equals(this.protocol)) {
        	sb.append(", xecure.type=").append(this.xecureType);
        	//sb.append(", xecure.tmode=").append(this.xecureTmode);
        	//sb.append(", xecure.encode.mode=").append(this.xecureEncodeMode);
        	sb.append(", xecure.config.path=").append(this.xecureConfigPath);
        	sb.append(", xecure.password=").append(this.xecurePassword);
    	}
    	
    	if ("XECURE2".equals(this.protocol)) {
    		sb.append(", xecure2.config.path=").append(this.xecure2ConfigPath);
    		sb.append(", xecure2.sm.ip=").append(this.xecure2SmIp);
    		sb.append(", xecure2.sm.port=").append( String.valueOf(this.xecure2SmPort) );
    	}
        
        sb.append("]");
        
        return sb.toString();
    }
    
    /**
     * SMS
     */
	public String getSmsRunningTime() {
		return smsRunningTime;
	}

	public void setSmsRunningTime(String smsRunningTime) {
		this.smsRunningTime = smsRunningTime;
	}

	/**
	 * xecure protocol related
	 */
	public String getXecureType() {
		return xecureType;
	}

	public void setXecureType(String xecureType) {
		this.xecureType = xecureType;
	}
	
	public String getXecureConfigPath() {
		return xecureConfigPath;
	}

	public void setXecureConfigPath(String xecureConfigPath) {
		this.xecureConfigPath = xecureConfigPath;
	}

	public String getXecureRemoteCert() {
		return xecureRemoteCert;
	}

	public void setXecureRemoteCert(String xecureRemoteCert) {
		this.xecureRemoteCert = xecureRemoteCert;
	}

	/**
	 * xecure2 protocol related
	 */
	public String getXecure2ConfigPath() {
		return xecure2ConfigPath;
	}
	
	public void setXecure2ConfigPath(String xecure2ConfigPath) {
		this.xecure2ConfigPath = xecure2ConfigPath;
	}

	public String getXecure2SmIp() {
		return xecure2SmIp;
	}
	
	public void setXecure2SmIp(String xecure2SmIp) {
		this.xecure2SmIp = xecure2SmIp;
	}
	
	public int getXecure2SmPort() {
		return xecure2SmPort;
	}
	
	public void setXecure2SmPort(int xecure2SmPort) {
		this.xecure2SmPort = xecure2SmPort;
	}
	
	/**
	 * xecure2 Envelop protocol related
	 */
	public String getEnvelopPassword() {
		return envelopPassword;
	}

	public void setEnvelopPassword(String envelopPassword) {
		this.envelopPassword = envelopPassword;
	}

	public String getEnvelopSigncertPath() {
		return envelopSigncertPath;
	}

	public void setEnvelopSigncertPath(String envelopSigncertPath) {
		this.envelopSigncertPath = envelopSigncertPath;
	}

	public String getEnvelopSignkeyPath() {
		return envelopSignkeyPath;
	}

	public void setEnvelopSignkeyPath(String envelopSignkeyPath) {
		this.envelopSignkeyPath = envelopSignkeyPath;
	}

	/**
	 * xecure3 protocol related 20100901 JGY
	 */
	public String getXecure3CertStore() {
		return xecure3CertStore;
	}

	public void setXecure3CertStore(String xecure3CertStore) {
		this.xecure3CertStore = xecure3CertStore;
	}
	
	public String getXecure3ServerCert() {
		return xecure3ServerCert;
	}

	public void setXecure3ServerCert(String xecure3ServerCert) {
		this.xecure3ServerCert = xecure3ServerCert;
	}
	
	public String getXecure3ClientCert() {
		return xecure3ClientCert;
	}

	public void setXecure3ClientCert(String xecure3ClientCert) {
		this.xecure3ClientCert = xecure3ClientCert;
	}
	
	public String getXecure3CertKey() {
		return xecure3CertKey;
	}

	public void setXecure3CertKey(String xecure3CertKey) {
		this.xecure3CertKey = xecure3CertKey;
	}
	
	public String getXecure3CertPassword() {
		return xecure3CertPassword;
	}

	public void setXecure3CertPassword(String xecure3CertPassword) {
		this.xecure3CertPassword = xecure3CertPassword;
	}
	/**
	 * xecureconnect3 epb
	 */
	public String getXc3epbPassword() {
		return xc3epbPassword;
	}

	public void setXc3epbPassword(String xc3epbPassword) {
		this.xc3epbPassword = xc3epbPassword;
	}

	public String getXc3epbConfigPath() {
		return xc3epbConfigPath;
	}

	public void setXc3epbConfigPath(String xc3epbConfigPath) {
		this.xc3epbConfigPath = xc3epbConfigPath;
	}	

	/**
	 * inisafe_payload protocol related 20100515 JGY
	 */
	public String getInisafeIdPassword() {
		return inisafeIdPassword;
	}

	public void setInisafeIdPassword(String inisafeIdPassword) {
		this.inisafeIdPassword = inisafeIdPassword;
	}

	/**
	 * TCSEED protocol related 20101213 JGY
	 */
	public String getTcseedKeyStore() {
		return tcseedKeyStore;
	}

	public void setTcseedKeyStore(String tcseedKeyStore) {
		this.tcseedKeyStore = tcseedKeyStore;
	}
	
	/**
	 * variable header protocol related 20121030 KwonSeHwan
	 */

	public int getRecvHeaderLength() {
		return recvHeaderLength;
	}

	public void setRecvHeaderLength(int recvHeaderLength) {
		this.recvHeaderLength = recvHeaderLength;
	}

	public int getSendHeaderLength() {
		return sendHeaderLength;
	}

	public void setSendHeaderLength(int sendHeaderLength) {
		this.sendHeaderLength = sendHeaderLength;
	}

	public String getSingleSession() {
		return singleSession;
	}

	public void setSingleSession(String singleSession) {
		this.singleSession = singleSession;
	}

	public String getBlockIpList() {
		return blockIpList;
	}

	public void setBlockIpList(String blockIpList) {
		this.blockIpList = blockIpList;
	}

	public String getL4SkipIpList() {
		return l4SkipIpList;
	}

	public void setL4SkipIpList(String l4SkipIpList) {
		this.l4SkipIpList = l4SkipIpList;
	}

	public String getDelimiter() {
		return delimiter;
	}

	public void setDelimiter(String delimiter) {
		this.delimiter = delimiter;
	}

	public String getLoginSend() {
		return loginSend;
	}

	public void setLoginSend(String loginSend) {
		this.loginSend = loginSend;
	}

	public String getLoginRecv() {
		return loginRecv;
	}

	public void setLoginRecv(String loginRecv) {
		this.loginRecv = loginRecv;
	}

	public String getBindType() {
		return bindType;
	}

	public void setBindType(String bindType) {
		this.bindType = bindType;
	}

	public int getLlFieldLengthAlpha() {
		return llFieldLengthAlpha;
	}

	public void setLlFieldLengthAlpha(int llFieldLengthAlpha) {
		this.llFieldLengthAlpha = llFieldLengthAlpha;
	}

	public String getInicisKeyPath() {
		return inicisKeyPath;
	}

	public void setInicisKeyPath(String inicisKeyPath) {
		this.inicisKeyPath = inicisKeyPath;
	}

	public String getInicisKeyPass() {
		return inicisKeyPass;
	}

	public void setInicisKeyPass(String inicisKeyPass) {
		this.inicisKeyPass = inicisKeyPass;
	}

	public String getAppendHead() {
		return appendHead;
	}

	public void setAppendHead(String appendHead) {
		this.appendHead = appendHead;
	}

	public String getAppendTail() {
		return appendTail;
	}

	public void setAppendTail(String appendTail) {
		this.appendTail = appendTail;
	}
	
	public String getDataControlRule() {
		return dataControlRule;
	}

	public void setDataControlRule(String dataControlRule) {
		this.dataControlRule = dataControlRule;
	}
	
	// for 싱글어댑터 
	public String getPrimaryInstId() {
		return primaryInstId;
	}

	// for 싱글어댑터	
	public void setPrimaryInstId(String primaryInstId) {
		this.primaryInstId = primaryInstId;
	}

	public String getDynamicOffsetPattern() {
		return dynamicOffsetPattern;
	}

	public void setDynamicOffsetPattern(String dynamicOffsetPattern) {
		this.dynamicOffsetPattern = dynamicOffsetPattern;
	}

	public String getDataAddRule() {
		return dataAddRule;
	}

	public void setDataAddRule(String dataAddRule) {
		this.dataAddRule = dataAddRule;
	}

	public String getDataRemoveRule() {
		return dataRemoveRule;
	}

	public void setDataRemoveRule(String dataRemoveRule) {
		this.dataRemoveRule = dataRemoveRule;
	}

	public void setKeepAlive(String keepAlive) {
		this.keepAlive = keepAlive;
	}

	public String getKeepAlive() {
		return keepAlive;
	}
	
	public boolean isKeepAlive() {
		return "Y".equals(keepAlive);
	}	
}
