Changes
This commit is contained in:
parent
8532ad12b1
commit
dd7bd5577a
@ -1,7 +1,7 @@
|
|||||||
package com.sunyard.sge.database;
|
package com.sunyard.sge.database;
|
||||||
|
|
||||||
import com.sunyard.sge.log.LogFactory;
|
import com.sunyard.sge.log.LogFactory;
|
||||||
import org.slf4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import racal.sunyard.main.SydApi4j;
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -26,9 +26,17 @@ public interface SydApi {
|
|||||||
static void SYD_SetLogConfig(
|
static void SYD_SetLogConfig(
|
||||||
String pcLogPath,
|
String pcLogPath,
|
||||||
int iLogLevel) {
|
int iLogLevel) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
Logger logger = LogFactory.createLogger(pcLogPath, iLogLevel);
|
try {
|
||||||
SydApi4j.setLogger( logger );
|
if (iLogLevel<0||iLogLevel>3){
|
||||||
|
throw new IllegalArgumentException("IllegalArgumentException");
|
||||||
|
}
|
||||||
|
Logger logger = LogFactory.createLogger(pcLogPath, iLogLevel);
|
||||||
|
SydApi4j.setLogger( logger );
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException e){
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -280,8 +288,4 @@ public interface SydApi {
|
|||||||
byte[] pcData,
|
byte[] pcData,
|
||||||
String pcMac
|
String pcMac
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,16 +2,19 @@ package com.sunyard.sge.database;
|
|||||||
|
|
||||||
import com.sunyard.SydApiException;
|
import com.sunyard.SydApiException;
|
||||||
import com.sunyard.proto.Util;
|
import com.sunyard.proto.Util;
|
||||||
|
import com.sunyard.sge.log.LogFactory;
|
||||||
import com.sunyard.util.SYMUtil;
|
import com.sunyard.util.SYMUtil;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import racal.sunyard.main.SydApi4j;
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上海黄金交易所 - 数据库加密方案
|
* 上海黄金交易所 - 数据库加密方案
|
||||||
*/
|
*/
|
||||||
public class SydApi4Database implements SydApi {
|
public class SydApi4Database implements SydApi {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
private SydApi4j[] hsms = null;
|
private SydApi4j[] hsms = null;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -24,6 +27,9 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SydApi SYD_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut) {
|
public SydApi SYD_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut) {
|
||||||
|
if (LogFactory.iLogLevel==3) {
|
||||||
|
log.debug("SYD_Connect_Ex方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList), Arrays.toString(iPortList), iConnectTimeOut, iDealTimeOut);
|
||||||
|
}
|
||||||
SydApi4j api = (SydApi4j) new SydApi4j().connect(pcIpList[0], iPortList[0], null, iConnectTimeOut);
|
SydApi4j api = (SydApi4j) new SydApi4j().connect(pcIpList[0], iPortList[0], null, iConnectTimeOut);
|
||||||
hsms = new SydApi4j[]{ api };
|
hsms = new SydApi4j[]{ api };
|
||||||
return this;
|
return this;
|
||||||
@ -43,6 +49,9 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String SYD_SM3_Hash_ShortData(byte[] pcData) {
|
public String SYD_SM3_Hash_ShortData(byte[] pcData) {
|
||||||
|
if (LogFactory.iLogLevel==3) {
|
||||||
|
log.debug("SYD_SM3_Hash_ShortData方法接收参数:pcData:{}", Arrays.toString(pcData));
|
||||||
|
}
|
||||||
if (null == this.hsms || this.hsms.length < 1) {
|
if (null == this.hsms || this.hsms.length < 1) {
|
||||||
throw new SydApiException(-1);
|
throw new SydApiException(-1);
|
||||||
}
|
}
|
||||||
@ -51,6 +60,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
for (SydApi4j api : this.hsms) {
|
for (SydApi4j api : this.hsms) {
|
||||||
try {
|
try {
|
||||||
byte[] hash = api.SYD_SM3_LongData(pcData, null, 0);
|
byte[] hash = api.SYD_SM3_LongData(pcData, null, 0);
|
||||||
|
log.debug("api.SYD_SM3_LongData方法返回值:{}",Arrays.toString(hash));
|
||||||
return Util.bytes2HexString(hash);
|
return Util.bytes2HexString(hash);
|
||||||
} catch (SydApiException e) {
|
} catch (SydApiException e) {
|
||||||
le = e;
|
le = e;
|
||||||
@ -65,6 +75,9 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LongDataReturn<String, String> SYD_SM3_Hash_LongData(byte[] pcData, int iPkgNum, String pcProcData) {
|
public LongDataReturn<String, String> SYD_SM3_Hash_LongData(byte[] pcData, int iPkgNum, String pcProcData) {
|
||||||
|
if (LogFactory.iLogLevel==3) {
|
||||||
|
log.debug("SYD_SM3_Hash_LongData方法接收参数:pcData:{},iPkgNum:{},pcProcData:{}", Arrays.toString(pcData), iPkgNum, pcProcData);
|
||||||
|
}
|
||||||
if (null == this.hsms || this.hsms.length < 1) {
|
if (null == this.hsms || this.hsms.length < 1) {
|
||||||
throw new SydApiException(-1);
|
throw new SydApiException(-1);
|
||||||
}
|
}
|
||||||
@ -72,12 +85,14 @@ public class SydApi4Database implements SydApi {
|
|||||||
byte[] procData = null;
|
byte[] procData = null;
|
||||||
if (2 == iPkgNum || 3 == iPkgNum) {
|
if (2 == iPkgNum || 3 == iPkgNum) {
|
||||||
procData = Util.hexString2Bytes(pcProcData);
|
procData = Util.hexString2Bytes(pcProcData);
|
||||||
|
log.debug("Util.hexString2Bytes方法返回值:{}",Arrays.toString(procData));
|
||||||
|
|
||||||
}
|
}
|
||||||
SydApiException le = null;
|
SydApiException le = null;
|
||||||
for (SydApi4j api : this.hsms) {
|
for (SydApi4j api : this.hsms) {
|
||||||
try {
|
try {
|
||||||
byte[] hash = api.SYD_SM3_LongData(pcData, procData, iPkgNum);
|
byte[] hash = api.SYD_SM3_LongData(pcData, procData, iPkgNum);
|
||||||
|
log.debug("api.SYD_SM3_LongData方法返回值:{}",Arrays.toString(hash));
|
||||||
if (0 == iPkgNum || 3 == iPkgNum) {
|
if (0 == iPkgNum || 3 == iPkgNum) {
|
||||||
return new LongDataReturn<String, String>(null, Util.bytes2HexString(hash));
|
return new LongDataReturn<String, String>(null, Util.bytes2HexString(hash));
|
||||||
} else {
|
} else {
|
||||||
@ -96,7 +111,9 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] SYD_SM4_ShortData(int iKeyIndex, byte[] pcData, int iFlag) {
|
public byte[] SYD_SM4_ShortData(int iKeyIndex, byte[] pcData, int iFlag) {
|
||||||
|
if (LogFactory.iLogLevel==3) {
|
||||||
|
log.debug("SYD_SM4_ShortData方法接收参数:iKeyIndex:{},pcData:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData), iFlag);
|
||||||
|
}
|
||||||
if (null == this.hsms || this.hsms.length < 1) {
|
if (null == this.hsms || this.hsms.length < 1) {
|
||||||
throw new SydApiException(-1);
|
throw new SydApiException(-1);
|
||||||
}
|
}
|
||||||
@ -132,6 +149,9 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<byte[]> SYD_SM4_BatchData(int[] iKeyIndex, List<byte[]> pcData, int iFlag) {
|
public List<byte[]> SYD_SM4_BatchData(int[] iKeyIndex, List<byte[]> pcData, int iFlag) {
|
||||||
|
if (LogFactory.iLogLevel==3) {
|
||||||
|
log.debug("SYD_SM4_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},iFlag:{}", iKeyIndex, pcData.size(), iFlag);
|
||||||
|
}
|
||||||
if (null == this.hsms || this.hsms.length < 1) {
|
if (null == this.hsms || this.hsms.length < 1) {
|
||||||
throw new SydApiException(-1);
|
throw new SydApiException(-1);
|
||||||
}
|
}
|
||||||
@ -146,6 +166,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
try {
|
try {
|
||||||
if (Consts.ECB_ENC == iFlag) {
|
if (Consts.ECB_ENC == iFlag) {
|
||||||
return api.SYMEncryptDecryptBatchData(8, 1, null, keys, 1, pcData);
|
return api.SYMEncryptDecryptBatchData(8, 1, null, keys, 1, pcData);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return api.SYMEncryptDecryptBatchData(9, 1, null, keys, 1, pcData);
|
return api.SYMEncryptDecryptBatchData(9, 1, null, keys, 1, pcData);
|
||||||
}
|
}
|
||||||
@ -162,6 +183,9 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] SYD_SM4_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, int iFlag) {
|
public byte[] SYD_SM4_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, int iFlag) {
|
||||||
|
if (LogFactory.iLogLevel==3) {
|
||||||
|
log.debug("SYD_SM4_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, iFlag);
|
||||||
|
}
|
||||||
if (null == this.hsms || this.hsms.length < 1) {
|
if (null == this.hsms || this.hsms.length < 1) {
|
||||||
throw new SydApiException(-1);
|
throw new SydApiException(-1);
|
||||||
}
|
}
|
||||||
@ -200,6 +224,9 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData) {
|
public String[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData) {
|
||||||
|
if (LogFactory.iLogLevel==3) {
|
||||||
|
log.debug("SYD_SM4Mac_BatchData:iKeyIndex:{},pcData元素个数为:{}", iKeyIndex, pcData.size());
|
||||||
|
}
|
||||||
if (null == this.hsms || this.hsms.length < 1) {
|
if (null == this.hsms || this.hsms.length < 1) {
|
||||||
throw new SydApiException(-1);
|
throw new SydApiException(-1);
|
||||||
}
|
}
|
||||||
@ -234,6 +261,9 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData, String[] pcMac) {
|
public boolean[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData, String[] pcMac) {
|
||||||
|
if (LogFactory.iLogLevel==3) {
|
||||||
|
log.debug("SYD_SM4Mac_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},pcMac:{}", iKeyIndex, pcData.size(), Arrays.toString(pcMac));
|
||||||
|
}
|
||||||
if (null == this.hsms || this.hsms.length < 1) {
|
if (null == this.hsms || this.hsms.length < 1) {
|
||||||
throw new SydApiException(-1);
|
throw new SydApiException(-1);
|
||||||
}
|
}
|
||||||
@ -245,7 +275,6 @@ public class SydApi4Database implements SydApi {
|
|||||||
SydApiException le = null;
|
SydApiException le = null;
|
||||||
for (SydApi4j api : this.hsms) {
|
for (SydApi4j api : this.hsms) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
List<byte[]> list = api.SYMEncryptDecryptBatchData(8, 2, null, keys, 1, pcData);
|
List<byte[]> list = api.SYMEncryptDecryptBatchData(8, 2, null, keys, 1, pcData);
|
||||||
boolean[] ret = new boolean[list.size()];
|
boolean[] ret = new boolean[list.size()];
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
@ -269,6 +298,9 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LongDataReturn<String, String> SYD_SM4Mac_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, String pcProcData) {
|
public LongDataReturn<String, String> SYD_SM4Mac_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, String pcProcData) {
|
||||||
|
if (LogFactory.iLogLevel==3) {
|
||||||
|
log.debug("SYD_SM4Mac_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},pcProcData:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, pcProcData);
|
||||||
|
}
|
||||||
if (null == this.hsms || this.hsms.length < 1) {
|
if (null == this.hsms || this.hsms.length < 1) {
|
||||||
throw new SydApiException(-1);
|
throw new SydApiException(-1);
|
||||||
}
|
}
|
||||||
@ -316,7 +348,9 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LongDataReturn<String, Boolean> SYD_SM4Mac_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, String pcProcData, String pcMac) {
|
public LongDataReturn<String, Boolean> SYD_SM4Mac_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, String pcProcData, String pcMac) {
|
||||||
|
if (LogFactory.iLogLevel==3) {
|
||||||
|
log.debug("SYD_SM4Mac_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},pcProcData:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, pcProcData, pcMac);
|
||||||
|
}
|
||||||
LongDataReturn<String, String> ret = SYD_SM4Mac_LongData(iKeyIndex, pcData, iPkgNum, pcProcData);
|
LongDataReturn<String, String> ret = SYD_SM4Mac_LongData(iKeyIndex, pcData, iPkgNum, pcProcData);
|
||||||
|
|
||||||
// 仅一包 和 尾包 返回最终结果
|
// 仅一包 和 尾包 返回最终结果
|
||||||
@ -330,13 +364,15 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData) {
|
public String SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData) {
|
||||||
|
if (LogFactory.iLogLevel==3) {
|
||||||
|
log.debug("SYD_SM4Mac_ShortData方法接收参数:iKeyIndex:{},pcData:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData));
|
||||||
|
}
|
||||||
if (null == this.hsms || this.hsms.length < 1) {
|
if (null == this.hsms || this.hsms.length < 1) {
|
||||||
throw new SydApiException(-1);
|
throw new SydApiException(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String keyIndex = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex));
|
String keyIndex = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex));
|
||||||
|
log.debug("\"SK\" + SYMUtil.genPrivateKeyMark方法返回值:{}",keyIndex);
|
||||||
SydApiException le = null;
|
SydApiException le = null;
|
||||||
for (SydApi4j api : this.hsms) {
|
for (SydApi4j api : this.hsms) {
|
||||||
try {
|
try {
|
||||||
@ -356,6 +392,9 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData, String pcMac) {
|
public boolean SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData, String pcMac) {
|
||||||
|
if (LogFactory.iLogLevel==3) {
|
||||||
|
log.debug("SYD_SM4Mac_ShortData方法接收参数:{}", iKeyIndex, Arrays.toString(pcData), pcMac);
|
||||||
|
}
|
||||||
if (null == this.hsms || this.hsms.length < 1) {
|
if (null == this.hsms || this.hsms.length < 1) {
|
||||||
throw new SydApiException(-1);
|
throw new SydApiException(-1);
|
||||||
}
|
}
|
||||||
@ -365,7 +404,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String mac = this.SYD_SM4Mac_ShortData(iKeyIndex, pcData);
|
String mac = this.SYD_SM4Mac_ShortData(iKeyIndex, pcData);
|
||||||
|
log.debug(this+".SYD_SM4Mac_ShortData方法返回值:{}",mac);
|
||||||
return pcMac.equals(mac);
|
return pcMac.equals(mac);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,25 +3,24 @@ package com.sunyard.sge.database;
|
|||||||
import com.sunyard.sge.database.pool.HsmLinkInfo;
|
import com.sunyard.sge.database.pool.HsmLinkInfo;
|
||||||
import com.sunyard.sge.database.pool.SydApiPool;
|
import com.sunyard.sge.database.pool.SydApiPool;
|
||||||
import com.sunyard.sge.log.LogFactory;
|
import com.sunyard.sge.log.LogFactory;
|
||||||
import org.slf4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class SydApiBuilder {
|
public class SydApiBuilder {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
private SydApiPool pool;
|
private SydApiPool pool;
|
||||||
|
|
||||||
public SydApiBuilder(
|
public SydApiBuilder(
|
||||||
String[] pcIpList,
|
String[] pcIpList,
|
||||||
int[] iPortList,
|
int[] iPortList,
|
||||||
int iConnectTimeOut,
|
int iConnectTimeOut,
|
||||||
int iDealTimeOut
|
int iDealTimeOut
|
||||||
) {
|
) {
|
||||||
Logger log = LogFactory.getLogger();
|
|
||||||
log.debug("创建链接");
|
log.debug("创建链接");
|
||||||
|
log.debug("SydApiBuilder构造方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList),Arrays.toString(iPortList),iConnectTimeOut,iDealTimeOut);
|
||||||
HsmLinkInfo[] linkInfo = HsmLinkInfo.mutiHsmLinkInfo(pcIpList, iPortList, iConnectTimeOut, iDealTimeOut);
|
HsmLinkInfo[] linkInfo = HsmLinkInfo.mutiHsmLinkInfo(pcIpList, iPortList, iConnectTimeOut, iDealTimeOut);
|
||||||
|
log.debug("mutiHsmLinkInfo方法返回值:linkInfo:{}",linkInfo);
|
||||||
this.pool = new SydApiPool(linkInfo);
|
this.pool = new SydApiPool(linkInfo);
|
||||||
|
|
||||||
warmUp( pcIpList, iPortList, iConnectTimeOut, iDealTimeOut );
|
warmUp( pcIpList, iPortList, iConnectTimeOut, iDealTimeOut );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,13 +2,15 @@ package com.sunyard.sge.database.pool;
|
|||||||
|
|
||||||
|
|
||||||
import com.sunyard.sge.log.LogFactory;
|
import com.sunyard.sge.log.LogFactory;
|
||||||
import org.slf4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 到加密机的链接信息
|
* 到加密机的链接信息
|
||||||
*/
|
*/
|
||||||
public class HsmLinkInfo {
|
public class HsmLinkInfo {
|
||||||
|
|
||||||
private String pcIp;
|
private String pcIp;
|
||||||
private int iPort;
|
private int iPort;
|
||||||
private int iConnectTimeOut;
|
private int iConnectTimeOut;
|
||||||
@ -24,8 +26,8 @@ public class HsmLinkInfo {
|
|||||||
|
|
||||||
public static HsmLinkInfo[] mutiHsmLinkInfo(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iAllDealTimeOut) {
|
public static HsmLinkInfo[] mutiHsmLinkInfo(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iAllDealTimeOut) {
|
||||||
Logger log = LogFactory.getLogger();
|
Logger log = LogFactory.getLogger();
|
||||||
|
log.debug("mutiHsmLinkInfo方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList),Arrays.toString(iPortList),iConnectTimeOut,iAllDealTimeOut);
|
||||||
log.debug("链接参数整理");
|
log.debug("链接参数整理");
|
||||||
|
|
||||||
if (null == pcIpList &&
|
if (null == pcIpList &&
|
||||||
null == iPortList &&
|
null == iPortList &&
|
||||||
pcIpList.length != iPortList.length) {
|
pcIpList.length != iPortList.length) {
|
||||||
@ -66,4 +68,14 @@ public class HsmLinkInfo {
|
|||||||
public int getiDealTimeOut() {
|
public int getiDealTimeOut() {
|
||||||
return iDealTimeOut;
|
return iDealTimeOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "HsmLinkInfo{" +
|
||||||
|
"pcIp='" + pcIp + '\'' +
|
||||||
|
", iPort=" + iPort +
|
||||||
|
", iConnectTimeOut=" + iConnectTimeOut +
|
||||||
|
", iDealTimeOut=" + iDealTimeOut +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,8 +13,7 @@ import org.apache.logging.log4j.core.config.AppenderRef;
|
|||||||
import org.apache.logging.log4j.core.config.Configuration;
|
import org.apache.logging.log4j.core.config.Configuration;
|
||||||
import org.apache.logging.log4j.core.config.LoggerConfig;
|
import org.apache.logging.log4j.core.config.LoggerConfig;
|
||||||
import org.apache.logging.log4j.core.layout.PatternLayout;
|
import org.apache.logging.log4j.core.layout.PatternLayout;
|
||||||
import org.slf4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -49,7 +48,7 @@ public class LogFactory {
|
|||||||
|
|
||||||
// 创建一个展示的样式
|
// 创建一个展示的样式
|
||||||
Layout layout = PatternLayout.createLayout(
|
Layout layout = PatternLayout.createLayout(
|
||||||
"[%level{DEBUG=3, INFO=2, ERROR=1, OFF=0}: %d{ISO8601} <%thread>] %message%n%throwable%n",
|
"[%level{DEBUG=3, INFO=2, ERROR=1, OFF=0}: %d{ISO8601} <%thread>] %message%n%throwable",
|
||||||
null,
|
null,
|
||||||
config, null, null, true, false, null, null);
|
config, null, null, true, false, null, null);
|
||||||
|
|
||||||
@ -101,7 +100,8 @@ public class LogFactory {
|
|||||||
LogFactory.pcLogPath = pcLogPath;
|
LogFactory.pcLogPath = pcLogPath;
|
||||||
LogFactory.iLogLevel = iLogLevel;
|
LogFactory.iLogLevel = iLogLevel;
|
||||||
start();
|
start();
|
||||||
return LoggerFactory.getLogger( logName );
|
return LogManager.getLogger(logName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,6 +109,8 @@ public class LogFactory {
|
|||||||
* @return Logger
|
* @return Logger
|
||||||
*/
|
*/
|
||||||
public static Logger getLogger() {
|
public static Logger getLogger() {
|
||||||
return LoggerFactory.getLogger( logName );
|
return LogManager.getLogger(logName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
package com.sunyard.sge.pool;
|
package com.sunyard.sge.pool;
|
||||||
|
|
||||||
import com.sunyard.sge.log.LogFactory;
|
import com.sunyard.sge.log.LogFactory;
|
||||||
import org.slf4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -12,6 +13,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
public class ThreadBasedConnectPool<T> {
|
public class ThreadBasedConnectPool<T> {
|
||||||
|
|
||||||
|
|
||||||
// ThreadLocal
|
// ThreadLocal
|
||||||
private final Map<Thread, ObjectInPool<T>> map = new HashMap<>();
|
private final Map<Thread, ObjectInPool<T>> map = new HashMap<>();
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,8 @@ import com.sunyard.proto.Util;
|
|||||||
import com.sunyard.sge.database.*;
|
import com.sunyard.sge.database.*;
|
||||||
import com.sunyard.sge.database.Consts;
|
import com.sunyard.sge.database.Consts;
|
||||||
import com.sunyard.sge.log.LogFactory;
|
import com.sunyard.sge.log.LogFactory;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -16,7 +16,7 @@ public class Sample
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
// 路径要以 / 或 \\ 结尾表示目录
|
// 路径要以 / 或 \\ 结尾表示目录
|
||||||
SydApi.SYD_SetLogConfig("./logs/", Consts.LogLevelDebug );
|
SydApi.SYD_SetLogConfig("./logs/",2);
|
||||||
|
|
||||||
Logger log = LogFactory.getLogger();
|
Logger log = LogFactory.getLogger();
|
||||||
log.info("start");
|
log.info("start");
|
||||||
|
|||||||
@ -2,18 +2,29 @@ package test;
|
|||||||
|
|
||||||
import com.sunyard.sge.database.SydApi;
|
import com.sunyard.sge.database.SydApi;
|
||||||
import com.sunyard.sge.database.SydApiBuilder;
|
import com.sunyard.sge.database.SydApiBuilder;
|
||||||
|
import com.sunyard.sge.database.pool.HsmLinkInfo;
|
||||||
|
import com.sunyard.sge.database.pool.SydApiPool;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 功能确认
|
* 功能确认
|
||||||
*/
|
*/
|
||||||
public class FuncTest {
|
public class FuncTest {
|
||||||
|
|
||||||
private SydApi api;
|
private SydApi api;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init(){
|
public void init(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sm3(){
|
||||||
SydApiBuilder builder = new SydApiBuilder(
|
SydApiBuilder builder = new SydApiBuilder(
|
||||||
new String[]{ "192.168.0.200" },
|
new String[]{ "192.168.0.200" },
|
||||||
new int[]{ 8889 },
|
new int[]{ 8889 },
|
||||||
@ -24,9 +35,4 @@ public class FuncTest {
|
|||||||
api = builder.build();
|
api = builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void sm3(){
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,22 @@
|
|||||||
package test;
|
package test;
|
||||||
|
|
||||||
|
import com.sunyard.sge.database.SydApi;
|
||||||
|
import com.sunyard.sge.database.SydApi4Database;
|
||||||
import com.sunyard.sge.log.LogFactory;
|
import com.sunyard.sge.log.LogFactory;
|
||||||
import org.slf4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
||||||
public class LogTest {
|
public class LogTest {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
SydApi.SYD_SetLogConfig("./test-log/",11);
|
||||||
Logger log = LogFactory.createLogger("./test-log/", 2);
|
// int[] a1 = {1,2,3};
|
||||||
log.error("error");
|
// Logger log = LogFactory.createLogger("./test-log/", 9);
|
||||||
log.info("info");
|
// log.error("error");
|
||||||
log.debug("debug");
|
// log.info(Arrays.toString(a1));
|
||||||
|
// log.debug("debug");
|
||||||
|
// System.out.println("发送数据");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user