This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nms-nmsserver/src/com/nms/server/util/socket/SSLSocketCallable.java
fangshunjian e0737f8a42 1、修复dc数据库连接没有释放的bug
2、socket server 添加连接client限制,防止同时多个client连接导致dc程序不能正常运行的问题
2018-11-21 13:26:37 +08:00

103 lines
2.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.nms.server.util.socket;
import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;
import java.util.Calendar;
import java.util.concurrent.Callable;
import javax.net.ssl.SSLServerSocket;
import org.apache.log4j.Logger;
import com.nms.server.common.Common;
import com.nms.server.common.Constants;
/**
* SSL 通讯 工具类
* @date Feb 29, 2012 10:05:50 AM
* @author ZhangGang
*
*/
public abstract class SSLSocketCallable extends SocketUtils implements Callable<Object>{
private static Logger logger = Logger.getLogger(SSLSocketCallable.class);
//ServerSocket 通讯服务
protected SSLServerSocket ss = null;
private boolean clientFlag = false;// 是否dc server 接收的client
/**
* 通讯创建
* @param ip 目标主机IP
* @param port 目标主机端口
* @throws Exception
*/
public SSLSocketCallable(String ip,Integer port){
super(ip, port);
}
/**
* 通讯创建
* @param client 目标通讯实例
*/
public SSLSocketCallable(Socket client) {
super(client);
clientFlag = true;
}
/**
* 通讯线程执行方法 默认格式
* @return
* @throws Exception
*/
public Object call(){
Thread.currentThread().setName("Create communication"+ip+":"+port);
Object obj = null; //返回对象
try {
try {
//- 校验 是否创建新通讯连接
if(socket==null){ //客户端通讯创建
createClientSocket();
}else{ //服务端通讯创建
createServerSocket();
}
} catch (SocketException e) {
logger.error("Create failed"+e.getMessage(),e);
Common.addErrorInfo(Constants.ERROR_CODE_CREATE_SOCKET,ip, Calendar.getInstance().getTime(), Constants.ERROR_INFO_SATAE_ERROR,"");
close();
return obj;
} catch (Exception e) {
close();
return obj;
}
//-- 自定义通讯操作
try {
obj = toDo();
}catch (Exception e) {
logger.error("Communicate contents exception"+e.getMessage(),e);
Common.addErrorInfo(Constants.ERROR_CODE_SOCKET_RUNTIME,ip, Calendar.getInstance().getTime(), Constants.ERROR_INFO_SATAE_ERROR,"");
} finally {
close();
}
} finally {
if(clientFlag){
Common.releaseServerSemaphore();//释放server信号量
}
}
return obj;
}
/**
* 待实现的通信操作
* @time Aug 28, 2011-9:04:46 PM
* @param outl
* @param inl
* @throws Exception
*/
protected abstract Object toDo()throws Exception;
}