package com.eactive.eai.adapter.socket2.app.echo;

import com.eactive.eai.adapter.socket2.config.SocketAdapterContext;
import com.eactive.eai.adapter.socket2.config.SocketAdapterFactory;
import com.eactive.eai.adapter.socket2.config.SocketAdapterManager;
import com.eactive.eai.adapter.socket2.protocol.ISocketAdapter;

public class EchoServer {
	static public void main(String[] args) throws Exception {		
		/**
		 * Xecure Server - [1] BASIC
		 */
		SocketAdapterContext context = new SocketAdapterContext();
		context.setProtocol("XECURE");
		context.setAdapterGroupName("XecureServerAdapterGroup");
		context.setAdapterName("XecureBasicServerAdapter");
		context.setBoundUsage("IOBOUND");
		context.setSocketType("SERVER");
		context.setHostName("localhost");
		context.setPortNumber(9901);
		context.setResponseType("SYNC");
		context.setTimeout(10);
		context.setMaxConnection(10);
		context.setTraceLevel(context.TRACE_LEVEL_DEBUG);
		context.setPermanent("N");
		
		context.setXecureType("BASIC");
		//context.setXecureTmode("10");
		//context.setXecureEncodeMode("BASE64");
		//context.setXecurePassword("qwer1234");
		context.setXecureConfigPath("modules/xecure/windows/conf/xc_conf.txt");

		ISocketAdapter adapter = SocketAdapterFactory.createSocketAdapter(context);
		adapter.start().join();

		
		/**
		 * process command
		 */
		processCommand();
	}
	
    private static void processCommand() {
        while(true) {
            try {
            	System.out.print("> ");
            	String cmd = (new java.io.BufferedReader(new java.io.InputStreamReader(System.in))).readLine();
            	if ("".equals(cmd)) {
            		// System.out.println(SocketAdapterManager.getInstance());
            	} else if ("exit".equals(cmd)) {
            		System.exit(1);
            	}
            } catch(Exception e) {
                // System.out.println("processCommand errpr "+ e.toString());
            }
        }
	}	
}
