package com.nms.server.thread.socket;

import org.apache.log4j.Logger;

import com.nms.server.common.Common;
import com.nms.server.common.Constants;
import com.nms.server.util.socket.SSLSocketCallable;


/**
 * 安全通讯的客户端
 */

public class SSLClient extends SSLSocketCallable {
	private static Logger logger = Logger.getLogger(SSLClient.class);
	private String cmd  = null;

	public static final String RELEASE_DETECT = "char:releaseDetect";


	
	public SSLClient(String ip,int port,String cmd){
		super(ip, port);
		this.cmd = cmd;
	}
	
	public SSLClient(String ip, int port)throws Exception {
		super(ip, port);
	}

	@Override
	protected Object toDo() throws Exception {
		Thread.currentThread().setName("通信线程 TO:>"+ip);
		logger.debug("通讯命令:>"+cmd);
		if(RELEASE_DETECT.equalsIgnoreCase(cmd)){
			/**
			 * 通知 web 监测数据入库完成
			 */
			sendMessage(cmd);
			String msg = receiveMessage();
			logger.debug(RELEASE_DETECT + " -> " + msg);
		}
		return null;
	}
	
	/**
	 * 向web 发送 释放 监测数据锁
	 * @param ip
	 * @param port
	 */
	public static void sengReleaseDetect() {
		try {
			Common.service.submit(new SSLClient(Constants.WEB_SOCKET_IP, Constants.WEB_SOCKET_PORT, RELEASE_DETECT));
		} catch (Exception e) {
			logger.error("",e);
		}
	}
	
	public static void main(String [] args){

	}
}